Skip to content

Commit 73678be

Browse files
only check new links on pull requests to avoid rate limiting (open-telemetry#5162)
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
1 parent ee2be49 commit 73678be

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

.github/workflows/check-links.yml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
steps:
3030
- name: Checkout Repo
3131
uses: actions/checkout@v6
32+
with:
33+
fetch-depth: 0
3234

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

45-
- name: Run markdown-link-check
46-
if: steps.changed-files.outputs.any_changed == 'true'
47+
- name: Check links on push to main
48+
if: steps.changed-files.outputs.any_changed == 'true' && github.event_name == 'push'
4749
run: |
4850
markdown-link-check \
4951
--verbose \
5052
--config .github/workflows/check_links_config.json \
5153
${{ steps.changed-files.outputs.all_changed_files }} \
52-
|| { echo "Check that anchor links are lowercase"; exit 1; }
54+
|| { echo "Check that anchor links are lowercase"; exit 1; }
55+
56+
- name: Check new links only on pull requests
57+
if: steps.changed-files.outputs.any_changed == 'true' && github.event_name == 'pull_request'
58+
run: |
59+
# Extract URLs only from added lines in the diff to avoid
60+
# rate limiting when checking all links in large files like
61+
# CHANGELOG.md. Only new/changed links are checked on PRs;
62+
# pushes to main still check all links in changed files.
63+
git diff "origin/${{ github.base_ref }}...HEAD" -- \
64+
${{ steps.changed-files.outputs.all_changed_files }} \
65+
| grep '^+' | grep -v '^+++' \
66+
| grep -oP 'https?://[^\s\)\]\"'"'"'`>]+' \
67+
| sort -u > /tmp/new_links.txt
68+
69+
if [ ! -s /tmp/new_links.txt ]; then
70+
echo "No new links found in diff, skipping check"
71+
exit 0
72+
fi
73+
74+
echo "Checking $(wc -l < /tmp/new_links.txt) new links:"
75+
cat /tmp/new_links.txt
76+
77+
# Write links as markdown so markdown-link-check can parse them
78+
awk '{print "- <" $0 ">"}' /tmp/new_links.txt > /tmp/new_links.md
79+
80+
markdown-link-check \
81+
--verbose \
82+
--config .github/workflows/check_links_config.json \
83+
/tmp/new_links.md \
84+
|| { echo "Check that anchor links are lowercase"; exit 1; }

0 commit comments

Comments
 (0)