Skip to content

Commit e0fc238

Browse files
committed
Add auto publishing gradle plugin
1 parent f51457d commit e0fc238

File tree

5 files changed

+93
-6
lines changed

5 files changed

+93
-6
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
build:
10-
runs-on: ubuntu-22.04
10+
runs-on: ubuntu-24.04
1111
if: "!contains(github.event.head_commit.message, 'skip ci') && !contains(github.event.head_commit.message, 'ci skip')"
1212

1313
steps:

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Release
2+
on:
3+
workflow_dispatch:
4+
5+
permissions:
6+
contents: write
7+
8+
jobs:
9+
release:
10+
name: Publish Release
11+
runs-on: ubuntu-24.04
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Validate gradle wrapper
18+
uses: gradle/actions/wrapper-validation@v3
19+
20+
- name: Setup java 21
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: 21
24+
distribution: temurin
25+
26+
- name: Publish plugin
27+
env:
28+
GITHUB_API_TOKEN: ${{ github.token }}
29+
MODRINTH_API_TOKEN: ${{ secrets.MODRINTH_PUBLISH_TOKEN }}
30+
run: ./gradlew publishMods --no-daemon -PnoDryPublish

build.gradle.kts

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
2+
import me.modmuss50.mpp.MppPlugin
3+
import me.modmuss50.mpp.PublishModTask
14
import net.kyori.indra.IndraPlugin
25
import org.jetbrains.gradle.ext.IdeaExtPlugin
36

@@ -13,6 +16,8 @@ plugins {
1316

1417
alias(libs.plugins.indra)
1518
alias(libs.plugins.blossom) apply false
19+
20+
alias(libs.plugins.publishing)
1621
}
1722

1823
allprojects {
@@ -22,7 +27,6 @@ allprojects {
2227
apply<IndraPlugin>()
2328

2429
group = "dev.booky"
25-
version = "1.1.0-SNAPSHOT"
2630

2731
repositories {
2832
maven("https://repo.cloudcraftmc.de/public/")
@@ -54,11 +58,61 @@ allprojects {
5458
tasks.withType<Jar> {
5559
archiveBaseName = project.name
5660
}
57-
}
5861

59-
subprojects {
60-
tasks.withType<Jar> {
61-
destinationDirectory = rootProject.tasks.jar.map { it.destinationDirectory }.get()
62+
if (project != rootProject) {
63+
tasks.withType<Jar> {
64+
destinationDirectory = rootProject.tasks.jar.map { it.destinationDirectory }.get()
65+
}
66+
}
67+
68+
if (project.projectDir.name != "common") {
69+
apply<ShadowPlugin>()
70+
apply<MppPlugin>()
71+
72+
publishMods {
73+
val repositoryName = "CloudCraftProjects/CloudCore"
74+
file = tasks.shadowJar.flatMap { it.archiveFile }.get()
75+
changelog = "See https://github.com/$repositoryName/releases/tag/v${project.version}"
76+
type = if (project.version.toString().endsWith("-SNAPSHOT")) BETA else STABLE
77+
additionalFiles.from(tasks.sourcesJar.flatMap { it.archiveFile }.get())
78+
dryRun = !hasProperty("noDryPublish")
79+
80+
github {
81+
accessToken = providers.environmentVariable("GITHUB_API_TOKEN")
82+
.orElse(providers.gradleProperty("ccGithubToken"))
83+
84+
displayName = "${rootProject.name} v${project.version}"
85+
86+
repository = repositoryName
87+
commitish = "master"
88+
tagName = "v${project.version}"
89+
90+
if (project != rootProject) {
91+
parent(rootProject.tasks.named("publishGithub"))
92+
}
93+
}
94+
modrinth {
95+
accessToken = providers.environmentVariable("MODRINTH_API_TOKEN")
96+
.orElse(providers.gradleProperty("ccModrinthToken"))
97+
98+
val platformName = if (project == rootProject) "paper" else project.projectDir.name
99+
val fancyPlatformName = platformName.replaceFirstChar { it.titlecaseChar() }
100+
version = "${project.version}+$platformName"
101+
displayName = "${rootProject.name} $fancyPlatformName v${project.version}"
102+
modLoaders.add(platformName)
103+
104+
projectId = "I9yBw5Kw"
105+
minecraftVersionRange {
106+
start = rootProject.libs.versions.paper.get().split("-")[0]
107+
end = "latest"
108+
}
109+
}
110+
}
111+
112+
tasks.withType<PublishModTask> {
113+
dependsOn(tasks.shadowJar)
114+
dependsOn(tasks.sourcesJar)
115+
}
62116
}
63117
}
64118

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=1.1.0

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ shadow = "8.1.7"
55
indra = "3.1.3"
66
blossom = "2.1.0"
77
ideaext = "1.1.8"
8+
publishing = "0.7.4"
89

910
# common
1011
adventure = "4.17.0"
@@ -27,6 +28,7 @@ shadow = { id = "io.github.goooler.shadow", version.ref = "shadow" }
2728
indra = { id = "net.kyori.indra", version.ref = "indra" }
2829
blossom = { id = "net.kyori.blossom", version.ref = "blossom" }
2930
ideaext = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "ideaext" }
31+
publishing = { id = "me.modmuss50.mod-publish-plugin", version.ref = "publishing" }
3032

3133
[libraries]
3234
# common

0 commit comments

Comments
 (0)