Skip to content

Commit d323d4e

Browse files
committed
Github action to verify if links are broken or not
1 parent 66b6ee7 commit d323d4e

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.github/workflows/links_checkerPR.yml

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

0 commit comments

Comments
 (0)