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