|
| 1 | +# Documentation anti-rot gates. |
| 2 | +# |
| 3 | +# Split deliberately into blocking and non-blocking halves: |
| 4 | +# |
| 5 | +# * `docs` (on PRs) -- checks only things that are decidable from the contents |
| 6 | +# of the commit itself: do internal doc links resolve, and is the markdown |
| 7 | +# well formed. Deterministic, offline, fast. Safe to block a merge on. |
| 8 | +# |
| 9 | +# * `external-links` (cron) -- checks whether third-party URLs are still alive. |
| 10 | +# That depends on the internet, not on the diff, so it must never block a |
| 11 | +# merge: a PR touching the compiler should not go red because someone else's |
| 12 | +# blog went down overnight. It runs on a schedule and opens an issue instead. |
| 13 | +# |
| 14 | +# This is not a live-with-the-flakiness compromise; a link that rots in week 30 |
| 15 | +# has nothing to do with whatever PR happens to be open in week 30, so gating a |
| 16 | +# PR on it reports the failure to the one person who cannot fix it. |
| 17 | +# |
| 18 | +# MAINTAINERS: do NOT mark `docs (blocking)` as a required status check in |
| 19 | +# branch protection. The `paths:` filters below mean it never runs at all on a |
| 20 | +# PR that touches no documentation, and a required check that never reports |
| 21 | +# leaves such PRs waiting forever on a check that will never arrive. |
| 22 | +name: docs |
| 23 | + |
| 24 | +on: |
| 25 | + push: |
| 26 | + branches: |
| 27 | + - master |
| 28 | + - '*-stable' |
| 29 | + paths: |
| 30 | + - 'docs/**' |
| 31 | + - '*.md' |
| 32 | + - '.markdownlint-cli2.jsonc' |
| 33 | + - '.lycheeignore' |
| 34 | + - 'lychee.toml' |
| 35 | + - '.yardopts' |
| 36 | + - 'tasks/docs.rake' |
| 37 | + - '.github/workflows/docs.yml' |
| 38 | + pull_request: |
| 39 | + paths: |
| 40 | + - 'docs/**' |
| 41 | + - '*.md' |
| 42 | + - '.markdownlint-cli2.jsonc' |
| 43 | + - '.lycheeignore' |
| 44 | + - 'lychee.toml' |
| 45 | + - '.yardopts' |
| 46 | + - 'tasks/docs.rake' |
| 47 | + - '.github/workflows/docs.yml' |
| 48 | + schedule: |
| 49 | + # Mondays 06:17 UTC. Off-the-hour to dodge the top-of-hour scheduling crush |
| 50 | + # that makes GitHub delay or drop cron runs. |
| 51 | + - cron: '17 6 * * 1' |
| 52 | + workflow_dispatch: {} |
| 53 | + |
| 54 | +permissions: |
| 55 | + contents: read |
| 56 | + |
| 57 | +jobs: |
| 58 | + # --------------------------------------------------------------------------- |
| 59 | + # BLOCKING. Deterministic, no network. |
| 60 | + # --------------------------------------------------------------------------- |
| 61 | + docs: |
| 62 | + name: docs (blocking) |
| 63 | + if: github.event_name != 'schedule' |
| 64 | + runs-on: ubuntu-latest |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + |
| 68 | + - uses: ruby/setup-ruby@v1 |
| 69 | + with: |
| 70 | + ruby-version: '3.4' |
| 71 | + # No `bundle install`: docs:links is plain stdlib Ruby and needs no |
| 72 | + # gems, so it is invoked as `rake`, not `bundle exec rake`. Installing |
| 73 | + # the bundle here would cost minutes for nothing. |
| 74 | + bundler-cache: false |
| 75 | + |
| 76 | + # Internal link integrity. This is the check that would have caught |
| 77 | + # docs/index.md pointing at headless_chrome.html, a page that never |
| 78 | + # existed. It maps the published .html form back to the .md source and |
| 79 | + # resolves it relative to the linking file, so it understands the |
| 80 | + # docs/ layout instead of guessing. |
| 81 | + # |
| 82 | + # Run via `rake -f` so it works whether or not the root Rakefile has |
| 83 | + # picked up tasks/docs.rake yet. |
| 84 | + - name: Internal doc links resolve |
| 85 | + run: rake -f tasks/docs.rake docs:links |
| 86 | + |
| 87 | + - uses: actions/setup-node@v4 |
| 88 | + with: |
| 89 | + node-version: '20' |
| 90 | + |
| 91 | + # Markdown lint. Config is tuned so the current tree passes; see the |
| 92 | + # comments in .markdownlint-cli2.jsonc for why each rule is off. |
| 93 | + # |
| 94 | + # Deliberately advisory (`continue-on-error`) rather than blocking. A hard |
| 95 | + # formatting gate turns a drive-by typo fix into a red X that a first-time |
| 96 | + # contributor cannot debug, and the maintainers end up pushing the fixup |
| 97 | + # anyway. The annotations still show up in the PR, so the signal is there |
| 98 | + # without the toll booth. Promote it to blocking later if the tree stays |
| 99 | + # clean on its own. |
| 100 | + - name: markdownlint |
| 101 | + continue-on-error: true |
| 102 | + run: npx --yes markdownlint-cli2@0.18.1 |
| 103 | + |
| 104 | + # --------------------------------------------------------------------------- |
| 105 | + # NON-BLOCKING. Touches the network, so it only ever reports. |
| 106 | + # --------------------------------------------------------------------------- |
| 107 | + external-links: |
| 108 | + name: external links (scheduled, non-blocking) |
| 109 | + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' |
| 110 | + runs-on: ubuntu-latest |
| 111 | + permissions: |
| 112 | + contents: read |
| 113 | + issues: write |
| 114 | + steps: |
| 115 | + - uses: actions/checkout@v4 |
| 116 | + |
| 117 | + - name: lychee |
| 118 | + id: lychee |
| 119 | + uses: lycheeverse/lychee-action@v2 |
| 120 | + with: |
| 121 | + # --root-dir lets lychee resolve site-absolute links such as `/docs` |
| 122 | + # against the checkout instead of erroring on them. |
| 123 | + args: >- |
| 124 | + --config lychee.toml |
| 125 | + --root-dir ${{ github.workspace }} |
| 126 | + --no-progress |
| 127 | + docs/**/*.md |
| 128 | + README.md |
| 129 | + HACKING.md |
| 130 | + CONTRIBUTING.md |
| 131 | + AGENTS.md |
| 132 | + CONDUCT.md |
| 133 | + output: lychee/out.md |
| 134 | + # Do not let a dead third-party link fail the workflow run; the issue |
| 135 | + # below is the notification channel. |
| 136 | + fail: false |
| 137 | + |
| 138 | + # Surface results as a single rolling issue rather than a red X. Reusing |
| 139 | + # one issue avoids opening a duplicate every Monday. |
| 140 | + - name: Report broken links |
| 141 | + if: steps.lychee.outputs.exit_code != 0 |
| 142 | + uses: peter-evans/create-issue-from-file@v5 |
| 143 | + with: |
| 144 | + title: 'Docs: broken external links detected' |
| 145 | + content-filepath: lychee/out.md |
| 146 | + labels: documentation |
0 commit comments