|
| 1 | +name: Comment Check Amalgamation |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Check amalgamation"] |
| 5 | + types: |
| 6 | + - completed |
| 7 | + |
| 8 | +permissions: {} |
| 9 | + |
| 10 | +jobs: |
| 11 | + comment: |
| 12 | + if: ${{ github.event.workflow_run.conclusion == 'failure' }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + actions: read |
| 17 | + issues: read |
| 18 | + pull-requests: write |
| 19 | + steps: |
| 20 | + - name: 'Download artifact' |
| 21 | + uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 # v6.4.0 |
| 22 | + with: |
| 23 | + script: | |
| 24 | + var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 25 | + owner: context.repo.owner, |
| 26 | + repo: context.repo.repo, |
| 27 | + run_id: ${{github.event.workflow_run.id }}, |
| 28 | + }); |
| 29 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 30 | + return artifact.name == "pr" |
| 31 | + })[0]; |
| 32 | + var download = await github.rest.actions.downloadArtifact({ |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + artifact_id: matchArtifact.id, |
| 36 | + archive_format: 'zip', |
| 37 | + }); |
| 38 | + var fs = require('fs'); |
| 39 | + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); |
| 40 | + - run: unzip pr.zip |
| 41 | + |
| 42 | + - name: 'Comment on PR' |
| 43 | + uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 # v6.4.0 |
| 44 | + with: |
| 45 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + script: | |
| 47 | + var fs = require('fs'); |
| 48 | + const author = fs.readFileSync('./author') |
| 49 | + const issue_number = Number(fs.readFileSync('./number')); |
| 50 | + const opts = github.rest.issues.listForRepo.endpoint.merge({ |
| 51 | + owner: context.repo.owner, |
| 52 | + repo: context.repo.repo, |
| 53 | + creator: author, |
| 54 | + state: 'all' |
| 55 | + }) |
| 56 | + let first = true |
| 57 | + const issues = await github.paginate(opts) |
| 58 | + for (const issue of issues) { |
| 59 | + if (issue.number === issue_number) { |
| 60 | + continue |
| 61 | + } |
| 62 | + if (issue.pull_request) { |
| 63 | + first = false |
| 64 | + break |
| 65 | + } |
| 66 | + } |
| 67 | + await github.rest.issues.createComment({ |
| 68 | + issue_number: issue_number, |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + body: '## 🔴 Amalgamation check failed! 🔴\nThe source code has not been amalgamated.' |
| 72 | + + (first ? ' @' + author + ' Please read and follow the [Contribution Guidelines]' |
| 73 | + + '(https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change).' |
| 74 | + : '') |
| 75 | + }) |
0 commit comments