Check README Links #96
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 Links | |
on: | |
push: | |
branches: [ main, master ] | |
paths: [ 'README.md', 'readme.md', 'Readme.md' ] | |
pull_request: | |
branches: [ main, master ] | |
paths: [ 'README.md', 'readme.md', 'Readme.md' ] | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
check-links: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Install lychee | |
run: | | |
curl -L https://github.com/lycheeverse/lychee/releases/latest/download/lychee-x86_64-unknown-linux-gnu.tar.gz | tar xz | |
sudo mv lychee /usr/local/bin/ | |
- name: Setup configuration | |
run: | | |
chmod +x .github/scripts/setup-config.sh | |
./.github/scripts/setup-config.sh | |
- name: Check README links | |
id: link-check | |
run: | | |
chmod +x .github/scripts/check-links.sh | |
./.github/scripts/check-links.sh | |
- name: Handle dead links | |
if: steps.link-check.outputs.dead_links_found == 'true' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const { execSync } = require('child_process'); | |
// Make script executable and run it | |
execSync('chmod +x .github/scripts/handle-issues.js'); | |
execSync('node .github/scripts/handle-issues.js', { | |
env: { | |
...process.env, | |
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}', | |
GITHUB_REPOSITORY: context.repo.owner + '/' + context.repo.repo, | |
GITHUB_WORKFLOW: context.workflow, | |
TOTAL_FILES: '${{ steps.link-check.outputs.total_files }}', | |
FILES_WITH_ISSUES: '${{ steps.link-check.outputs.files_with_issues }}', | |
BROKEN_LINKS: '${{ steps.link-check.outputs.broken_links }}' | |
} | |
}); | |
- name: Close fixed issues | |
if: steps.link-check.outputs.dead_links_found == 'false' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { execSync } = require('child_process'); | |
execSync('chmod +x .github/scripts/close-issues.js'); | |
execSync('node .github/scripts/close-issues.js', { | |
env: { | |
...process.env, | |
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}', | |
GITHUB_REPOSITORY: context.repo.owner + '/' + context.repo.repo, | |
TOTAL_FILES: '${{ steps.link-check.outputs.total_files }}' | |
} | |
}); | |
- name: Upload results | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: link-check-results-${{ github.run_number }} | |
path: link-check-results/ | |
retention-days: 30 | |
- name: Set job summary | |
if: always() | |
run: | | |
if [ -f "link-check-results/results.md" ]; then | |
cat link-check-results/results.md >> $GITHUB_STEP_SUMMARY | |
fi |