publish-release #72
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: publish-release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| forge: | |
| description: 'Forge' | |
| required: true | |
| type: boolean | |
| default: true | |
| fabric: | |
| description: 'Fabric' | |
| required: true | |
| type: boolean | |
| default: true | |
| neoforge: | |
| description: 'NeoForge' | |
| required: true | |
| type: boolean | |
| default: true | |
| maven: | |
| description: 'Maven' | |
| required: true | |
| type: boolean | |
| default: true | |
| modrinth: | |
| description: 'Modrinth' | |
| required: true | |
| type: boolean | |
| default: true | |
| curseforge: | |
| description: 'CurseForge' | |
| required: true | |
| type: boolean | |
| default: true | |
| jobs: | |
| create-release: | |
| runs-on: ubuntu-latest | |
| environment: Releases | |
| outputs: | |
| ref: v${{ steps.bump-version.outputs.version }} | |
| version: ${{ steps.bump-version.outputs.version }} | |
| build-matrix: ${{ steps.set-build-matrix.outputs.result }} | |
| publish-matrix: ${{ steps.set-publish-matrix.outputs.result }} | |
| steps: | |
| - uses: actions/create-github-app-token@v2 | |
| id: app-token | |
| with: | |
| app-id: ${{ vars.AUTOMATIONS_APP_ID }} | |
| private-key: ${{ secrets.AUTOMATIONS_PRIVATE_KEY }} | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| - name: Get GitHub App User ID | |
| id: get-user-id | |
| run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| - run: | | |
| git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' | |
| git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' | |
| - name: Extracting version from properties | |
| shell: bash | |
| run: echo "version=$(cat gradle.properties | grep -w "\bversion\s*=" | cut -d= -f2)" >> $GITHUB_OUTPUT | |
| id: extract-version | |
| - name: Bumping version | |
| uses: TwelveIterations/bump-version@v1 | |
| with: | |
| version: ${{ steps.extract-version.outputs.version }} | |
| bump: patch | |
| id: bump-version | |
| - name: Updating version properties | |
| run: | | |
| sed -i "s/^\s*version\s*=.*/version = ${{ steps.bump-version.outputs.version }}/g" gradle.properties | |
| git commit -am "Set version to ${{ steps.bump-version.outputs.version }}" | |
| git push origin ${BRANCH_NAME} | |
| git tag -a "v${{ steps.bump-version.outputs.version }}" -m "Release ${{ steps.bump-version.outputs.version }}" | |
| git push origin "v${{ steps.bump-version.outputs.version }}" | |
| shell: bash | |
| env: | |
| BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | |
| - name: Preparing build matrix | |
| id: set-build-matrix | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const settingsGradle = fs.readFileSync('settings.gradle', 'utf8'); | |
| const includePattern = /^(?!\s*\/\/)\s*include\s*\(\s*(['"]([^'"]+)['"](?:,\s*['"]([^'"]+)['"])*\s*)\)/gm; | |
| const includes = [...settingsGradle.matchAll(includePattern)].flatMap(match => match[0].match(/['"]([^'"]+)['"]/g).map(item => item.replace(/['"]/g, ''))); | |
| const includeFabric = includes.includes('fabric') && ${{inputs.fabric}}; | |
| const includeForge = includes.includes('forge') && ${{inputs.forge}}; | |
| const includeNeoForge = includes.includes('neoforge') && ${{inputs.neoforge}}; | |
| return { | |
| loader: [includeFabric ? 'fabric' : false, includeForge ? 'forge' : false, includeNeoForge ? 'neoforge' : false].filter(Boolean), | |
| } | |
| - name: Preparing publish matrix | |
| id: set-publish-matrix | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const settingsGradle = fs.readFileSync('settings.gradle', 'utf8'); | |
| const includePattern = /^(?!\s*\/\/)\s*include\s*\(\s*(['"]([^'"]+)['"](?:,\s*['"]([^'"]+)['"])*\s*)\)/gm; | |
| const includes = [...settingsGradle.matchAll(includePattern)].flatMap(match => match[0].match(/['"]([^'"]+)['"]/g).map(item => item.replace(/['"]/g, ''))); | |
| const includeFabric = includes.includes('fabric') && ${{inputs.fabric}}; | |
| const includeForge = includes.includes('forge') && ${{inputs.forge}}; | |
| const includeNeoForge = includes.includes('neoforge') && ${{inputs.neoforge}}; | |
| const gradleProperties = fs.readFileSync('gradle.properties', 'utf8'); | |
| const curseForgeProjectId = gradleProperties.match(/^(?!#)curseforge_project_id\s*=\s*(.+)/m); | |
| const modrinthProjectId = gradleProperties.match(/^(?!#)modrinth_project_id\s*=\s*(.+)/m); | |
| const mavenReleases = gradleProperties.match(/^(?!#)maven_releases\s*=\s*(.+)/m); | |
| const publishCurseForge = curseForgeProjectId && ${{inputs.curseforge}}; | |
| const publishModrinth = modrinthProjectId && ${{inputs.modrinth}}; | |
| const publishMaven = mavenReleases && ${{inputs.maven}}; | |
| return { | |
| loader: ['common', includeFabric ? 'fabric' : false, includeForge ? 'forge' : false, includeNeoForge ? 'neoforge' : false].filter(Boolean), | |
| site: [publishCurseForge ? 'curseforge' : false, publishModrinth ? 'modrinth' : false, publishMaven ? 'publish' : false].filter(Boolean), | |
| exclude: [ | |
| {loader: 'common', site: 'curseforge'}, | |
| {loader: 'common', site: 'modrinth'} | |
| ] | |
| } | |
| build-common: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.create-release.outputs.ref }} | |
| - name: Validate gradle wrapper | |
| uses: gradle/actions/wrapper-validation@v5 | |
| - name: Setup JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 21 | |
| distribution: temurin | |
| cache: 'gradle' | |
| - name: Make gradle wrapper executable | |
| run: chmod +x ./gradlew | |
| - name: Build common artifact | |
| run: ./gradlew :common:build '-Pversion=${{needs.create-release.outputs.version}}' | |
| - name: Upload common artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: common-artifact | |
| path: common/build | |
| needs: create-release | |
| build-release: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: ${{fromJson(needs.create-release.outputs.build-matrix)}} | |
| fail-fast: false | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.create-release.outputs.ref }} | |
| - name: Validate gradle wrapper | |
| uses: gradle/actions/wrapper-validation@v5 | |
| - name: Setup JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 21 | |
| distribution: temurin | |
| cache: 'gradle' | |
| - name: Make gradle wrapper executable | |
| run: chmod +x ./gradlew | |
| - name: Download common artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: common-artifact | |
| path: common/build | |
| - name: Build ${{ matrix.loader }} artifact | |
| run: ./gradlew :${{ matrix.loader }}:build '-Pversion=${{needs.create-release.outputs.version}}' | |
| - name: Upload ${{ matrix.loader }} artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.loader }}-artifact | |
| path: ${{ matrix.loader }}/build | |
| needs: | |
| - create-release | |
| - build-common | |
| publish-release: | |
| runs-on: ubuntu-latest | |
| environment: Releases | |
| strategy: | |
| matrix: ${{fromJson(needs.create-release.outputs.publish-matrix)}} | |
| fail-fast: false | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.create-release.outputs.ref }} | |
| - name: Download ${{ matrix.loader }} artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ matrix.loader }}-artifact | |
| path: ${{ matrix.loader }}/build | |
| - name: Validate gradle wrapper | |
| uses: gradle/actions/wrapper-validation@v5 | |
| - name: Setup JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 21 | |
| distribution: temurin | |
| cache: 'gradle' | |
| - name: Make gradle wrapper executable | |
| run: chmod +x ./gradlew | |
| - name: Workaround for FG7 | |
| run: ./gradlew | |
| if: matrix.loader == 'forge' | |
| - name: Publish | |
| run: ./gradlew :${{ matrix.loader }}:${{ matrix.site }} '-Pversion=${{needs.create-release.outputs.version}}' '-PmavenUsername=${{ secrets.MAVEN_USER }}' '-PmavenPassword=${{ secrets.MAVEN_PASSWORD }}' | |
| env: | |
| CURSEFORGE_TOKEN: ${{secrets.CURSEFORGE_TOKEN}} | |
| MODRINTH_TOKEN: ${{secrets.MODRINTH_TOKEN}} | |
| needs: | |
| - create-release | |
| - build-common | |
| - build-release |