Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions .github/lychee.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ no_progress = false
############################# Cache ###############################
# Enable link caching. This can be helpful to avoid checking the same links on
# multiple runs.
cache = true

# Discard all cached requests older than this duration.
max_cache_age = "1d"
cache = false

############################# Runtime #############################
# Maximum number of concurrent link checks.
Expand Down
76 changes: 15 additions & 61 deletions .github/workflows/check-pr-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@ on:
branches:
- main
paths:
- '**/*.md' # Only trigger workflow if any Markdown files change
- '**/*.md'

jobs:
check-links:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout GitHub repo
uses: actions/checkout@v4
# Checkout repo
- uses: actions/checkout@v4
with:
fetch-depth: 0

# Step 2: Check out base branch
- name: Check out base branch
run: git checkout ${{ github.event.pull_request.base.ref }}

# Step 3: Get changed Markdown files
# Find changed Markdown files
- name: Get changed Markdown files
id: changed-files
run: |
Expand All @@ -30,39 +25,14 @@ jobs:
echo "Changed Markdown files:"
echo "$files"

# Step 4: Skip workflow if no Markdown files changed
# Skip if no Markdown files
- name: Skip if no Markdown files changed
if: ${{ env.changed_files == '' }}
run: |
echo "No Markdown files changed in this PR. Skipping link check."
echo "No Markdown files changed. Skipping link check."
exit 0

# Step 5: Dump base branch links for changed files only (no fragments)
- name: Dump base branch links
uses: lycheeverse/lychee-action@v2
with:
args: "--dump ${{ env.changed_files }}"
output: ./existing-links.txt
continue-on-error: true

# Step 6: Stash untracked files and switch back to feature branch
- name: Stash untracked files
run: git stash push --include-untracked

- name: Check out feature branch
run: git checkout ${{ github.head_ref }}

- name: Apply stashed changes
run: git stash pop || true

# Step 7: Add base branch links to .lycheeignore
- name: Update ignore file
run: |
if [ -f "existing-links.txt" ]; then
cat existing-links.txt >> .lycheeignore
fi

# Step 8: Run Lychee on changed files one by one and extract broken links
# Run Lychee
- name: Run Lychee link checker
id: lychee
continue-on-error: true
Expand All @@ -73,33 +43,17 @@ jobs:
lychee --no-progress --include-fragments "$f" >> lychee-full-report.txt || true
done

# Extract only broken links
if [ -f lychee-full-report.txt ]; then
grep -E "❌|ERROR" lychee-full-report.txt > lychee-broken.txt || true
# Extract only broken links for log
if grep -qE "❌|ERROR" lychee-full-report.txt; then
echo "❌ Broken links found:"
grep -E "❌|ERROR" lychee-full-report.txt
else
echo "No report generated." > lychee-broken.txt
echo "βœ… No broken links found."
fi

echo "full_report=lychee-full-report.txt" >> $GITHUB_ENV
echo "broken_report=lychee-broken.txt" >> $GITHUB_ENV

# Step 9: Upload full report for debugging (optional)
- name: Upload full Lychee report
# Upload full report as artifact
- name: Upload Lychee full report
uses: actions/upload-artifact@v4
with:
name: lychee-full-report
path: ${{ env.full_report }}

# Step 10: Post PR comment with only broken links
- name: Comment broken links on PR
if: always()
uses: marocchino/sticky-pull-request-comment@v2
with:
path: ${{ env.broken_report }}

# Step 11: Fail if broken links exist
- name: Fail on broken links
if: steps.lychee.outcome == 'failure'
run: |
echo "::error::Broken links detected. See the PR comment above for details."
exit 1
path: lychee-full-report.txt