Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
steps:
- name: Checkout Repo
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Get changed markdown files
id: changed-files
Expand All @@ -42,11 +44,41 @@ jobs:
if: steps.changed-files.outputs.any_changed == 'true'
run: npm install -g markdown-link-check@v3.12.2

- name: Run markdown-link-check
if: steps.changed-files.outputs.any_changed == 'true'
- name: Check links on push to main
if: steps.changed-files.outputs.any_changed == 'true' && github.event_name == 'push'
run: |
markdown-link-check \
--verbose \
--config .github/workflows/check_links_config.json \
${{ steps.changed-files.outputs.all_changed_files }} \
|| { echo "Check that anchor links are lowercase"; exit 1; }
|| { echo "Check that anchor links are lowercase"; exit 1; }

- name: Check new links only on pull requests
if: steps.changed-files.outputs.any_changed == 'true' && github.event_name == 'pull_request'
run: |
# Extract URLs only from added lines in the diff to avoid
# rate limiting when checking all links in large files like
# CHANGELOG.md. Only new/changed links are checked on PRs;
# pushes to main still check all links in changed files.
git diff "origin/${{ github.base_ref }}...HEAD" -- \
${{ steps.changed-files.outputs.all_changed_files }} \
| grep '^+' | grep -v '^+++' \
| grep -oP 'https?://[^\s\)\]\"'"'"'`>]+' \
| sort -u > /tmp/new_links.txt

if [ ! -s /tmp/new_links.txt ]; then
echo "No new links found in diff, skipping check"
exit 0
fi

echo "Checking $(wc -l < /tmp/new_links.txt) new links:"
cat /tmp/new_links.txt

# Write links as markdown so markdown-link-check can parse them
awk '{print "- <" $0 ">"}' /tmp/new_links.txt > /tmp/new_links.md

markdown-link-check \
--verbose \
--config .github/workflows/check_links_config.json \
/tmp/new_links.md \
|| { echo "Check that anchor links are lowercase"; exit 1; }
Loading