Skip to content

Commit 4c15e4b

Browse files
authored
fix: make link checker workflow more robust to handle no-changes scenario (#1545)
## Description This PR fixes the link checker workflow that was failing in [run #17112443036](https://github.com/wandb/docs/actions/runs/17112443036/job/48536639778#step:7:1) when there were no auto-fixable changes to commit. ## Problem The `peter-evans/create-pull-request` action fails when there are no changes to commit. This happens when: - All broken links require manual intervention (true 404s) - No broken links are found - The lychee checker finds links but none can be auto-fixed ## Solution 1. **Added change detection**: The workflow now checks if there are actual file changes before attempting to create a PR 2. **Conditional PR creation**: Only creates a PR if there are auto-fixed changes 3. **Issue creation fallback**: When there are no auto-fixes but manual fixes are needed, creates an issue instead 4. **Workflow summary**: Added a summary step to clearly show what actions were taken ## Changes Made - Modified `.github/workflows/linkcheck.yml` to: - Check for file changes using `git status --porcelain` - Check if a report was generated - Only create PR when `has_changes=true` - Create an issue when `has_changes=false` but `has_report=true` and manual fixes are needed - Add a summary step that shows what happened in the workflow run ## Testing Tested locally using the `.github/test-link-checker.sh` script to verify: - ✅ Auto-fixes are applied when possible - ✅ Report is generated correctly - ✅ Change detection logic works - ✅ Generated reference docs are skipped ## Expected Behavior After this fix: - If auto-fixable links are found → Creates PR with fixes - If only manual fixes needed → Creates issue with report - If no broken links → Workflow succeeds with summary - No more workflow failures due to "nothing to commit"
1 parent d142557 commit 4c15e4b

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

.github/workflows/linkcheck.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,24 @@ jobs:
4141
run: |
4242
set -euo pipefail
4343
node .github/scripts/fix_broken_links.mjs || true
44+
45+
# Check if there are any changes to commit
46+
if [[ -n $(git status --porcelain) ]]; then
47+
echo "has_changes=true" >> $GITHUB_OUTPUT
48+
else
49+
echo "has_changes=false" >> $GITHUB_OUTPUT
50+
fi
51+
52+
# Check if report exists
53+
if [[ -f .github/lychee-report.md ]]; then
54+
echo "has_report=true" >> $GITHUB_OUTPUT
55+
else
56+
echo "has_report=false" >> $GITHUB_OUTPUT
57+
fi
4458
4559
- name: Create Pull Request with fixes
4660
id: cpr
61+
if: steps.fix.outputs.has_changes == 'true'
4762
uses: peter-evans/create-pull-request@v6
4863
with:
4964
commit-message: "docs: fix broken links (automated)"
@@ -82,3 +97,51 @@ jobs:
8297
body,
8398
});
8499
}
100+
101+
- name: Create issue for manual fixes if no PR created
102+
if: steps.fix.outputs.has_changes == 'false' && steps.fix.outputs.has_report == 'true'
103+
uses: actions/github-script@v7
104+
with:
105+
script: |
106+
const fs = require('fs');
107+
const reportPath = '.github/lychee-report.md';
108+
109+
let reportContent = 'No report found.';
110+
if (fs.existsSync(reportPath)) {
111+
reportContent = fs.readFileSync(reportPath, 'utf8');
112+
}
113+
114+
// Check if report contains manual follow-ups
115+
if (reportContent.includes('Manual follow-up needed')) {
116+
const issue = await github.rest.issues.create({
117+
owner: context.repo.owner,
118+
repo: context.repo.repo,
119+
title: `Link Check Report: Manual fixes needed (Run #${context.runId})`,
120+
body: `The automated link checker found broken links that require manual intervention.\n\n${reportContent}`,
121+
labels: ['documentation', 'maintenance']
122+
});
123+
124+
console.log(`Created issue #${issue.data.number} for manual link fixes`);
125+
} else {
126+
console.log('No manual fixes needed, skipping issue creation');
127+
}
128+
129+
- name: Summary
130+
if: always()
131+
run: |
132+
echo "## Link Check Summary" >> $GITHUB_STEP_SUMMARY
133+
echo "" >> $GITHUB_STEP_SUMMARY
134+
135+
if [[ "${{ steps.fix.outputs.has_changes }}" == "true" ]]; then
136+
echo "✅ Created PR #${{ steps.cpr.outputs.pull-request-number }} with auto-fixed links" >> $GITHUB_STEP_SUMMARY
137+
elif [[ "${{ steps.fix.outputs.has_report }}" == "true" ]]; then
138+
echo "📋 No auto-fixable changes, but manual fixes are needed (see issue created)" >> $GITHUB_STEP_SUMMARY
139+
else
140+
echo "✨ No broken links found!" >> $GITHUB_STEP_SUMMARY
141+
fi
142+
143+
echo "" >> $GITHUB_STEP_SUMMARY
144+
if [[ -f .github/lychee-report.md ]]; then
145+
echo "### Report Preview" >> $GITHUB_STEP_SUMMARY
146+
head -20 .github/lychee-report.md >> $GITHUB_STEP_SUMMARY
147+
fi

0 commit comments

Comments
 (0)