Skip to content

Commit 3342712

Browse files
author
Georges Bossert
committed
fix(broken-links): init broken links checks
1 parent 9d345e7 commit 3342712

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Check Broken Links
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Upload preview to OVH Object Storage"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
check-broken-links:
11+
name: Check Broken Links
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout main
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Python
19+
uses: actions/setup-python@v5
20+
id: setup-python
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Download artifact
25+
uses: actions/[email protected]
26+
with:
27+
script: |
28+
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
run_id: ${{github.event.workflow_run.id }},
32+
});
33+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
34+
return artifact.name == "site.tar.gz"
35+
})[0];
36+
var download = await github.rest.actions.downloadArtifact({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
artifact_id: matchArtifact.id,
40+
archive_format: 'zip',
41+
});
42+
var fs = require('fs');
43+
fs.writeFileSync('${{github.workspace}}/site.tar.gz.zip', Buffer.from(download.data));
44+
45+
- run: |
46+
unzip site.tar.gz.zip
47+
mkdir site
48+
tar zxvf site.tar.gz -C ./site
49+
50+
- name: Get PR number
51+
id: pr_number
52+
run: echo "pr_number=$(cat site/.pr_number)" >> $GITHUB_OUTPUT
53+
54+
- name: Find Comment
55+
uses: peter-evans/find-comment@v3
56+
id: fc
57+
with:
58+
issue-number: ${{ steps.pr_number.outputs.pr_number }}
59+
comment-author: github-actions[bot]
60+
body-includes: Found broken links
61+
62+
# install linkchecker
63+
- name: Install linkchecker
64+
run: sudo apt-get install linkchecker
65+
66+
# execute linkchecker on docs.sekoia.io
67+
- name: Check broken links
68+
run: linkchecker --check-extern \
69+
--no-follow-url="!://storage.gra.cloud.ovh.net/v1/AUTH_741841e1c7da4c50a76152cbc2609bd1/sekoiaio-documentation-previews" \
70+
--ignore-url="github.com/SEKOIA-IO" \
71+
--ignore-url="https://storage.gra.cloud.ovh.net/v1/AUTH_741841e1c7da4c50a76152cbc2609bd1/sekoiaio-documentation-previews/${{ steps.pr_number.outputs.pr_number }}/tip/" \
72+
-o csv -F csv \
73+
"https://storage.gra.cloud.ovh.net/v1/AUTH_741841e1c7da4c50a76152cbc2609bd1/sekoiaio-documentation-previews/${{ steps.pr_number.outputs.pr_number }}/getting_started/"
74+
75+
# execute python script to parse the csv file and get the broken links
76+
- name: Parse broken links
77+
run: python scripts/broken_links/create_issues.py linkchecker-out.csv
78+
79+
- name: Add comment to PR
80+
uses: peter-evans/create-or-update-comment@v4
81+
with:
82+
token: ${{ secrets.GITHUB_TOKEN }}
83+
issue-number: ${{ steps.pr_number.outputs.pr_number }}
84+
comment-id: ${{ steps.fc.outputs.comment-id }}
85+
edit-mode: replace
86+
body: |
87+
Found broken links in preview environment !
88+
89+
90+
91+
92+
93+

0 commit comments

Comments
 (0)