Comment on issues when fix is released #2640
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: Build ModernFix using Gradle | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| tags-ignore: | |
| - '**' | |
| pull_request: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| issues: write | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: true | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: 21 | |
| check-latest: true | |
| - name: Check if release branch | |
| id: check_branch | |
| if: github.event_name == 'push' | |
| run: | | |
| if [[ "${{ github.ref }}" =~ ^refs/heads/[0-9]+\. ]]; then | |
| echo "is_release=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_release=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| with: | |
| cache-read-only: ${{ steps.check_branch.outputs.is_release != 'true' }} | |
| gradle-home-cache-cleanup: true | |
| - name: Remove tags for release on other versions | |
| if: steps.check_branch.outputs.is_release == 'true' | |
| run: ./scripts/tagcleaner.sh | |
| - name: Build ModernFix using Gradle | |
| run: ./gradlew build | |
| - name: Run mixin audit | |
| run: timeout 60 xvfb-run ./gradlew runAuditClient | |
| - name: Publish mod to CurseForge & Modrinth | |
| if: steps.check_branch.outputs.is_release == 'true' | |
| run: ./gradlew publishMods copyJarToBin | |
| env: | |
| CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} | |
| MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} | |
| - name: Capture mod version | |
| if: steps.check_branch.outputs.is_release == 'true' | |
| run: echo "MOD_VERSION=$(./gradlew properties -q | grep '^version:' | awk '{print $2}')" >> $GITHUB_ENV | |
| - name: Comment on fixed issues | |
| if: steps.check_branch.outputs.is_release == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { execSync } = require('child_process'); | |
| const branch = context.ref.replace('refs/heads/', ''); | |
| const { data: runs } = await github.rest.actions.listWorkflowRuns({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| workflow_id: 'gradle.yml', | |
| branch, | |
| status: 'success', | |
| per_page: 1 | |
| }); | |
| const logArgs = runs.workflow_runs.length > 0 | |
| ? `${runs.workflow_runs[0].head_sha}..${context.sha}` | |
| : `-1 ${context.sha}`; | |
| const log = execSync(`git log ${logArgs} --format=%s%n%b`, { encoding: 'utf8' }); | |
| const issueNumbers = new Set(); | |
| const pattern = /(?:fix(?:es|ed)?|close[sd]?|resolve[sd]?)\s+#(\d+)/gi; | |
| let match; | |
| while ((match = pattern.exec(log)) !== null) { | |
| issueNumbers.add(parseInt(match[1])); | |
| } | |
| if (issueNumbers.size === 0) { | |
| console.log('No fixed issues found in commits'); | |
| return; | |
| } | |
| const version = process.env.MOD_VERSION; | |
| for (const issueNumber of issueNumbers) { | |
| try { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: `The fix for this issue has been released in ModernFix ${version}` | |
| }); | |
| console.log(`Commented on issue #${issueNumber}`); | |
| } catch (e) { | |
| console.log(`Could not comment on #${issueNumber}: ${e.message}`); | |
| } | |
| } | |
| - name: Upload Artifacts to GitHub | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Package | |
| path: bin |