From 38b0df3915cfacad979d6e8d0b852eb8272e615d Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Wed, 18 Nov 2026 14:41:35 +1100 Subject: [PATCH 1/2] ci(prek): make the download-cache exclusion take effect actions/cache tars each matched path whole and applies an exclusion only to paths the glob matched on its own. With the bare `~/.cache/prek` directory listed, `!~/.cache/prek/cache` matched nothing, so prek's download caches stayed in the archive. Listing the directory's entries (`~/.cache/prek/*`) lets the exclusion drop `cache`. Found by the pre-PR adversarial review. Generated-by: Claude Opus 5 --- .github/workflows/pre-commit.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 871478951..f97453bfe 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -147,8 +147,11 @@ jobs: env: SEGMENT_DOWNLOAD_TIMEOUT_MINS: "2" with: + # `prek/*`, not `prek`: the action tars each matched path whole, so an + # exclusion only drops a path the glob matched on its own. With the + # bare directory, `!…/cache` would match nothing and stay in. path: | - ~/.cache/prek + ~/.cache/prek/* !~/.cache/prek/cache # `v2`: a fresh prefix, so the first run builds a lean archive instead # of restoring the old ~3.5 GB one (download caches and stale envs From 7ae681f586edf49d96d757eb6493bfefda29768c Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Wed, 18 Nov 2026 14:39:17 +1100 Subject: [PATCH 2/2] ci(prek): run lychee from a pinned prebuilt release in CI The lychee hook is `language: rust`, so CI had prek `cargo install` it: a multi-minute compile on ubuntu-slim's single vCPU, and the largest part of the hook-environment cache the job restores on every run (#2175). CI now downloads lychee 0.24.2's static musl release, checks it against the SHA-256 GitHub reports for the asset, and runs it with the hook's own arguments. No new action is involved. Since CI no longer runs the hook, prek builds no Rust environment there; the cache key moves to a `v3` prefix so restore-keys stops carrying the old one forward. Contributors still run the hook locally through prek; both places note that the arguments must stay in step. Generated-by: Claude Opus 5 --- .github/workflows/pre-commit.yml | 60 ++++++++++++++++++++++---------- .pre-commit-config.yaml | 8 +++-- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index f97453bfe..10424c063 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -122,12 +122,11 @@ jobs: # `package = false` so member packages and their # `[project.scripts]` entry points would be skipped. run: uv sync --all-packages --group dev - # Cache prek's hook environments. The `lychee` hook is - # `language: rust` with `additional_dependencies: [cli:lychee:…]`, - # so prek `cargo install`s lychee into a hook env under - # `~/.cache/prek` — a multi-minute compile. Caching that dir - # reuses the built binary (and every other hook env) across runs; - # keyed on the prek config so a hook/version change busts it. + # Cache prek's hook environments, so each run reuses the built envs + # instead of installing every hook's dependencies again; keyed on the + # prek config so a hook/version change busts it. (lychee, the one + # `language: rust` hook, is not among them in CI: it runs from a + # prebuilt binary, see "Install lychee" below.) # # Kept small for `ubuntu-slim` (#2175), whose single vCPU has to # download and unpack the archive on every PR run. The archive had @@ -153,13 +152,15 @@ jobs: path: | ~/.cache/prek/* !~/.cache/prek/cache - # `v2`: a fresh prefix, so the first run builds a lean archive instead - # of restoring the old ~3.5 GB one (download caches and stale envs - # included) through `restore-keys`. Bump it whenever the archive - # must start over rather than carry the previous one forward. - key: prek-v2-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }} + # `v3` (`v2` was the cache-size fix): CI stopped building lychee's + # Rust env (see "Install lychee" below). `prek cache gc` keeps envs + # of every hook the config names, so under the old prefix + # `restore-keys` would carry that env forward for good; a new prefix + # starts the archive without it. Bump it whenever the archive must + # start over rather than carry the previous one forward. + key: prek-v3-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }} restore-keys: | - prek-v2-${{ runner.os }}- + prek-v3-${{ runner.os }}- # There is deliberately no lychee result cache here. `.lychee.toml` # sets `offline = true`, so the hook resolves only in-repo paths and # anchors and never fetches a URL — there are no results to cache. @@ -279,16 +280,39 @@ jobs: # # Cheap enough to do on both events: `.lychee.toml` sets # `offline = true`, so this resolves in-repo paths and `#anchor` - # fragments only and fetches no URL. The hook is `language: rust` - # (no Docker daemon, no service container), so it runs on - # `ubuntu-slim` as happily as on `ubuntu-latest`, and the prek - # hook-env cache above already holds the compiled binary. + # fragments only and fetches no URL. + # + # CI runs lychee's prebuilt release binary rather than the hook: + # the hook is `language: rust`, so prek would `cargo install` it, a + # multi-minute compile on `ubuntu-slim`'s one vCPU and the biggest + # thing in the hook-env cache (#2175). The release tarball is pinned + # by version and SHA-256 (the digest GitHub reports for the asset); + # the static musl build runs on both runner images. The arguments are + # the hook's own, from `.pre-commit-config.yaml`: keep the two in + # step. Contributors still run the hook locally through prek. + - name: Install lychee (pinned prebuilt release) + if: ${{ !cancelled() }} + env: + LYCHEE_VERSION: "0.24.2" + LYCHEE_SHA256: "73657a111819a30c47c08352896796f23d64e4eb2b3ed39b6d32149241566fc5" + run: | + dir="$RUNNER_TEMP/lychee" + mkdir -p "$dir/bin" + curl -sSfL --retry 3 -o "$dir/lychee.tar.gz" \ + "https://github.com/lycheeverse/lychee/releases/download/lychee-v${LYCHEE_VERSION}/lychee-x86_64-unknown-linux-musl.tar.gz" + echo "${LYCHEE_SHA256} $dir/lychee.tar.gz" | sha256sum --check --strict + tar -xzf "$dir/lychee.tar.gz" -C "$dir" + bin="$(find "$dir" -path "$dir/bin" -prune -o -type f -name lychee -print | head -n 1)" + test -n "$bin" + install -m 0755 "$bin" "$dir/bin/lychee" + echo "$dir/bin" >> "$GITHUB_PATH" + "$dir/bin/lychee" --version # # `!cancelled()` rather than `always()`: a link break and a hook # failure in the step above are independent, and a contributor # should see both in one run instead of fixing one to discover the # other. `always()` would also run this on a cancelled job. - - name: Run prek (lychee — whole repo, both events) + - name: Run lychee (whole repo, both events) if: ${{ !cancelled() }} # GITHUB_TOKEN lets lychee authenticate its github.com link # checks — unauthenticated requests get rate-limited (429) once a @@ -298,7 +322,7 @@ jobs: # kept so flipping that back on needs no workflow change. env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: prek run lychee --color=always --all-files + run: lychee --config .lychee.toml --no-progress . # Claude Code mods: `claude plugin validate --strict` and `claude plugin # test` on every plugin whose `hooks/hooks.json` declares `modules`. The # hook is `stages: [manual]` so contributors' commits never fetch the diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4b8090084..266bad3c0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -225,14 +225,16 @@ repos: # whole repo (so a renamed link target is caught no matter which # file references it); `files:` only gates *whether* the whole-repo # scan fires, i.e. it runs when any doc file changes and always on - # `prek run --all-files`. That gate is why CI gives this hook a step - # of its own (`prek run lychee --all-files`, both events) instead of + # `prek run --all-files`. That gate is why CI gives lychee a step + # of its own (whole repo, both events) instead of # letting it ride along with the pull-request run's `--from-ref` # scope: a PR that breaks a link by renaming a non-doc file matches # no `.md`, so the hook would never fire. `.lychee.toml` sets # `offline = true`, so no external URL is fetched and the # `.lycheecache` result cache stays empty — CI carries no cache step - # for it. + # for it. CI runs a pinned prebuilt lychee with this hook's `args` + # rather than the hook itself (no cargo build on the runner, see + # `.github/workflows/pre-commit.yml`): change the args in both places. - repo: local hooks: - id: lychee