-
Notifications
You must be signed in to change notification settings - Fork 51
67 lines (63 loc) · 2.11 KB
/
check-external-links.yml
File metadata and controls
67 lines (63 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: Check External Links
on:
pull_request:
branches:
- main
paths:
- "docs/**"
- ".github/workflows/check-external-links.yml"
jobs:
check-external-links:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v6
- name: Restore lychee cache
uses: actions/cache@v5
with:
path: .lycheecache
key: cache-lychee-${{ hashFiles('lychee.toml') }}
restore-keys: cache-lychee-
- name: Link Checker
id: lychee
uses: lycheeverse/lychee-action@v2
continue-on-error: true
with:
lycheeVersion: "latest"
args: |
--config lychee.toml
docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare broken link report
id: lychee_report
if: ${{ steps.lychee.outputs.exit_code && steps.lychee.outputs.exit_code != '0' }}
shell: bash
run: |
report_file="lychee/out.md"
if [[ ! -s "$report_file" ]]; then
echo "report<<EOF" >> "$GITHUB_OUTPUT"
echo "Lychee detected broken links, but the report file (\`$report_file\`) was empty or missing." >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "report<<EOF" >> "$GITHUB_OUTPUT"
cat "$report_file" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Comment on PR if broken links found
if: ${{ steps.lychee.outputs.exit_code && steps.lychee.outputs.exit_code != '0' }}
uses: thollander/actions-comment-pull-request@v3
with:
message: |
### 🚨 Broken links detected
<details>
<summary>Click to expand</summary>
${{ steps.lychee_report.outputs.report }}
</details>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail if broken links found
if: ${{ failure() || (steps.lychee.outputs.exit_code && steps.lychee.outputs.exit_code != '0') }}
run: exit 1