From 21e152ecb8421d42d01ce08b42325357bd3ffa1d Mon Sep 17 00:00:00 2001 From: maggi373 <40539743+maggi373@users.noreply.github.com> Date: Sat, 19 Sep 2026 14:00:50 +0200 Subject: [PATCH] update workflow --- .github/scripts/validate-release-artifacts.sh | 146 +++++++++ .github/workflows/gradle.yml | 169 +++++++++- .github/workflows/maven.yml | 301 +++++++++++++++++- build.gradle | 5 +- gradle.properties | 2 +- 5 files changed, 594 insertions(+), 29 deletions(-) create mode 100644 .github/scripts/validate-release-artifacts.sh diff --git a/.github/scripts/validate-release-artifacts.sh b/.github/scripts/validate-release-artifacts.sh new file mode 100644 index 000000000..0f24a77b9 --- /dev/null +++ b/.github/scripts/validate-release-artifacts.sh @@ -0,0 +1,146 @@ +#!/usr/bin/env bash + +set -euo pipefail + +artifact_dir="${1:-output}" +artifact_prefix="${2:-}" +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +minecraft_version="$(sed -n 's/^minecraft_version=//p' "$repo_root/gradle.properties" | tr -d '\r' | tail -n 1)" +mod_version="$(sed -n 's/^mod_version=//p' "$repo_root/gradle.properties" | tr -d '\r' | tail -n 1)" + +if [[ ! -d "$artifact_dir" ]]; then + echo "Artifact directory does not exist: $artifact_dir" >&2 + exit 1 +fi + +if [[ -z "$minecraft_version" || -z "$mod_version" ]]; then + echo "Could not determine artifact versions from gradle.properties." >&2 + exit 1 +fi + +if [[ -z "$artifact_prefix" ]]; then + artifact_prefix="Mekanism-Community-Edition-${minecraft_version}-${mod_version}" + + if [[ -n "${BUILD_VER:-}" ]]; then + artifact_prefix="${artifact_prefix}-${BUILD_VER}" + fi +fi + +case "$minecraft_version" in + 1.7.10) + expected=(ALL:jar API:jar Core:jar DEV:jar DefenseTech:jar Generators:jar MDK:zip Tools:jar Ultimate:jar) + ;; + 1.12.2) + expected=(ALL:jar API:jar Core:jar Generators:jar Tools:jar Ultimate:jar) + ;; + *) + echo "Unsupported Minecraft version: $minecraft_version" >&2 + exit 1 + ;; +esac + +listing="$(mktemp)" +trap 'rm -f -- "$listing"' EXIT + +require_exact_entry() { + local entry="$1" + local artifact="$2" + if ! grep -Fqx "$entry" "$listing"; then + echo "Required entry '$entry' is missing from $artifact" >&2 + exit 1 + fi +} + +require_matching_entry() { + local pattern="$1" + local description="$2" + local artifact="$3" + if ! grep -Eq "$pattern" "$listing"; then + echo "Required $description is missing from $artifact" >&2 + exit 1 + fi +} + +reject_matching_entry() { + local pattern="$1" + local description="$2" + local artifact="$3" + if grep -Eq "$pattern" "$listing"; then + echo "Unexpected $description was packaged in $artifact" >&2 + exit 1 + fi +} + +for spec in "${expected[@]}"; do + classifier="${spec%%:*}" + extension="${spec##*:}" + artifact="$artifact_dir/$artifact_prefix-$classifier.$extension" + + if [[ ! -f "$artifact" ]]; then + echo "Expected artifact is missing: $artifact" >&2 + exit 1 + fi + + if (( $(wc -c < "$artifact") < 512 )); then + echo "Artifact is unexpectedly small: $artifact" >&2 + exit 1 + fi + + jar tf "$artifact" | tr -d '\r' > "$listing" + if [[ ! -s "$listing" ]]; then + echo "Artifact is empty or unreadable: $artifact" >&2 + exit 1 + fi + + case "$classifier" in + Core) + require_exact_entry 'mekanism/common/Mekanism.class' "$artifact" + reject_matching_entry '^(mekanism/(generators|tools|ultimate)/|defense/)' 'module class' "$artifact" + + if [[ "$minecraft_version" == '1.12.2' ]]; then + reject_matching_entry '^assets/mekanism(generators|tools|ultimate)/' 'module asset' "$artifact" + fi + ;; + ALL) + require_exact_entry 'mekanism/common/Mekanism.class' "$artifact" + require_exact_entry 'mekanism/generators/common/MekanismGenerators.class' "$artifact" + require_exact_entry 'mekanism/tools/common/MekanismTools.class' "$artifact" + require_exact_entry 'mekanism/ultimate/common/MekanismUltimate.class' "$artifact" + + if [[ "$minecraft_version" == '1.7.10' ]]; then + require_exact_entry 'defense/common/DefenseTech.class' "$artifact" + fi + ;; + API) + require_matching_entry '^mekanism/api/.*\.class$' 'compiled Mekanism API class' "$artifact" + + if [[ "$minecraft_version" == '1.12.2' ]]; then + require_matching_entry '^mekanism/api/.*\.java$' 'Mekanism API source' "$artifact" + fi + ;; + DEV) + require_exact_entry 'mekanism/common/Mekanism.class' "$artifact" + require_exact_entry 'mekanism/common/Mekanism.java' "$artifact" + ;; + DefenseTech) + require_exact_entry 'defense/common/DefenseTech.class' "$artifact" + ;; + Generators) + require_exact_entry 'mcmod.info' "$artifact" + require_exact_entry 'mekanism/generators/common/MekanismGenerators.class' "$artifact" + ;; + MDK) + require_matching_entry '^mekanism/api/.*\.java$' 'Mekanism API source' "$artifact" + ;; + Tools) + require_exact_entry 'mcmod.info' "$artifact" + require_exact_entry 'mekanism/tools/common/MekanismTools.class' "$artifact" + ;; + Ultimate) + require_exact_entry 'mcmod.info' "$artifact" + require_exact_entry 'mekanism/ultimate/common/MekanismUltimate.class' "$artifact" + ;; + esac + + echo "Validated $artifact" +done diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 3087c5c99..0ac6742d5 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,35 +1,176 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: Check code +name: Build and publish development artifacts on: push: + branches: + - '**' + paths-ignore: + - '**/README.md' + - '**/Mekanism.txt' + pull_request: + paths-ignore: + - '**/README.md' + - '**/Mekanism.txt' + # Trusted PRs run from the base branch's workflow so Maven credentials are + # available even when a team member opens the PR from a fork. The job-level + # trust check prevents unknown PRs from running under this event. + pull_request_target: paths-ignore: - '**/README.md' - '**/Mekanism.txt' schedule: - cron: '0 12 1 * *' + workflow_dispatch: + +permissions: + contents: read jobs: build: - - runs-on: ubuntu-latest + if: >- + ${{ (github.event_name == 'pull_request' && + !contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.pull_request.author_association)) || + (github.event_name == 'pull_request_target' && + contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.pull_request.author_association)) || + !contains(fromJSON('["pull_request","pull_request_target"]'), github.event_name) }} + name: >- + Build (${{ github.event_name == 'pull_request' && 'GitHub-hosted' || 'self-hosted' }}) + # Pull requests from repository owners, organization members, and explicit + # collaborators are trusted on our runner. All other PR code is isolated on + # a fresh GitHub-hosted runner. Pushes, schedules, and manual runs are + # maintainer-controlled and use the self-hosted runner. + runs-on: ${{ github.event_name == 'pull_request' && 'ubuntu-24.04' || 'self-hosted' }} + timeout-minutes: 90 steps: - - uses: actions/checkout@v2 - - name: Set up JDK 8 - uses: actions/setup-java@v2 + - name: Check out repository + uses: actions/checkout@v7 with: + clean: true + fetch-depth: 0 + persist-credentials: false + repository: >- + ${{ github.event_name == 'pull_request_target' && + github.event.pull_request.head.repo.full_name || github.repository }} + ref: >- + ${{ github.event_name == 'pull_request_target' && + github.event.pull_request.head.sha || '' }} + + - name: Set up JDK 8 + uses: actions/setup-java@v6 + with: + distribution: temurin java-version: '8' - distribution: 'adopt' - - name: Grant execute permission for gradlew + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 + with: + validate-wrappers: true + + - name: Grant execute permission for Gradle run: chmod +x gradlew - - name: Build and Publish - run: ./gradlew fullbuild artifactoryPublish + + - name: Determine exact artifact names + id: artifacts + shell: bash env: + PR_NUMBER: ${{ github.event.pull_request.number || '' }} + run: | + minecraft_version="$(sed -n 's/^minecraft_version=//p' gradle.properties | tr -d '\r' | tail -n 1)" + mod_version="$(sed -n 's/^mod_version=//p' gradle.properties | tr -d '\r' | tail -n 1)" + + if [[ -z "$minecraft_version" || -z "$mod_version" ]]; then + echo "Could not determine artifact versions from gradle.properties." >&2 + exit 1 + fi + + case "$GITHUB_EVENT_NAME" in + pull_request|pull_request_target) + build_suffix="pr-${PR_NUMBER}-${GITHUB_RUN_NUMBER}" + ;; + *) + build_suffix="$GITHUB_RUN_NUMBER" + ;; + esac + + artifact_prefix="Mekanism-Community-Edition-${minecraft_version}-${mod_version}-${build_suffix}" + + case "$minecraft_version" in + 1.7.10) + artifact_specs=(ALL.jar API.jar Core.jar DEV.jar DefenseTech.jar Generators.jar MDK.zip Tools.jar Ultimate.jar) + ;; + 1.12.2) + artifact_specs=(ALL.jar API.jar Core.jar Generators.jar Tools.jar Ultimate.jar) + ;; + *) + echo "Unsupported Minecraft version: $minecraft_version" >&2 + exit 1 + ;; + esac + + echo "prefix=$artifact_prefix" >> "$GITHUB_OUTPUT" + { + echo 'artifact_files<> "$GITHUB_OUTPUT" + + - name: Empty output directory + shell: bash + run: | + mkdir -p output + find output -mindepth 1 -delete + + - name: Build external pull request + if: github.event_name == 'pull_request' + run: ./gradlew --no-daemon --stacktrace clean fullBuild + env: + BUILD_VER: ${{ format('pr-{0}-{1}', github.event.pull_request.number, github.run_number) }} + + - name: Build trusted team pull request + if: github.event_name == 'pull_request_target' + run: ./gradlew --no-daemon --stacktrace clean fullBuild + env: + BUILD_VER: ${{ format('pr-{0}-{1}', github.event.pull_request.number, github.run_number) }} + + - name: Build development version + if: >- + ${{ !contains(fromJSON('["pull_request","pull_request_target"]'), github.event_name) }} + run: ./gradlew --no-daemon --stacktrace clean fullBuild + env: + BUILD_VER: ${{ github.run_number }} + + - name: Validate packaged artifacts + shell: bash + run: >- + bash .github/scripts/validate-release-artifacts.sh + output '${{ steps.artifacts.outputs.prefix }}' + + # Preserve the development Maven publication used by the external test + # servers. Trusted team PRs publish a unique pr-N-RUN version. Unknown PRs + # use pull_request on GitHub-hosted runners and never receive credentials. + - name: Publish development version to Maven + if: github.event_name != 'pull_request' + run: ./gradlew --no-daemon --stacktrace artifactoryPublish + env: + BUILD_VER: >- + ${{ github.event_name == 'pull_request_target' && + format('pr-{0}-{1}', github.event.pull_request.number, github.run_number) || github.run_number }} MAVEN_URL: ${{ secrets.MAVEN_URL }} MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_TOKEN }} MAVEN_REPO: ${{ secrets.MAVEN_DEVREPO }} - BUILD_VER: ${{ github.run_number }} + + # External contributors cannot publish to Maven, so retain their build + # output in Actions for review and testing. All trusted builds use Maven. + - name: Upload external pull request artifacts + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v7 + with: + name: mekanism-ce-${{ github.run_id }}-${{ github.run_attempt }} + path: ${{ steps.artifacts.outputs.artifact_files }} + if-no-files-found: error + retention-days: 14 + compression-level: 0 diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 515f2a75c..ef6777edd 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,29 +1,306 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle +name: Publish release + +# GitHub resolves release-event workflows from the repository's default branch. +# Keep this workflow branch-aware so both 1.7.10 and 1.12.2 tags publish correctly. -name: Publish package to the Maven Central Repository on: release: types: [published] +permissions: + contents: read + +concurrency: + group: release-${{ github.event.release.tag_name }} + cancel-in-progress: false + jobs: build: - - runs-on: ubuntu-latest + name: Build, publish Maven, and attach GitHub assets + runs-on: self-hosted + timeout-minutes: 90 + environment: release + outputs: + artifact_prefix: ${{ steps.artifacts.outputs.prefix }} + minecraft_version: ${{ steps.artifacts.outputs.minecraft_version }} + release_files: ${{ steps.artifacts.outputs.release_files }} + main_files: ${{ steps.artifacts.outputs.main_files }} steps: - - uses: actions/checkout@v2 - - name: Set up JDK 8 - uses: actions/setup-java@v2 + - name: Check out release tag + uses: actions/checkout@v7 with: + clean: true + fetch-depth: 0 + ref: ${{ github.event.release.tag_name }} + + - name: Set up JDK 8 + uses: actions/setup-java@v6 + with: + distribution: temurin java-version: '8' - distribution: 'adopt' - - name: Grant execute permission for gradlew + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 + with: + validate-wrappers: true + + - name: Grant execute permission for Gradle run: chmod +x gradlew - - name: Build and Publish - run: ./gradlew fullbuild artifactoryPublish + + - name: Determine exact artifact names + id: artifacts + shell: bash + run: | + minecraft_version="$(sed -n 's/^minecraft_version=//p' gradle.properties | tr -d '\r' | tail -n 1)" + mod_version="$(sed -n 's/^mod_version=//p' gradle.properties | tr -d '\r' | tail -n 1)" + + if [[ -z "$minecraft_version" || -z "$mod_version" ]]; then + echo "Could not determine artifact versions from gradle.properties." >&2 + exit 1 + fi + + artifact_prefix="Mekanism-Community-Edition-${minecraft_version}-${mod_version}" + + case "$minecraft_version" in + 1.7.10) + release_specs=(ALL.jar API.jar Core.jar DEV.jar DefenseTech.jar Generators.jar MDK.zip Tools.jar Ultimate.jar) + main_specs=(Core.jar API.jar DEV.jar MDK.zip) + ;; + 1.12.2) + release_specs=(ALL.jar API.jar Core.jar Generators.jar Tools.jar Ultimate.jar) + main_specs=(Core.jar API.jar) + ;; + *) + echo "Unsupported Minecraft version: $minecraft_version" >&2 + exit 1 + ;; + esac + + echo "prefix=$artifact_prefix" >> "$GITHUB_OUTPUT" + echo "minecraft_version=$minecraft_version" >> "$GITHUB_OUTPUT" + { + echo 'release_files<> "$GITHUB_OUTPUT" + + - name: Verify tag matches the project version + shell: bash + env: + RELEASE_TAG: ${{ github.event.release.tag_name }} + run: | + project_version="$(sed -n 's/^mod_version=//p' gradle.properties | tr -d '\r' | tail -n 1)" + if [[ -z "$project_version" || "$RELEASE_TAG" != "$project_version" ]]; then + echo "Release tag '$RELEASE_TAG' must equal gradle.properties mod_version '$project_version'." >&2 + exit 1 + fi + + - name: Empty output directory + shell: bash + run: | + mkdir -p output + find output -mindepth 1 -delete + + - name: Build release artifacts + run: ./gradlew --no-daemon --stacktrace clean fullBuild + + - name: Validate packaged artifacts + shell: bash + run: >- + bash .github/scripts/validate-release-artifacts.sh + output '${{ steps.artifacts.outputs.prefix }}' + + - name: Publish release to Maven + run: ./gradlew --no-daemon --stacktrace artifactoryPublish env: MAVEN_URL: ${{ secrets.MAVEN_URL }} MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_TOKEN }} MAVEN_REPO: ${{ secrets.MAVEN_REPO }} + + - name: Attach artifacts to GitHub release + uses: Kira-NT/mc-publish@52307b03863581dec6b652b83e597aec02ebb075 # v3.3.1 + with: + github-token: ${{ secrets.RELEASE_GITHUB_TOKEN }} + github-tag: ${{ github.event.release.tag_name }} + github-generate-changelog: false + files: ${{ steps.artifacts.outputs.release_files }} + version: ${{ github.event.release.tag_name }} + + - name: Save release artifacts for publishing jobs + uses: actions/upload-artifact@v7 + with: + name: release-${{ github.event.release.tag_name }} + path: ${{ steps.artifacts.outputs.release_files }} + if-no-files-found: error + # This artifact only passes the verified files to the parallel + # publishing jobs; GitHub Releases and Maven are the durable stores. + retention-days: 1 + compression-level: 0 + + publish-modrinth-main: + name: Publish Modrinth main project + needs: build + runs-on: self-hosted + timeout-minutes: 30 + environment: release + + steps: + - name: Download release artifacts + uses: actions/download-artifact@v8 + with: + name: release-${{ github.event.release.tag_name }} + path: output + + # Core is the primary file on the main project. The combined ALL artifact + # is intentionally distributed through GitHub and Maven, not Modrinth. + - name: Publish Mekanism Community Edition to Modrinth + uses: Kira-NT/mc-publish@52307b03863581dec6b652b83e597aec02ebb075 # v3.3.1 + with: + modrinth-id: toGHjw6t + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + files: ${{ needs.build.outputs.main_files }} + name: Mekanism CE - CORE ${{ github.event.release.tag_name }} + version: ${{ github.event.release.tag_name }} + version-type: ${{ github.event.release.prerelease && 'beta' || 'release' }} + changelog: ${{ github.event.release.body }} + loaders: forge + game-versions: ${{ needs.build.outputs.minecraft_version }} + game-version-filter: none + java: '8' + environment: client | server + retry-attempts: 2 + + publish-modrinth-modules: + name: Publish Modrinth (${{ matrix.name }}) + needs: build + runs-on: self-hosted + timeout-minutes: 30 + environment: release + strategy: + fail-fast: false + matrix: + include: + - name: DefenseTech + project-id: qBExn86I + classifier: DefenseTech + beta-only: false + only_version: '1.7.10' + - name: Generators + project-id: ksSEAhTL + classifier: Generators + beta-only: false + only_version: '' + - name: Tools + project-id: CD05L8Jr + classifier: Tools + beta-only: false + only_version: '' + - name: Ultimate + project-id: Q6fY4JVC + classifier: Ultimate + beta-only: true + only_version: '' + + steps: + - name: Download release artifacts + if: matrix.only_version == '' || needs.build.outputs.minecraft_version == matrix.only_version + uses: actions/download-artifact@v8 + with: + name: release-${{ github.event.release.tag_name }} + path: output + + - name: Publish ${{ matrix.name }} to Modrinth + if: matrix.only_version == '' || needs.build.outputs.minecraft_version == matrix.only_version + uses: Kira-NT/mc-publish@52307b03863581dec6b652b83e597aec02ebb075 # v3.3.1 + with: + modrinth-id: ${{ matrix.project-id }} + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + files: output/${{ needs.build.outputs.artifact_prefix }}-${{ matrix.classifier }}.jar + name: Mekanism CE - ${{ matrix.name }} ${{ github.event.release.tag_name }} + version: ${{ github.event.release.tag_name }} + version-type: ${{ matrix.beta-only && 'beta' || (github.event.release.prerelease && 'beta' || 'release') }} + changelog: ${{ github.event.release.body }} + loaders: forge + game-versions: ${{ needs.build.outputs.minecraft_version }} + game-version-filter: none + java: '8' + environment: client | server + modrinth-dependencies: toGHjw6t(required) + retry-attempts: 2 + + publish-curseforge: + name: Publish CurseForge (${{ matrix.name }}) + needs: build + runs-on: self-hosted + timeout-minutes: 30 + environment: release + strategy: + fail-fast: false + matrix: + include: + - name: Core + project-id: '399904' + classifier: Core + dependencies: '' + beta-only: false + only_version: '' + - name: DefenseTech + project-id: '1488821' + classifier: DefenseTech + dependencies: mekanism-ce(required) + beta-only: false + only_version: '1.7.10' + - name: Generators + project-id: '813408' + classifier: Generators + dependencies: mekanism-ce(required) + beta-only: false + only_version: '' + - name: Tools + project-id: '813407' + classifier: Tools + dependencies: mekanism-ce(required) + beta-only: false + only_version: '' + - name: Ultimate + project-id: '872280' + classifier: Ultimate + dependencies: mekanism-ce(required) + beta-only: true + only_version: '' + + steps: + - name: Download release artifacts + if: matrix.only_version == '' || needs.build.outputs.minecraft_version == matrix.only_version + uses: actions/download-artifact@v8 + with: + name: release-${{ github.event.release.tag_name }} + path: output + + - name: Publish ${{ matrix.name }} to CurseForge + if: matrix.only_version == '' || needs.build.outputs.minecraft_version == matrix.only_version + uses: Kira-NT/mc-publish@52307b03863581dec6b652b83e597aec02ebb075 # v3.3.1 + with: + curseforge-id: ${{ matrix.project-id }} + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + files: output/${{ needs.build.outputs.artifact_prefix }}-${{ matrix.classifier }}.jar + name: Mekanism CE - ${{ matrix.name }} ${{ github.event.release.tag_name }} + version: ${{ github.event.release.tag_name }} + version-type: ${{ matrix.beta-only && 'beta' || (github.event.release.prerelease && 'beta' || 'release') }} + changelog: ${{ github.event.release.body }} + loaders: forge + game-versions: ${{ needs.build.outputs.minecraft_version }} + game-version-filter: none + java: '8' + environment: client | server + curseforge-dependencies: ${{ matrix.dependencies }} + retry-attempts: 2 diff --git a/build.gradle b/build.gradle index 3ec20311d..162bffa70 100644 --- a/build.gradle +++ b/build.gradle @@ -155,7 +155,8 @@ task coreJar(type: Jar) { } from zipTree(jar.outputs.getFiles().getSingleFile()).matching { - exclude 'mekanism/tools/**', 'mekanism/generators/**', 'assets/mekanismtools/**', 'assets/mekanismgenerators/**', 'mcmod.info' + exclude 'mekanism/tools/**', 'mekanism/generators/**', 'mekanism/ultimate/**', + 'assets/mekanismtools/**', 'assets/mekanismgenerators/**', 'assets/mekanismultimate/**', 'mcmod.info' } manifest(setMainManifestProps) @@ -293,4 +294,4 @@ publishing { } } } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index b0aff5de9..66c6678e9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ minecraft_version=1.12.2 mappings_version=stable_39 forge_version=14.23.5.2847 -mod_version=9.12.14 +mod_version=9.12.15 mcmp_version=2.5.3 jei_version=4.15.0.289