|
| 1 | +name: Maintenance |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "0 9 * * 1" |
| 7 | + - cron: "0 9 1 * *" |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + issues: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + link-check: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v6 |
| 19 | + |
| 20 | + - name: Run link checker |
| 21 | + id: lychee |
| 22 | + continue-on-error: true |
| 23 | + run: | |
| 24 | + npx lychee \ |
| 25 | + --verbose \ |
| 26 | + --no-progress \ |
| 27 | + --max-concurrency 8 \ |
| 28 | + --accept 200,429 \ |
| 29 | + --format markdown \ |
| 30 | + README.md > lychee-report.md |
| 31 | +
|
| 32 | + - name: Count dead links |
| 33 | + id: dead-links |
| 34 | + run: | |
| 35 | + if [ "${{ steps.lychee.outcome }}" = "success" ]; then |
| 36 | + echo "dead_count=0" >> "$GITHUB_OUTPUT" |
| 37 | + exit 0 |
| 38 | + fi |
| 39 | + dead_count=$(awk '/^\s*\[✗\]/{count++} END {print count+0}' lychee-report.md) |
| 40 | + echo "dead_count=${dead_count:-0}" >> "$GITHUB_OUTPUT" |
| 41 | +
|
| 42 | + - name: Open or update dead-link issue |
| 43 | + if: steps.dead-links.outputs.dead_count != '0' |
| 44 | + uses: actions/github-script@v8 |
| 45 | + with: |
| 46 | + script: | |
| 47 | + const fs = require("fs"); |
| 48 | + const title = "Automated dead link report"; |
| 49 | + const report = fs.readFileSync("lychee-report.md", "utf8"); |
| 50 | + const body = [ |
| 51 | + "## Dead links detected", |
| 52 | + "", |
| 53 | + `Detected by scheduled maintenance run on ${new Date().toISOString()}.`, |
| 54 | + "", |
| 55 | + `Dead links found: ${process.env.DEAD_COUNT}`, |
| 56 | + "", |
| 57 | + "### Report", |
| 58 | + "", |
| 59 | + report |
| 60 | + ].join("\n"); |
| 61 | +
|
| 62 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + state: "open" |
| 66 | + }); |
| 67 | +
|
| 68 | + const existing = issues.find((issue) => issue.title === title); |
| 69 | +
|
| 70 | + if (existing) { |
| 71 | + await github.rest.issues.update({ |
| 72 | + owner: context.repo.owner, |
| 73 | + repo: context.repo.repo, |
| 74 | + issue_number: existing.number, |
| 75 | + body |
| 76 | + }); |
| 77 | + } else { |
| 78 | + await github.rest.issues.create({ |
| 79 | + owner: context.repo.owner, |
| 80 | + repo: context.repo.repo, |
| 81 | + title, |
| 82 | + body, |
| 83 | + labels: ["type:maintenance", "area:links", "priority:high"] |
| 84 | + }); |
| 85 | + } |
| 86 | + env: |
| 87 | + DEAD_COUNT: ${{ steps.dead-links.outputs.dead_count }} |
| 88 | + |
| 89 | + monthly-stale-entry-review: |
| 90 | + if: github.event_name == 'workflow_dispatch' || (github.event_name == 'schedule' && github.event.schedule == '0 9 1 * *') |
| 91 | + runs-on: ubuntu-latest |
| 92 | + steps: |
| 93 | + - name: Open monthly stale-entry review issue |
| 94 | + uses: actions/github-script@v8 |
| 95 | + with: |
| 96 | + script: | |
| 97 | + const now = new Date().toISOString().slice(0, 10); |
| 98 | + const title = `Monthly stale entry review (${now.slice(0, 7)})`; |
| 99 | + const body = [ |
| 100 | + "## Monthly stale entry review", |
| 101 | + "", |
| 102 | + "Review the list for stale entries and open targeted cleanup PRs.", |
| 103 | + "", |
| 104 | + "### Checklist", |
| 105 | + "- [ ] Verify links for recently changed websites.", |
| 106 | + "- [ ] Remove or replace deprecated entries.", |
| 107 | + "- [ ] Refresh outdated descriptions.", |
| 108 | + "- [ ] Re-check category fit for recent additions." |
| 109 | + ].join("\\n"); |
| 110 | +
|
| 111 | + await github.rest.issues.create({ |
| 112 | + owner: context.repo.owner, |
| 113 | + repo: context.repo.repo, |
| 114 | + title, |
| 115 | + body, |
| 116 | + labels: ["type:maintenance", "priority:medium", "status:triage"] |
| 117 | + }); |
0 commit comments