Skip to content

Commit c8a2a43

Browse files
authored
Merge pull request #13 from CyrilBaah/link_checker
Link checker
2 parents 9ab94df + 89f70c7 commit c8a2a43

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/links_checkerPR.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "Check docs links"
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
paths:
7+
- "README.md"
8+
- ".github/workflows/links_checkerPR.yml"
9+
10+
jobs:
11+
linkChecker:
12+
if: github.actor != 'dependabot[bot]'
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Link Checker
18+
id: lychee
19+
uses: lycheeverse/lychee-action@v1
20+
21+
- name: Read link checker output
22+
id: read_links
23+
run: |
24+
error_count=$(grep -c "🚫 Errors" ./lychee/out.md) # Count errors
25+
echo "error_count=$error_count" >> $GITHUB_ENV # Set error count
26+
if [ "$error_count" -gt 0 ]; then
27+
echo "broken_links<<EOF" >> $GITHUB_ENV
28+
cat ./lychee/out.md >> $GITHUB_ENV # Set broken links detail
29+
echo "EOF" >> $GITHUB_ENV
30+
else
31+
echo "broken_links=All links in the README.md are working fine! 🎉" >> $GITHUB_ENV
32+
fi
33+
shell: bash
34+
35+
- name: Set output for error count
36+
run: echo "::set-output name=error_count::${{ env.error_count }}"
37+
38+
- name: Create or Update Comment - No Broken Links
39+
if: env.lychee_exit_code == '0' # Run if there are no broken links
40+
uses: peter-evans/create-or-update-comment@v4
41+
with:
42+
issue-number: ${{ github.event.pull_request.number }}
43+
body: |
44+
**Link Checker Report:**
45+
All links in the README.md are working fine! 🎉
46+
reactions: hooray # React with a 'hooray' if there are no broken links
47+
48+
- name: Create or Update Comment - Summary of Broken Links
49+
if: env.lychee_exit_code != '0' # Run if there are broken links
50+
uses: peter-evans/create-or-update-comment@v4
51+
with:
52+
issue-number: ${{ github.event.pull_request.number }}
53+
body: |
54+
**Link Checker Report:**
55+
The following links are broken in the README.md:
56+
```markdown
57+
${{ env.broken_links }}
58+
```

0 commit comments

Comments
 (0)