Update broken-links.yml #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
| \`\`\` | ||
| ${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, | ||
| }); | ||