77
88jobs :
99 check-links :
10- runs-on : ubuntu-22.04 # Updated to explicitly specify Ubuntu 22.04
10+ runs-on : ubuntu-22.04
1111
1212 steps :
1313 - name : Checkout code
@@ -24,34 +24,20 @@ jobs:
2424 - name : Check README links
2525 id : check-links
2626 run : |
27- markdown-link-check README.md > link-check-results.txt || true # Avoid failing the workflow
27+ markdown-link-check README.md > link-check-results.txt || true
2828
29- - name : Process Results
30- id : process-results
29+ - name : Display Results
30+ run : |
31+ echo "#### Link Check Results ####"
32+ cat link-check-results.txt
33+
34+ - name : Fail if Broken Links Found
35+ if : always()
3136 run : |
3237 if grep -q "ERROR" link-check-results.txt; then
33- echo "broken_links=true" >> $GITHUB_ENV
34- echo "$(cat link-check-results.txt)" > broken-links-report.txt
38+ echo "Broken links were found:"
39+ cat link-check-results.txt
40+ exit 1
3541 else
36- echo "broken_links=false" >> $GITHUB_ENV
37- echo "All links are valid!" > broken-links-report.txt
42+ echo "No broken links found! All links are valid."
3843 fi
39-
40- - name : Notify GarlicRot
41- if : always() # Ensure this runs even if previous steps fail
42- uses : actions/github-script@v6
43- with :
44- script : |
45- const fs = require('fs');
46- const report = fs.readFileSync('broken-links-report.txt', 'utf8');
47- const brokenLinks = process.env.broken_links === 'true';
48- const body = brokenLinks
49- ? `### ⚠️ Broken Links Found\nHi @GarlicRot, the following broken links were detected:\n\`\`\`\n${report}\n\`\`\`\nPlease address them!`
50- : `### ✅ All Links Valid\nHi @GarlicRot, all links in the README are valid! Great job!`;
51-
52- await github.rest.repos.createCommitComment({
53- owner: context.repo.owner,
54- repo: context.repo.repo,
55- commit_sha: context.sha,
56- body: body,
57- });
0 commit comments