Skip to content

Commit aa28d78

Browse files
authored
Workflow and Gradle based publishing setup with changelog system (#3575)
1 parent 0da7343 commit aa28d78

5 files changed

Lines changed: 136 additions & 17 deletions

File tree

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
# Used when a commit is tagged and pushed to the repository
1+
# Used when a developer decides to publish a release
22
# This makes use of caching for faster builds and uploads the resulting artifacts
3-
name: build-tag
3+
name: Release GH+MR+CF
4+
permissions:
5+
contents: write # Needed to publish a GitHub release
46

57
on:
6-
push:
7-
tags:
8-
- '*'
8+
workflow_dispatch:
9+
inputs:
10+
platform:
11+
type: choice
12+
description: Platform
13+
options:
14+
- both
15+
- fabric
16+
- neoforge
917

1018
jobs:
1119
build:
@@ -19,8 +27,10 @@ jobs:
1927
# bash pattern expansion to grab branch name without slashes
2028
run: ref="${GITHUB_REF#refs/heads/}" && echo "branch=${ref////-}" >> $GITHUB_OUTPUT
2129
id: ref
30+
2231
- name: Checkout sources
2332
uses: actions/checkout@v6
33+
2434
- uses: actions/setup-java@v5
2535
with:
2636
distribution: temurin
@@ -39,6 +49,13 @@ jobs:
3949
with:
4050
name: sodium-artifacts-${{ steps.ref.outputs.branch }}
4151
path: build/mods/*.jar
52+
53+
- name: Publish Modrinth, Curseforge and Github Releases
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
57+
MODRINTH_API_KEY: ${{ secrets.MODRINTH_API_KEY }}
58+
run: ./gradlew publishMods -Pbuild.release=true -Pbuild.release.platform=${{ inputs.platform }}
4259

4360
- name: Publish Tag Release to CaffeineMC Maven
4461
env:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[ReleaseTag]() is automatically replaced with the release tag, e.g. mc26.1-0.8.9
2+
[MCVersion]() is automatically replaced with the minecraft version, e.g. 26.1
3+
[SodiumVersion]() is automatically replaced with the sodium version, e.g. 0.8.9
4+
Everything above the line is ignored and not included in the changelog. Everything below will be in the
5+
changelog on GitHub, Modrinth and CurseForge.
6+
----------
7+
Sodium [SodiumVersion]() is the first release for Minecraft [MCVersion]().
8+

build.gradle.kts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import me.modmuss50.mpp.ReleaseType
2+
import me.modmuss50.mpp.platforms.curseforge.CurseforgeOptions
3+
import me.modmuss50.mpp.platforms.modrinth.ModrinthOptions
4+
import java.util.Locale
5+
6+
plugins {
7+
id("me.modmuss50.mod-publish-plugin") version("1.1.0")
8+
}
9+
10+
gradle.projectsEvaluated {
11+
publishMods {
12+
if (!project.hasProperty("build.release")) {
13+
return@publishMods println("Publishing is disabled, please use the CI publishing workflow")
14+
}
15+
16+
val releasePlatform: String = project.providers.gradleProperty("build.release.platform").orNull
17+
?: return@publishMods println("build.release.platform must be defined (expected: both, fabric, neoforge)")
18+
19+
val modVersion = BuildConfig.createVersionString(project);
20+
21+
type = when {
22+
modVersion.contains("alpha") -> ReleaseType.ALPHA
23+
modVersion.contains("beta") -> ReleaseType.BETA
24+
else -> ReleaseType.STABLE
25+
}
26+
version = modVersion
27+
changelog = BuildConfig.getChangelog(project)
28+
29+
val curseforgeShared = curseforgeOptions {
30+
accessToken = project.providers.environmentVariable("CURSEFORGE_API_KEY")
31+
projectId = BuildConfig.CURSEFORGE_PROJECT_ID
32+
minecraftVersions.add(BuildConfig.MINECRAFT_VERSION)
33+
}
34+
35+
val modrinthShared = modrinthOptions {
36+
accessToken = project.providers.environmentVariable("MODRINTH_API_KEY")
37+
projectId = BuildConfig.MODRINTH_PROJECT_ID
38+
minecraftVersions.add(BuildConfig.MINECRAFT_VERSION)
39+
}
40+
41+
setupFor("Fabric", releasePlatform, curseforgeShared, modrinthShared)
42+
setupFor("NeoForge", releasePlatform, curseforgeShared, modrinthShared)
43+
44+
github {
45+
accessToken = project.providers.environmentVariable("GITHUB_TOKEN")
46+
repository = "CaffeineMC/sodium"
47+
commitish = BuildConfig.calculateGitHash(project)
48+
tagName = BuildConfig.RELEASE_TAG
49+
file.unset()
50+
file.unsetConvention()
51+
52+
allowEmptyFiles = true
53+
}
54+
}
55+
}
56+
57+
fun me.modmuss50.mpp.ModPublishExtension.setupFor(loaderName: String, releasePlatform: String, curseforgeOptions: Provider<CurseforgeOptions>, modrinthOptions: Provider<ModrinthOptions>) {
58+
val loaderLowercase = loaderName.lowercase(Locale.ROOT)
59+
60+
if (releasePlatform == "both" || releasePlatform == loaderLowercase) {
61+
val jar = project(":$loaderLowercase").tasks.named<Jar>("jar").get().archiveFile
62+
63+
curseforge("curseforge$loaderName") {
64+
from(curseforgeOptions)
65+
66+
file.set(jar)
67+
displayName = "Sodium ${BuildConfig.MOD_VERSION} for $loaderName ${BuildConfig.MINECRAFT_VERSION}"
68+
modLoaders.add(loaderLowercase)
69+
70+
clientRequired = true
71+
serverRequired = false
72+
}
73+
74+
modrinth("modrinth$loaderName") {
75+
from(modrinthOptions)
76+
77+
file.set(jar)
78+
displayName = "Sodium ${BuildConfig.MOD_VERSION} for $loaderName ${BuildConfig.MINECRAFT_VERSION}"
79+
modLoaders.add(loaderLowercase)
80+
}
81+
}
82+
}

buildSrc/src/main/kotlin/BuildConfig.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import org.gradle.api.Project
1+
import org.gradle.api.Project
22

33
object BuildConfig {
44
val MINECRAFT_VERSION: String = "26.1.2"
@@ -7,11 +7,13 @@ object BuildConfig {
77
val FABRIC_API_VERSION: String = "0.145.4+26.1.2"
88
val SUPPORT_FRAPI : Boolean = true
99

10-
// This value can be set to null to disable Parchment.
11-
val PARCHMENT_VERSION: String? = null
12-
1310
// https://semver.org/
14-
var MOD_VERSION: String = "0.8.9"
11+
val MOD_VERSION: String = "0.8.9"
12+
13+
val RELEASE_TAG: String = "mc$MINECRAFT_VERSION-$MOD_VERSION"
14+
15+
val CURSEFORGE_PROJECT_ID = "394468"
16+
val MODRINTH_PROJECT_ID = "AANobbMI"
1517

1618
fun createVersionString(project: Project): String {
1719
val builder = StringBuilder()
@@ -38,4 +40,21 @@ object BuildConfig {
3840

3941
return builder.toString()
4042
}
43+
44+
fun calculateGitHash(project: Project): String = try {
45+
val output = project.providers.exec {
46+
workingDir(project.projectDir)
47+
commandLine("git", "rev-parse", "HEAD")
48+
}
49+
output.standardOutput.asText.get().trim()
50+
} catch (_: Throwable) {
51+
"unknown"
52+
}
53+
54+
fun getChangelog(project: Project): String = project.rootProject.file("CHANGELOG.md").readText()
55+
.split("----------")[1]
56+
.trim()
57+
.replace("[ReleaseTag]()", RELEASE_TAG)
58+
.replace("[MCVersion]()", MINECRAFT_VERSION)
59+
.replace("[SodiumVersion]()", MOD_VERSION)
4160
}

neoforge/build.gradle.kts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,6 @@ sourceSets {
137137
neoForge {
138138
version = BuildConfig.NEOFORGE_VERSION
139139

140-
if (BuildConfig.PARCHMENT_VERSION != null) {
141-
parchment {
142-
minecraftVersion = BuildConfig.MINECRAFT_VERSION
143-
mappingsVersion = BuildConfig.PARCHMENT_VERSION
144-
}
145-
}
146-
147140
runs {
148141
create("Client") {
149142
client()

0 commit comments

Comments
 (0)