|
|
name: Check Links |
|
|
|
|
|
on: |
|
|
schedule: |
|
|
- cron: '0 0 * * 1' |
|
|
workflow_dispatch: |
|
|
pull_request: |
|
|
paths: ['README.md'] |
|
|
|
|
|
jobs: |
|
|
link-check: |
|
|
runs-on: ubuntu-latest |
|
|
permissions: |
|
|
contents: read |
|
|
issues: write |
|
|
pull-requests: write |
|
|
|
|
|
steps: |
|
|
- name: Checkout |
|
|
uses: actions/checkout@v4 |
|
|
|
|
|
- name: Link Checker |
|
|
uses: lycheeverse/[email protected] |
|
|
with: |
|
|
args: --verbose --no-progress README.md |
|
|
fail: false |
|
|
env: |
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
|
|
|
|
|
- name: Create Issue for Broken Links |
|
|
if: failure() && github.event_name == 'schedule' |
|
|
uses: actions/github-script@v6 |
|
|
with: |
|
|
script: | |
|
|
const date = new Date().toISOString().split('T')[0]; |
|
|
github.rest.issues.create({ |
|
|
owner: context.repo.owner, |
|
|
repo: context.repo.repo, |
|
|
title: `🔗 Broken Links Found - ${date}`, |
|
|
body: `Automated link checking found broken links in the repository. |
|
|
|
|
|
Please check the workflow logs for details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
|
|
|
|
|
--- |
|
|
*This issue was automatically created by the link checker workflow.*`, |
|
|
labels: ['maintenance', 'broken-links'] |
|
|
}); |
|
|
|
|
|
- name: Comment on PR if links are broken |
|
|
if: failure() && github.event_name == 'pull_request' |
|
|
uses: actions/github-script@v6 |
|
|
with: |
|
|
script: | |
|
|
github.rest.issues.createComment({ |
|
|
issue_number: context.issue.number, |
|
|
owner: context.repo.owner, |
|
|
repo: context.repo.repo, |
|
|
body: `⚠️ **Link Check Failed** |
|
|
|
|
|
Some links in your changes appear to be broken or inaccessible. Please check the workflow logs and fix any broken links before merging. |
|
|
|
|
|
**How to check locally:** |
|
|
\`\`\`bash |
|
|
pip install lychee |
|
|
lychee README.md |
|
|
\`\`\` |
|
|
|
|
|
*This comment was automatically generated by the link checker.*` |
|
|
}); |