Multi-Release #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Multi-Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release-body: | |
| description: "Changelog for this release" | |
| type: string | |
| required: false | |
| default: "" | |
| run-tests: | |
| description: "Run game tests after build" | |
| type: boolean | |
| required: false | |
| default: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| setup: | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| matrix: ${{ steps.gen_matrix.outputs.matrix }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - id: gen_matrix | |
| run: | | |
| ENTRIES=$(jq -c '[.versions[] | {version, mc_src: (.mcVersion // .version), mc_ver: .minecraft_version, fabric_api: .fabric_api_version, yarn: (.yarn_mappings // ""), loader: (.loader_version // "")}]' versions.json) | |
| FILTERED="[]" | |
| while read -r entry; do | |
| MC_SRC=$(echo "$entry" | jq -r '.mc_src') | |
| if [ -d "src/mc-$MC_SRC" ]; then | |
| FILTERED=$(echo "$FILTERED" | jq ". + [$entry]") | |
| fi | |
| done < <(echo "$ENTRIES" | jq -c '.[]') | |
| echo "matrix={\"include\": $FILTERED}" >> $GITHUB_OUTPUT | |
| build: | |
| needs: setup | |
| runs-on: ubuntu-24.04 | |
| strategy: | |
| matrix: ${{ fromJSON(needs.setup.outputs.matrix) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "25" | |
| distribution: "zulu" | |
| cache: "gradle" | |
| - name: Make gradle wrapper executable | |
| run: chmod +x ./gradlew | |
| - name: Skip if no source directory | |
| id: check_src | |
| run: | | |
| if [ -d "src/mc-${{ matrix.mc_src }}" ]; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build ${{ matrix.version }} | |
| if: steps.check_src.outputs.exists == 'true' | |
| run: | | |
| PROPS=(-DmcVersion="${{ matrix.mc_src }}" -PmcVersion="${{ matrix.mc_src }}" -Pminecraft_version="${{ matrix.mc_ver }}" -Pfabric_api_version="${{ matrix.fabric_api }}") | |
| [ -n "${{ matrix.yarn }}" ] && PROPS+=(-Pyarn_mappings="${{ matrix.yarn }}") | |
| [ -n "${{ matrix.loader }}" ] && PROPS+=(-Ploader_version="${{ matrix.loader }}") | |
| ./gradlew clean build "${PROPS[@]}" --no-daemon -q | |
| - name: Run game tests | |
| if: steps.check_src.outputs.exists == 'true' && github.event.inputs.run-tests == 'true' && !startsWith(matrix.mc_src, '26') | |
| run: | | |
| PROPS=(-DmcVersion="${{ matrix.mc_src }}" -PmcVersion="${{ matrix.mc_src }}" -Pminecraft_version="${{ matrix.mc_ver }}" -Pfabric_api_version="${{ matrix.fabric_api }}" -PenableGameTests=true) | |
| [ -n "${{ matrix.yarn }}" ] && PROPS+=(-Pyarn_mappings="${{ matrix.yarn }}") | |
| [ -n "${{ matrix.loader }}" ] && PROPS+=(-Ploader_version="${{ matrix.loader }}") | |
| ./gradlew runGameTest "${PROPS[@]}" --no-daemon -q | |
| - name: Get mod version | |
| if: steps.check_src.outputs.exists == 'true' | |
| id: mod_info | |
| run: echo "mod_version=$(grep '^mod_version' gradle.properties | cut -d= -f2)" >> $GITHUB_OUTPUT | |
| - name: Rename and upload JAR | |
| if: steps.check_src.outputs.exists == 'true' | |
| run: | | |
| MODVER="${{ steps.mod_info.outputs.mod_version }}" | |
| mv "build/libs/stackabletools-${MODVER}.jar" "build/libs/stackabletools-${MODVER}-mc${{ matrix.version }}.jar" | |
| - name: Upload artifact | |
| if: steps.check_src.outputs.exists == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: jar-mc-${{ matrix.version }} | |
| path: build/libs/stackabletools-*.jar | |
| release: | |
| needs: build | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download all JARs | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist-jars | |
| - name: Collect JARs | |
| run: | | |
| mkdir -p dist | |
| find dist-jars -name "*.jar" -exec cp {} dist/ \; | |
| echo "Collected JARs:" | |
| ls -lh dist/ | |
| - name: Bump version and push tag | |
| id: version_tag | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| increment_version() { | |
| local v=$1 | |
| local major=$(echo "$v" | cut -d. -f1) | |
| local minor=$(echo "$v" | cut -d. -f2) | |
| local patch=$(echo "$v" | cut -d. -f3) | |
| echo "$major.$minor.$((patch + 1))" | |
| } | |
| VERSION=$(grep '^mod_version' gradle.properties | cut -d= -f2) | |
| git fetch --tags | |
| while git rev-parse "v$VERSION" >/dev/null 2>&1; do | |
| VERSION=$(increment_version "$VERSION") | |
| done | |
| CURRENT_VERSION=$(grep '^mod_version' gradle.properties | cut -d= -f2) | |
| if [ "$VERSION" != "$CURRENT_VERSION" ]; then | |
| sed -i "s/^mod_version=$CURRENT_VERSION/mod_version=$VERSION/" gradle.properties | |
| git add gradle.properties | |
| git commit -m "chore: bump version to $VERSION [skip ci]" | |
| git push origin "${GITHUB_REF#refs/heads/}" | |
| fi | |
| git tag "v$VERSION" | |
| git push origin "v$VERSION" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.version_tag.outputs.version }} | |
| name: Release v${{ steps.version_tag.outputs.version }} | |
| body: ${{ github.event.inputs.release-body }} | |
| generate_release_notes: true | |
| files: dist/*.jar | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |