|
11 | 11 | jobs: |
12 | 12 | build: |
13 | 13 | runs-on: ubuntu-22.04 |
| 14 | + permissions: |
| 15 | + issues: write |
14 | 16 | concurrency: |
15 | 17 | group: release-${{ github.ref }} |
16 | 18 | cancel-in-progress: true |
|
52 | 54 | env: |
53 | 55 | CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} |
54 | 56 | MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} |
| 57 | + - name: Capture mod version |
| 58 | + if: steps.check_branch.outputs.is_release == 'true' |
| 59 | + run: | |
| 60 | + echo "MOD_VERSION=$(./gradlew properties -q | grep '^version:' | awk '{print $2}')" >> $GITHUB_ENV |
| 61 | + echo "MC_VERSION=$(grep '^minecraft_version=' gradle.properties | cut -d= -f2)" >> $GITHUB_ENV |
| 62 | + - name: Comment on fixed issues |
| 63 | + if: steps.check_branch.outputs.is_release == 'true' |
| 64 | + uses: actions/github-script@v7 |
| 65 | + with: |
| 66 | + script: | |
| 67 | + const { execSync } = require('child_process'); |
| 68 | +
|
| 69 | + const branch = context.ref.replace('refs/heads/', ''); |
| 70 | + const { data: runs } = await github.rest.actions.listWorkflowRuns({ |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + workflow_id: 'gradle.yml', |
| 74 | + branch, |
| 75 | + status: 'success', |
| 76 | + per_page: 1 |
| 77 | + }); |
| 78 | +
|
| 79 | + const logArgs = runs.workflow_runs.length > 0 |
| 80 | + ? `${runs.workflow_runs[0].head_sha}..${context.sha}` |
| 81 | + : `-1 ${context.sha}`; |
| 82 | + const log = execSync(`git log ${logArgs} --format=%s%n%b`, { encoding: 'utf8' }); |
| 83 | +
|
| 84 | + const issueNumbers = new Set(); |
| 85 | + const pattern = /(?:fix(?:es|ed)?|close[sd]?|resolve[sd]?)\s+#(\d+)/gi; |
| 86 | + let match; |
| 87 | + while ((match = pattern.exec(log)) !== null) { |
| 88 | + issueNumbers.add(parseInt(match[1])); |
| 89 | + } |
| 90 | +
|
| 91 | + if (issueNumbers.size === 0) { |
| 92 | + console.log('No fixed issues found in commits'); |
| 93 | + return; |
| 94 | + } |
| 95 | +
|
| 96 | + const MARKER = '<!-- modernfix-fix-tracker -->'; |
| 97 | + const modVersion = process.env.MOD_VERSION; |
| 98 | + const mcVersion = process.env.MC_VERSION; |
| 99 | + const newLine = `- ${modVersion} for Minecraft ${mcVersion}`; |
| 100 | +
|
| 101 | + for (const issueNumber of issueNumbers) { |
| 102 | + try { |
| 103 | + const { data: comments } = await github.rest.issues.listComments({ |
| 104 | + owner: context.repo.owner, |
| 105 | + repo: context.repo.repo, |
| 106 | + issue_number: issueNumber, |
| 107 | + per_page: 100 |
| 108 | + }); |
| 109 | +
|
| 110 | + const existing = comments.find(c => c.body.includes(MARKER)); |
| 111 | + if (existing) { |
| 112 | + await github.rest.issues.updateComment({ |
| 113 | + owner: context.repo.owner, |
| 114 | + repo: context.repo.repo, |
| 115 | + comment_id: existing.id, |
| 116 | + body: existing.body + `\n${newLine}` |
| 117 | + }); |
| 118 | + console.log(`Updated comment on issue #${issueNumber}`); |
| 119 | + } else { |
| 120 | + await github.rest.issues.createComment({ |
| 121 | + owner: context.repo.owner, |
| 122 | + repo: context.repo.repo, |
| 123 | + issue_number: issueNumber, |
| 124 | + body: `${MARKER}\nThe fix for this issue has been released in the following versions of ModernFix:\n${newLine}` |
| 125 | + }); |
| 126 | + console.log(`Created comment on issue #${issueNumber}`); |
| 127 | + } |
| 128 | + } catch (e) { |
| 129 | + console.log(`Could not comment on #${issueNumber}: ${e.message}`); |
| 130 | + } |
| 131 | + } |
55 | 132 | - name: Upload Artifacts to GitHub |
56 | 133 | uses: actions/upload-artifact@v4 |
57 | 134 | with: |
|
0 commit comments