Skip to content

Update broken-links.yml #4

Update broken-links.yml

Update broken-links.yml #4

Workflow file for this run

name: Check README for Broken Links
on:
push:
branches:
- main
jobs:
check-links:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install markdown-link-check
run: npm install -g markdown-link-check
- name: Check README links
id: check-links
run: |
markdown-link-check README.md > link-check-results.txt || exit 0
- name: Process Results
id: process-results
run: |
if grep -q "ERROR" link-check-results.txt; then
echo "broken_links=true" >> $GITHUB_ENV
echo "::set-output name=report::$(cat link-check-results.txt | sed 's/%/%25/g; s/\n/%0A/g; s/\r/%0D/g')"
else
echo "broken_links=false" >> $GITHUB_ENV
echo "::set-output name=report::All links are valid!"
fi
- name: Notify GarlicRot
uses: actions/github-script@v6
with:
script: |
const report = process.env.REPORT;
const body = process.env.broken_links === 'true'
? `### ⚠️ Broken Links Found
Hi @GarlicRot, the following broken links were detected:
\`\`\`

Check failure on line 48 in .github/workflows/broken-links.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/broken-links.yml

Invalid workflow file

You have an error in your yaml syntax on line 48
${report}
\`\`\`
Please address them!`
: `### ✅ All Links Valid
Hi @GarlicRot, all links in the README are valid! Great job!`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.runId,
body,
});