From c80423af8139f026ac1a48a6ce09a163be24686b Mon Sep 17 00:00:00 2001 From: Mike Goldsmith Date: Wed, 29 Apr 2026 16:02:05 +0100 Subject: [PATCH] only check new links on pull requests to avoid rate limiting Large files like CHANGELOG.md contain hundreds of links. Checking all of them on every PR triggers HTTP 502 rate limits. On PRs, now only URLs from added lines in the diff are checked. Pushes to main still check all links in changed files for full validation. Assisted-by: Claude Opus 4.6 --- .github/workflows/check-links.yml | 38 ++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-links.yml b/.github/workflows/check-links.yml index 70490b782d..6a895980ba 100644 --- a/.github/workflows/check-links.yml +++ b/.github/workflows/check-links.yml @@ -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 @@ -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; } \ No newline at end of file + || { 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; }