Skip to content

Commit 15ac0f2

Browse files
authored
Merge pull request #462 from sam-maloney/allow-linkcheck-fail
CI: pass with comment on linkcheck fail
2 parents c52537c + 15b40d4 commit 15ac0f2

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Comment if linkcheck failed
2+
3+
# Based on:
4+
# http://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
5+
6+
on:
7+
workflow_run:
8+
workflows: ["main"]
9+
types:
10+
- completed
11+
12+
jobs:
13+
linkcheck-comment:
14+
runs-on: ubuntu-latest
15+
if: github.event.workflow_run.event == 'pull_request'
16+
steps:
17+
- name: 'Download artifact'
18+
uses: actions/github-script@v7
19+
with:
20+
script: |
21+
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
run_id: ${{github.event.workflow_run.id }},
25+
});
26+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
27+
return artifact.name == "linkcheck"
28+
})[0];
29+
var download = await github.rest.actions.downloadArtifact({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
artifact_id: matchArtifact.id,
33+
archive_format: 'zip',
34+
});
35+
var fs = require('fs');
36+
fs.writeFileSync('${{github.workspace}}/linkcheck.zip', Buffer.from(download.data));
37+
- run: |
38+
unzip linkcheck.zip
39+
40+
- name: 'Comment on PR if linkcheck failed'
41+
uses: actions/github-script@v7
42+
with:
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
script: |
45+
var fs = require('fs');
46+
var status = Number(fs.readFileSync('./status'));
47+
var pr_number = Number(fs.readFileSync('./pr_number'));
48+
if (status != 0) {
49+
await github.rest.issues.createComment({
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
issue_number: pr_number,
53+
body: `⚠️ linkcheck failed with status code ${status}`
54+
});
55+
}

.github/workflows/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
name: main
12
on: [ pull_request, push ]
23
jobs:
34
check-pr:
@@ -44,4 +45,13 @@ jobs:
4445
pip3 install --upgrade -r ./requirements.txt
4546
- name: make linkcheck
4647
run: |
47-
make linkcheck
48+
status=0
49+
make linkcheck || status=$?
50+
mkdir -p ./linkcheck
51+
echo "${status}" > ./linkcheck/status
52+
echo ${{ github.event.number }} > ./linkcheck/pr_number
53+
exit 0 # this step should never fail the overall workflow
54+
- uses: actions/upload-artifact@v4
55+
with:
56+
name: linkcheck
57+
path: linkcheck/

0 commit comments

Comments
 (0)