Skip to content

Added script and workflows to check broken links #10

Added script and workflows to check broken links

Added script and workflows to check broken links #10

Workflow file for this run

name: Check Broken Links
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
check-broken-links:
name: Broken Link Checker
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set Up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install Dependencies
run: |
cd broken-links-script
npm install
- name: Run Broken Link Checker
run: |
cd broken-links-script
node BrokenLinkChecker.js
- name: Parse and Comment Broken Links
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = './broken-links-script/broken_links_markdown.csv';
if (fs.existsSync(path)) {
const data = fs.readFileSync(path, 'utf8').trim();
const lines = data.split('\n').slice(1); // Skip the header line
if (lines.length > 0) {
const body = `### :warning: The following 404 broken links were found:\n\n${broken404Links
.map((line) => {
const [url, file, status] = line.split(',');
return `- **[${url}](${url})** in file \`${file}\` (Status: ${status})`;
})
.join('\n')}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
} else {
console.log('No broken links with 404 status found');
}
} else {
console.log('Error: Broken link checker did not produce a CSV report.');
}