Skip to content

Commit c1a3df4

Browse files
committed
Smarter link checker
1 parent 6d7cd87 commit c1a3df4

1 file changed

Lines changed: 48 additions & 3 deletions

File tree

.github/workflows/link-check.yml

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
run: npm run build
3232

3333
- name: Check links
34+
id: lychee
3435
uses: lycheeverse/lychee-action@v1
3536
with:
3637
# Check all HTML files in the built site
@@ -40,13 +41,45 @@ jobs:
4041
env:
4142
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
4243

43-
- name: Create Issue on failure
44+
- name: Close issue if links are fixed
45+
if: success()
46+
uses: actions/github-script@v7
47+
with:
48+
script: |
49+
// Find any open issues with the broken-links label
50+
const issues = await github.rest.issues.listForRepo({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
state: 'open',
54+
labels: ['broken-links']
55+
});
56+
57+
// Close all open broken-links issues
58+
for (const issue of issues.data) {
59+
await github.rest.issues.createComment({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
issue_number: issue.number,
63+
body: `✅ All links are now working! Closing this issue.\n\nFixed in [workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId}).`
64+
});
65+
66+
await github.rest.issues.update({
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
issue_number: issue.number,
70+
state: 'closed'
71+
});
72+
73+
console.log(`Closed issue #${issue.number}`);
74+
}
75+
76+
- name: Create or update issue on failure
4477
if: failure()
4578
uses: actions/github-script@v7
4679
with:
4780
script: |
4881
const title = '🔗 Broken links detected';
49-
const body = `The scheduled link check found broken links.\n\nCheck the [workflow run](${context.payload.repository.html_url}/actions/runs/${context.runId}) for details.`;
82+
const body = `The link checker found broken links.\n\n**Workflow run:** ${context.payload.repository.html_url}/actions/runs/${context.runId}\n\n**Date:** ${new Date().toISOString()}\n\nPlease check the workflow run for details on which links are broken.`;
5083
5184
// Check if an issue already exists
5285
const issues = await github.rest.issues.listForRepo({
@@ -56,12 +89,24 @@ jobs:
5689
labels: ['broken-links']
5790
});
5891
59-
if (issues.data.length === 0) {
92+
if (issues.data.length > 0) {
93+
// Update existing issue
94+
const issue = issues.data[0];
95+
await github.rest.issues.createComment({
96+
owner: context.repo.owner,
97+
repo: context.repo.repo,
98+
issue_number: issue.number,
99+
body: `🔗 Broken links still detected (or new ones found).\n\n**Latest workflow run:** ${context.payload.repository.html_url}/actions/runs/${context.runId}\n**Date:** ${new Date().toISOString()}`
100+
});
101+
console.log(`Updated existing issue #${issue.number}`);
102+
} else {
103+
// Create new issue
60104
await github.rest.issues.create({
61105
owner: context.repo.owner,
62106
repo: context.repo.repo,
63107
title: title,
64108
body: body,
65109
labels: ['broken-links']
66110
});
111+
console.log('Created new issue');
67112
}

0 commit comments

Comments
 (0)