Skip to content

Commit 65b394f

Browse files
authored
Merge pull request #181 from NeurodataWithoutBorders/link-check-changed-files
Gate pull requests on links in the files they change
2 parents c648203 + ae04ae3 commit 65b394f

1 file changed

Lines changed: 52 additions & 16 deletions

File tree

‎.github/workflows/link-check.yml‎

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,74 @@ on:
55
# Runs weekly every Sunday at 05:00 UTC (midnight EST)
66
schedule:
77
- cron: '0 5 * * 0'
8-
# Runs on pull requests targeting the dev branch
8+
# Runs on pull requests targeting the main branch
99
pull_request:
1010
branches: ["main"]
1111
# Allows you to run this workflow manually from the Actions tab
1212
workflow_dispatch:
1313

14+
permissions:
15+
contents: read
16+
pull-requests: read
17+
18+
env:
19+
# --base resolves root-relative paths (e.g. /events/) against the live site
20+
# --accept includes 403/429 since many destinations (mathworks, hilton, doi.org,
21+
# slack invites) reject lychee's user-agent rather than the link being broken
22+
# --insecure: lychee (and sphinx) hit SSL cert issues on INCF URLs
23+
LYCHEE_ARGS: >-
24+
--verbose
25+
--no-progress
26+
--base 'https://neurodatawithoutborders.github.io/'
27+
--accept '200..=299,403,429'
28+
--max-retries 2
29+
--insecure
30+
1431
jobs:
15-
link_check:
32+
# Blocking check on the content files a pull request adds or edits.
33+
pr_link_check:
34+
if: github.event_name == 'pull_request'
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
40+
- name: List content files changed by this pull request
41+
id: changed
42+
env:
43+
GH_TOKEN: ${{ github.token }}
44+
run: |
45+
files=$(gh api --paginate \
46+
"repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
47+
--jq '.[] | select(.status != "removed") | .filename' \
48+
| grep -E '^content/.*\.(md|html|rst)$' \
49+
| tr '\n' ' ' || true)
50+
echo "files=${files}" >> "$GITHUB_OUTPUT"
51+
echo "Checking: ${files:-(no content files changed)}"
52+
53+
- name: Link Checker
54+
if: steps.changed.outputs.files != ''
55+
uses: lycheeverse/lychee-action@v2
56+
with:
57+
args: ${{ env.LYCHEE_ARGS }} ${{ steps.changed.outputs.files }}
58+
fail: true
59+
60+
# Advisory sweep of every content file. Archived event pages carry dead links
61+
# that are triaged separately, so the run reports them in the job summary
62+
# without failing.
63+
full_link_check:
64+
if: github.event_name != 'pull_request'
1665
runs-on: ubuntu-latest
1766
steps:
1867
- name: Checkout
1968
uses: actions/checkout@v4
2069

2170
- name: Link Checker
22-
id: lychee
2371
uses: lycheeverse/lychee-action@v2
2472
with:
25-
# --base resolves root-relative paths (e.g. /events/) against the live site
26-
# --accept includes 403/429 since many destinations (mathworks, hilton, doi.org,
27-
# slack invites) reject lychee's user-agent rather than the link being broken
28-
# --insecure: lychee (and sphinx) hit SSL cert issues on INCF URLs
2973
args: >-
30-
--verbose
31-
--no-progress
32-
--base 'https://neurodatawithoutborders.github.io/'
33-
--accept '200..=299,403,429'
34-
--max-retries 2
35-
--insecure
74+
${{ env.LYCHEE_ARGS }}
3675
'./content/**/*.md'
3776
'./content/**/*.html'
3877
'./content/**/*.rst'
39-
# Don't block PRs on the report; the job summary still surfaces broken links
40-
# so they can be triaged separately. Pre-existing dead links in archived
41-
# event pages otherwise fail every PR.
4278
fail: false

0 commit comments

Comments
 (0)