From cfc73390d84ce7c4368175054d33231a5ccc6250 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:37:56 -0700 Subject: [PATCH] Setup automated publishing to CF and Modrinth (#15) * Configure mod-publish-plugin * Configure actions to run mod-publish-plugin To publish a release: - Set the mod version to x.x.x(-beta.x) in gradle.properties and commit - Create a git tag named vx.x.x(-beta.x) (note the v prefix) - Push commit, push tag - Manually create a (pre-)release for the tag on GitHub web ui. The release notes will be reused for modrinth and CF. The release creation will trigger the workflow and publish to modrinth and CF. The build script will check for when the version contains `-beta.` and mark it as a beta on modrinth and CF. After publishing a release, it's good practice to bump the version and add -SNAPSHOT, i.e. after releasing 0.0.1, push a commit changing the version to 0.0.2-SNAPSHOT. This ensures people downloading action artifacts have correct version numbers. This commit also updates gradle/actions/setup-gradle which removes the need for a separate wrapper validation action (it is included in setup-gradle v4) * Set project IDs --- .github/workflows/build.yml | 14 +++++++--- build.gradle | 27 +++++++++++++++++++ fabric/build.gradle | 19 +++++++++++++ neoforge/build.gradle | 21 +++++++++++++++ .../resources/META-INF/neoforge.mods.toml | 4 +++ 5 files changed, 82 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 29f2489..614c5fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,9 @@ on: branches: [ "**" ] tags-ignore: [ "**" ] pull_request: + release: + types: [ published ] + jobs: build: # Only run on PRs if the source branch is on someone else's repo @@ -12,15 +15,13 @@ jobs: steps: - name: "checkout git repository" uses: actions/checkout@v4 - - name: "validate gradle wrapper" - uses: gradle/actions/wrapper-validation@v3 - name: "setup jdk" uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: 21 - name: "setup gradle" - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 # gradle-build-action doesn't support caching files in the project dir - name: "cache project local caches" uses: actions/cache@v4 @@ -34,6 +35,13 @@ jobs: run: ./installConcurrentUtil.sh - name: "execute gradle build" run: ./gradlew build + - name: Publish (Pre-)Release to Modrinth + if: "${{ env.STATUS == 'release' && github.event_name == 'release' }}" + run: ./gradlew :moonrise-fabric:publishMods :moonrise-neoforge:publishMods + env: + MODRINTH_TOKEN: "${{ secrets.MODRINTH_TOKEN }}" + CURSEFORGE_TOKEN: "${{ secrets.CURSEFORGE_TOKEN }}" + RELEASE_NOTES: "${{ github.event.release.body }}" - name: "upload artifacts" uses: actions/upload-artifact@v4 with: diff --git a/build.gradle b/build.gradle index c53cbc7..4bb123b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,8 @@ +import me.modmuss50.mpp.ReleaseType + plugins { id("xyz.jpenilla.quiet-architectury-loom") + id("me.modmuss50.mod-publish-plugin") version "0.7.2" apply false } /* @@ -97,6 +100,30 @@ subprojects { ideConfigGenerated true // property "mixin.debug", "true" } + + plugins.apply("me.modmuss50.mod-publish-plugin") + + publishMods { + file = remapJar.archiveFile + if (project.version.contains("-beta.")) { + type = ReleaseType.BETA + } else { + type = ReleaseType.STABLE + } + changelog = providers.environmentVariable("RELEASE_NOTES") + + modrinth { + projectId = "KOHu7RCS" + accessToken = providers.environmentVariable("MODRINTH_TOKEN") + minecraftVersions = [rootProject.minecraft_version] + } + + curseforge { + projectId = "1096335" + accessToken = providers.environmentVariable("CURSEFORGE_TOKEN") + minecraftVersions = [rootProject.minecraft_version] + } + } } loom.runs.all { diff --git a/fabric/build.gradle b/fabric/build.gradle index e6c7cbf..d09dffd 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -45,6 +45,25 @@ shadowJar { relocate 'org.yaml.snakeyaml', 'ca.spottedleaf.moonrise.libs.org.yaml.snakeyaml' } +publishMods { + modLoaders = ["fabric"] + + modrinth { + incompatible( + "notenoughcrashes", + "starlight", + "c2me-fabric" + ) + } + curseforge { + incompatible( + "not-enough-crashes", + "starlight", + "c2me-fabric" + ) + } +} + // Setup a run with lithium for compatibility testing sourceSets.create("lithium") configurations.create("lithium") diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 5f28457..8f463b6 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -46,3 +46,24 @@ shadowJar { } Aw2At.setup(getProject(), tasks.remapJar) + +publishMods { + modLoaders = ["neoforge"] + + modrinth { + incompatible( + "notenoughcrashes", + "starlight-forge", + "canary", + "radium" + ) + } + curseforge { + incompatible( + "not-enough-crashes-forge", + "starlight-forge", + "canary", + "radium-reforged" + ) + } +} diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 68097c6..165367a 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -28,6 +28,10 @@ versionRange = "[1.21,1.21.2)" ordering = "NONE" side = "BOTH" +[[dependencies.moonrise]] +modId = "notenoughcrashes" +type = "incompatible" + [[dependencies.moonrise]] modId = "starlight" type = "incompatible"