Skip to content

check-links

check-links #779

Workflow file for this run

name: check-links
on:
pull_request:
paths:
- '**/*.md'
- '**/*.rst'
- '.github/workflows/check-links.yml'
- '.github/workflows/check_links_config.json'
merge_group:
types: [checks_requested]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.merge_group.head_ref || github.ref }}
cancel-in-progress: true
jobs:
check-links:
runs-on: cncf-ubuntu-2-8-x86
if: ${{ github.actor != 'dependabot[bot]' && github.actor != 'otelbot[bot]' }}
timeout-minutes: 15
steps:
- name: Checkout Repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Get changed markdown files
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
with:
files: |
**/*.md
**/*.rst
- name: Install markdown-link-check
if: steps.changed-files.outputs.any_changed == 'true'
run: npm install -g markdown-link-check@v3.12.2 # zizmor: ignore[adhoc-packages] pinned CI-only checker is intentionally separate from project dependencies
- name: Check links in merge queue
if: steps.changed-files.outputs.any_changed == 'true' && github.event_name == 'merge_group'
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; }
env:
STEPS_CHANGED_FILES_OUTPUTS_ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
- 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;
# merge-queue runs 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; }
env:
STEPS_CHANGED_FILES_OUTPUTS_ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}