Skip to content

Commit f03dfb6

Browse files
authored
Add automated link checker (#99)
1 parent adb19ea commit f03dfb6

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Check Links in PRs
2+
3+
on:
4+
pull_request:
5+
paths: ['**.md']
6+
workflow_dispatch:
7+
8+
jobs:
9+
linkChecker:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v5
13+
14+
- name: Link Checker
15+
id: lychee
16+
uses: lycheeverse/lychee-action@v2
17+
with:
18+
fail: true
19+
args: |
20+
'./**/*.md'
21+
--max-concurrency 1
22+
--no-progress
23+
env:
24+
# avoid 429 errors (too many requests) on github.com api requests
25+
GITHUB_TOKEN: ${{secrets.TOKEN_GITHUB}}

.github/workflows/link-checker.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Check Links
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "00 23 * * 0" # Every Sunday 11pm (UTC)
7+
8+
jobs:
9+
linkChecker:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
issues: write # Required for peter-evans/create-issue-from-file
13+
steps:
14+
- uses: actions/checkout@v5
15+
16+
- name: Set up Ruby
17+
uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: '3.0'
20+
bundler-cache: true # installs and caches dependencies
21+
22+
- name: Build Jekyll Site
23+
run: |
24+
bundle exec jekyll build
25+
env:
26+
JEKYLL_ENV: production # Built like production (rather than locally)
27+
28+
29+
- name: Link Checker
30+
id: lychee
31+
uses: lycheeverse/lychee-action@v2
32+
with:
33+
fail: false
34+
# args to check source files without building
35+
# './**/*.md' './**/*.html' './**/*.rst'
36+
args: >
37+
./_site/**/*.html
38+
--max-concurrency 1 --no-progress
39+
--accept '100..=103,200..=399, 429'
40+
--exclude https://doi.org/
41+
env:
42+
# avoid 429 errors (too many requests) on github.com api requests
43+
GITHUB_TOKEN: ${{secrets.TOKEN_GITHUB}}
44+
45+
- name: Set current date
46+
run: echo "REPORT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
47+
48+
# sloppy workaround. Hiding redirects in lychees md format does not work
49+
- name: Clean up Report
50+
run: |
51+
sed -i '/^## Redirects per input/,$d' ./lychee/out.md
52+
sed -i '1i > This report was generated automatically. If links that are reported below are actually working, please ignore the corresponding urls in the `.lycheeignore` to avoid reoccurring error reports in the future.\n\n' ./lychee/out.md
53+
54+
- name: Create Issue From File
55+
if: steps.lychee.outputs.exit_code != 0
56+
uses: peter-evans/create-issue-from-file@v5
57+
with:
58+
title: "🔗 Link Check Report - ${{ env.REPORT_DATE }}"
59+
content-filepath: ./lychee/out.md
60+
labels: bug

0 commit comments

Comments
 (0)