Links (Scheduled → Issue) #2
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: Links (Scheduled → Issue) | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 11 * * 1" # Mondays 11:00 UTC | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| lychee: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Run lychee and write report | |
| id: lychee | |
| uses: lycheeverse/lychee-action@v2 | |
| with: | |
| args: > | |
| --config lychee.toml | |
| --verbose | |
| --no-progress | |
| --output lychee-report.md | |
| --format markdown | |
| **/*.md | |
| continue-on-error: true | |
| - name: Create or update issue if broken links found | |
| if: steps.lychee.outcome == 'failure' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const title = 'Broken links detected'; | |
| const reportPath = 'lychee-report.md'; | |
| const report = fs.existsSync(reportPath) ? fs.readFileSync(reportPath, 'utf8') : '(No report file found)'; | |
| const { data: issues } = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| per_page: 100 | |
| }); | |
| const existing = issues.find(i => i.title === title); | |
| const body = `This is an automated report from a scheduled link check.\n\n${report}`; | |
| if (existing) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existing.number, | |
| body | |
| }); | |
| } else { | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title, | |
| body | |
| }); | |
| } |