Links #3
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 | |
| on: | |
| schedule: | |
| - cron: "0 6 * * 1" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Check links | |
| id: lychee | |
| uses: lycheeverse/lychee-action@v2 | |
| with: | |
| # Checks github.com through the API instead of scraping it, which is what | |
| # keeps 55 repo links off the anonymous rate limit. | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # /stargazers is login-walled — it 404s for anonymous clients on every | |
| # repo, ours and psf/requests alike. pepy download badges 404 by design | |
| # until a listed package reaches PyPI (AGENTS.md), and test_profile.py | |
| # already pins each badge to its repo name. | |
| args: >- | |
| --cache | |
| --max-cache-age 1d | |
| --no-progress | |
| --exclude 'github\.com/.*/stargazers' | |
| --exclude 'static\.pepy\.tech' | |
| '**/*.md' | |
| fail: false | |
| # create-issue-from-file does not deduplicate — it calls issues.create | |
| # unconditionally, so six weeks of one dead link is six identical issues. This is | |
| # the same find-or-comment shape every repo's report-scheduled-failure.sh uses. | |
| - name: Open or update the tracking issue | |
| if: steps.lychee.outputs.exit_code != 0 | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| run: | | |
| set -euo pipefail | |
| LABEL="broken-links" | |
| gh label create "$LABEL" \ | |
| --color "D93F0B" \ | |
| --description "Weekly external link check failures" \ | |
| --force | |
| # The report is what changes week to week, so each comment carries the current | |
| # one; 30k keeps a long report inside GitHub's comment limit. | |
| report=$(head -c 30000 lychee/out.md 2>/dev/null || echo "(no report file produced)") | |
| existing=$(gh issue list --label "$LABEL" --state open --json number --jq '.[0].number // empty') | |
| if [ -z "$existing" ]; then | |
| gh issue create --title "Broken links found" --label "$LABEL" --body "$(printf '%s\n\n%s\n\n%s' \ | |
| "The weekly external link check failed. Close this issue once the links are fixed; the next failure opens a fresh one." \ | |
| "First failing run: ${RUN_URL}" \ | |
| "$report")" | |
| else | |
| gh issue comment "$existing" --body "$(printf '%s\n\n%s' \ | |
| "Still failing: ${RUN_URL}" \ | |
| "$report")" | |
| fi |