From 28a8785fd92a246eb6ddc812a6c00e2c93038619 Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Mon, 30 Sep 2024 14:50:19 -0700 Subject: [PATCH] Automate CurseForge and Modrinth releases --- .github/workflows/publish.yml | 34 +++++++++++++++++++ build.gradle | 64 +++++++++++++++++++++++++++++++++-- changelog.md | 2 +- gradlew | 0 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/publish.yml mode change 100644 => 100755 gradlew diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..d021768d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,34 @@ +name: Release for 1.20.1 + +on: + push: + branches: [ '1.20.1' ] + workflow_dispatch: + +jobs: + release: + name: Publish release JAR for Ex Deorum + runs-on: ubuntu-latest + if: "startsWith(github.event.head_commit.message, '[Release]')" + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'microsoft' + java-version: '17' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Upload to CurseForge + run: ./gradlew curseforge + env: + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + + - name: Upload to Modrinth + run: ./gradlew publishModrinth + env: + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 773016c0..7ebdaddd 100644 --- a/build.gradle +++ b/build.gradle @@ -3,13 +3,13 @@ plugins { id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'org.parchmentmc.librarian.forgegradle' version '1.+' id 'org.spongepowered.mixin' version '0.7.+' + id("com.modrinth.minotaur") version "2.+" + id("com.matthewprenger.cursegradle") version "1.4.0" } version = '1.41' group = 'thedarkcolour.exdeorum' -base { - archivesName = 'exdeorum' -} +base.archivesName = 'exdeorum' java.toolchain.languageVersion = JavaLanguageVersion.of(17) java.withSourcesJar() @@ -215,3 +215,61 @@ idea { downloadJavadoc = true } } + +if (System.getenv("CURSEFORGE_TOKEN")) { + curseforge { + apiKey = System.getenv("CURSEFORGE_TOKEN") + + project { + id = "901420" + changelogType = "markdown" + changelog = getChangelog(project.version) + + releaseType = "release" + + addGameVersion(mc_version) + addGameVersion("Forge") + addGameVersion("NeoForge") + addGameVersion("Java 17") + + mainArtifact(jar.archiveFile) { + displayName = "Ex Deorum ${project.version}" + } + } + } +} + +modrinth { + token = System.getenv("MODRINTH_TOKEN") + projectId = "WP0FLyzv" + uploadFile = jar + gameVersions = [mc_version] + loaders = ["forge", "neoforge"] + changelog = getChangelog(project.version) +} + +static def getChangelog(Object version) { + version = version.toString() + + def file = new File('changelog.md') + if (!file.exists()) { + return "Changelog file not found" + } + + // Relies on the changelog block being "##blahblahblah_VERSION" where _ is a space + def content = file.text.normalize().split("##.* ") + + for (final def chunk in content) { + if (chunk.isEmpty()) continue + + def lineTerminatorIndex = chunk.findIndexOf { c -> c == '\n' || c == '\r' } + def versionString = chunk.substring(0, lineTerminatorIndex) + + if (versionString == version) { + return "## Ex Deorum $version\n" + chunk.substring(lineTerminatorIndex + 1) + } + } + + // Fallback in case this fails + return "Ex Deorum Update ${version}" +} diff --git a/changelog.md b/changelog.md index 286a7040..3bb1f87a 100644 --- a/changelog.md +++ b/changelog.md @@ -244,7 +244,7 @@ ## Ex Deorum 1.1 - Fixed the missing barrel mixing recipe for Clay Block -## Ex Deorum 1.0 +## Ex Deorum 1.0 *Ex Deorum*'s new additions are listed first, then the additions from original *Ex Nihilo*. - Added the Watering Can, which can be used to hydrate farmland and speed up plant and tree growth. It is intended to be an alternative to mods like Twerk or Tree Growing Simulator, as a Wooden Watering Can is given to the player at the start (configurable). diff --git a/gradlew b/gradlew old mode 100644 new mode 100755