GnuComment #189
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: GnuComment | |
| # spell-checker:ignore zizmor backquote | |
| on: | |
| workflow_run: | |
| workflows: ["GnuTests"] | |
| types: | |
| - completed | |
| permissions: {} | |
| jobs: | |
| post-comment: | |
| permissions: | |
| actions: read # to list workflow runs artifacts | |
| pull-requests: write # to comment on pr | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.event == 'pull_request' | |
| steps: | |
| - name: 'Download artifact' | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: ${{ github.event.workflow_run.id }}, | |
| }); | |
| const matchArtifact = artifacts.data.artifacts.find(a => a.name === "comment"); | |
| if (!matchArtifact) { | |
| return core.info("No 'comment' artifact found"); | |
| } | |
| const download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: matchArtifact.id, | |
| archive_format: 'zip', | |
| }); | |
| const fs = require('fs'); | |
| fs.writeFileSync('${{ github.workspace }}/comment.zip', Buffer.from(download.data)); | |
| - name: 'Unzip artifact' | |
| run: unzip comment.zip | |
| - name: 'Comment on PR' | |
| uses: actions/github-script@v9 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| if (!fs.existsSync('./NR') || !fs.existsSync('./result.txt')) { | |
| return core.info("No NR or result.txt found, skipping comment"); | |
| } | |
| const issue_number = Number(fs.readFileSync('./NR', 'utf8').trim()); | |
| const content = fs.readFileSync('./result.txt', 'utf8').trim(); | |
| if (content.length > 0) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue_number, | |
| body: `### GNU Testsuite Comparison\n\n\`\`\`\n${content}\n\`\`\`` | |
| }); | |
| } |