Comment if linkcheck failed #145
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: Comment if linkcheck failed | |
| # Based on: | |
| # http://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ | |
| on: | |
| workflow_run: | |
| workflows: ["main"] | |
| types: | |
| - completed | |
| jobs: | |
| linkcheck-comment: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.event == 'pull_request' | |
| steps: | |
| - name: 'Download artifact' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: ${{github.event.workflow_run.id }}, | |
| }); | |
| var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name == "linkcheck" | |
| })[0]; | |
| var download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: matchArtifact.id, | |
| archive_format: 'zip', | |
| }); | |
| var fs = require('fs'); | |
| fs.writeFileSync('${{github.workspace}}/linkcheck.zip', Buffer.from(download.data)); | |
| - run: | | |
| unzip linkcheck.zip | |
| - name: 'Comment on PR if linkcheck failed' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| var fs = require('fs'); | |
| var status = Number(fs.readFileSync('./status')); | |
| var pr_number = Number(fs.readFileSync('./pr_number')); | |
| if (status != 0) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pr_number, | |
| body: `⚠️ linkcheck failed with status code ${status}` | |
| }); | |
| } |