From 10bbe78a91b41f2320095a4fb7662dbdc8f4f97d Mon Sep 17 00:00:00 2001 From: glowredman <35727266+glowredman@users.noreply.github.com> Date: Tue, 27 Jun 2023 21:54:05 +0200 Subject: [PATCH] Fix MN/CF Publishing --- .github/workflows/release-tags.yml | 96 +++++++++++++++++++++++++++--- build.gradle | 17 ++++-- 2 files changed, 99 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release-tags.yml b/.github/workflows/release-tags.yml index e4c0be6..af517ab 100644 --- a/.github/workflows/release-tags.yml +++ b/.github/workflows/release-tags.yml @@ -1,14 +1,94 @@ +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle name: Release tagged build on: - push: - tags: [ '*' ] - -permissions: - contents: write + workflow_call: + secrets: + MAVEN_USER: + required: false + MAVEN_PASSWORD: + required: false + CURSEFORGE_TOKEN: + required: false + MODRINTH_TOKEN: + required: false + inputs: + workspace: + description: 'setupCIWorkspace/setupDecompWorkspace' + required: false + default: "setupCIWorkspace" + type: string jobs: - release-tags: - uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/release-tags.yml@master - secrets: inherit + build: + runs-on: ubuntu-latest + steps: + - name: Checkout mod repo + uses: actions/checkout@v3 + with: + fetch-depth: 32 + + - name: Validate gradle wrapper checksum + uses: gradle/wrapper-validation-action@v1 + + - name: Set release version + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Set up JDK 8 and 17 + uses: actions/setup-java@v3 + with: + java-version: | + 8 + 17 + distribution: 'zulu' + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Setup the workspace + run: ./gradlew --build-cache --info --stacktrace ${{ inputs.workspace }} + + - name: Build the mod + run: ./gradlew --build-cache --info --stacktrace build + + # Continue on error in the following steps to make sure releases still get made even if one of the methods fails + + - name: Delete old release if it already exists + run: gh release delete --yes "${RELEASE_VERSION}" + continue-on-error: true + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Release under current tag + run: | + export "CHANGELOG_FILE=$(mktemp --suffix=.md)" + echo "CHANGELOG_FILE=${CHANGELOG_FILE}" >> $GITHUB_ENV + gh api --method POST -H "Accept: application/vnd.github+json" \ + "/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \ + -f tag_name="${RELEASE_VERSION}" \ + --jq ".body" > "${CHANGELOG_FILE}" + cat "${CHANGELOG_FILE}" + gh release create "${RELEASE_VERSION}" -F "${CHANGELOG_FILE}" ./build/libs/*.jar + shell: bash + continue-on-error: true + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish to Maven + run: ./gradlew --build-cache --info --stacktrace build publish + continue-on-error: true + env: + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + if: ${{ env.MAVEN_USER != '' }} + + - name: Publish to Modrinth and/or CurseForge + run: ./gradlew --build-cache --info --stacktrace publishMNCF + continue-on-error: true + env: + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + if: ${{ env.MODRINTH_TOKEN != '' || secrets.CURSEFORGE_TOKEN != '' }} diff --git a/build.gradle b/build.gradle index 3930990..cc6a416 100644 --- a/build.gradle +++ b/build.gradle @@ -1129,7 +1129,12 @@ publishing { } } -if (modrinthProjectId.size() != 0 && System.getenv("MODRINTH_TOKEN") != null) { +tasks.register('publishMNCF') { + group = 'publishing' + description = 'Publish to Modrinth and/or CurseForge' +} + +if (modrinthProjectId.size() != 0) { apply plugin: 'com.modrinth.minotaur' File changelogFile = new File(System.getenv("CHANGELOG_FILE") ?: "CHANGELOG.md") @@ -1144,7 +1149,7 @@ if (modrinthProjectId.size() != 0 && System.getenv("MODRINTH_TOKEN") != null) { additionalFiles = getSecondaryArtifacts() gameVersions = [minecraftVersion] loaders = ["forge"] - debugMode = false + debugMode = true } if (modrinthRelations.size() != 0) { @@ -1162,10 +1167,10 @@ if (modrinthProjectId.size() != 0 && System.getenv("MODRINTH_TOKEN") != null) { addModrinthDep("required", "project", "unimixins") } tasks.modrinth.dependsOn(build) - tasks.publish.dependsOn(tasks.modrinth) + tasks.publishMNCF.dependsOn(tasks.modrinth) } -if (curseForgeProjectId.size() != 0 && System.getenv("CURSEFORGE_TOKEN") != null) { +if (curseForgeProjectId.size() != 0) { apply plugin: 'com.matthewprenger.cursegradle' File changelogFile = new File(System.getenv("CHANGELOG_FILE") ?: "CHANGELOG.md") @@ -1188,7 +1193,7 @@ if (curseForgeProjectId.size() != 0 && System.getenv("CURSEFORGE_TOKEN") != null options { javaIntegration = false forgeGradleIntegration = false - debug = false + debug = true } } @@ -1206,7 +1211,7 @@ if (curseForgeProjectId.size() != 0 && System.getenv("CURSEFORGE_TOKEN") != null addCurseForgeRelation("requiredDependency", "unimixins") } tasks.curseforge.dependsOn(build) - tasks.publish.dependsOn(tasks.curseforge) + tasks.publishMNCF.dependsOn(tasks.curseforge) } def addModrinthDep(String scope, String type, String name) {