Skip to content

Key each uv cache on the file that pins its tools - #26

Merged
GavinLucas merged 3 commits into
mainfrom
fix/setup-uv-cache-glob
Nov 19, 2026
Merged

GavinLucas merged 3 commits into
mainfrom
fix/setup-uv-cache-glob

Conversation

@GavinLucas

@GavinLucas GavinLucas commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

  1. The premerge jobs that set up uv (actionlint and "Shared workflows and actions behave") now key setup-uv's cache on .github/workflows/premerge.yaml, through cache-dependency-glob. That file is where their tools are pinned. Each job also gets its own cache-suffix (${{ github.job }}).
  2. The repo-hygiene action keys its uv cache on its own script, through ${{ github.action_path }}/check-repo-hygiene.py. The script pins its one dependency inline.

Why

  • The warnings. setup-uv's default glob looks for requirements, pyproject.toml and lock files in the workspace. This repository has none, and neither do callers like quaffed, so every run warned "The cache will never get invalidated". That is two warnings here, and one in every caller's hygiene job.
  • The shared key. The two premerge jobs install different tools under one cache key. setup-uv saves nothing on an exact hit, so the job that saved first kept the other's tools out of the cache, and the other job downloaded them on every run (found in review).

No wrong version was ever installed: every tool is pinned exactly.

Checked

  • At the pinned setup-uv commit 68559e99:
    • cache-dependency-glob and cache-suffix are real inputs;
    • the key ends with the suffix;
    • hashFiles says it "supports hashing files outside the GITHUB_WORKSPACE".
  • The warning in a caller: it's on quaffed's main hygiene job.
  • Locally: actionlint is clean.

Not yet observed

  • The premerge warnings gone: this PR's own run shows it.
  • The repo-hygiene change: nothing in this repository runs that action, so it is first seen on a caller's run once a release moves v2. If github.action_path did not resolve there, setup-uv would warn as before, or the glob would match nothing; the hygiene check itself is unaffected. That run is what confirms it.

setup-uv keys its cache on a project's dependency files, requirements,
pyproject.toml, uv.lock and the like, and this repository has none: the
versions of actionlint-py, pytest and pyyaml are pinned in premerge.yaml.
So nothing matched, the cache key never changed, and both jobs that set
up uv warned on every run that the cache would never be invalidated.
Keyed on premerge.yaml, a changed pin starts a new cache, and the
warnings stop, so a new warning on these jobs is not lost among them.
Each uvx call names exact versions, so the old cache never installed a
wrong one; the cost was the noise.

Signed-off-by: Gavin Lucas <Gavin@L337.org>
@github-actions

Copy link
Copy Markdown

Claude review: approve

What changed

The range changes one file, .github/workflows/premerge.yaml. It adds cache-dependency-glob: .github/workflows/premerge.yaml to the astral-sh/setup-uv step in the actionlint job and the shared-behaviour job, with the same two-line comment above each.

What I checked

  • Instruction files: the repository has no CLAUDE.md or AGENTS.md, so I had no review rules to apply beyond the brief.
  • The input exists and is used as intended: I read setup-uv's action.yml and source at the pinned SHA 68559e99….
    • cache-dependency-glob is a real input. Its default lists requirements, constraints, pyproject.toml, uv.lock and *.py.lock files. This repository has none of them.
    • computeKeys (src/cache/restore-cache.ts) warns "No file matched … The cache will never get invalidated" when the glob matches nothing. With a glob that matches, the warning stops, which is what the commit message says.
    • The glob is resolved against the working directory. That defaults to github.workspace, and both jobs check out the repository before this step, so the path matches.
  • Caching is really on: enable-cache defaults to auto, which caches on GitHub-hosted runners for push, pull_request and workflow_dispatch. The new setting therefore has an effect on every trigger this workflow has.
  • No correctness risk: each uvx call pins exact versions (actionlint-py==1.7.12.25, pytest==8.3.5, pyyaml==6.0.3), so a cache from any key cannot install the wrong version.
  • The YAML parses: both with: blocks load as expected.
  • Tests: only tests/test_release_actions.py reads premerge.yaml, and only its input-defaults job. No test covers the setup-uv steps, and none is needed for this change.
  • Recorded state in the added comments: "The tools' versions are pinned in this file, not in a requirements or project file" gives the reason for the setting, and the uvx lines in the same file prove it. "A changed pin starts a new cache" describes what the setting does. Neither is a recorded-state finding.
  • Docs: the README does not describe how premerge caches, so nothing there becomes untrue.

Findings

1. maintainability (non-blocking, existed before this change): the two jobs share one cache key, so one job's tools are never cached. .github/workflows/premerge.yaml:48 and :75

  • setup-uv builds its key as setup-uv-2-<arch>-<platform>-<os>-<python>…<hash of the glob's files><suffix> (computeKeys in src/cache/restore-cache.ts). The job is not part of it.
  • actionlint and shared-behaviour set the same glob and run on the same runner image, so they compute the same key.
  • On the first run after premerge.yaml changes, whichever job saves first stores a cache holding only its own tools: actionlint-py, or pytest and pyyaml. The other job's save is refused because the key already exists.
  • On later runs both jobs get an exact hit on that key, and save-cache.ts skips saving on an exact hit (if (matchedKey === cacheKey)). The losing job downloads its tools on every run until premerge.yaml changes again.
  • The old key (…-no-dependency-glob) was shared the same way, so this change did not cause the problem. But the new comment says "a changed pin starts a new cache", which implies each job's pinned tools are cached, and today that is true for only one of the two.
  • Fix: give each step its own suffix, for example cache-suffix: ${{ github.job }}, or a literal per job.

Note, not a finding: the glob hashes the whole of premerge.yaml. Any edit to it, including a Dependabot bump of actions/checkout or a comment change, also starts a new cache, not only a changed tool pin. That costs one cold download per job, which is cheap. The comment is not wrong; it just names only the case that matters.

What I did not check

  • I could not run the test suite or actionlint locally, because neither uv nor pytest is installed in this environment.
  • I did not see a premerge run of this commit, so the claim that the warning is gone rests on reading setup-uv's source, not on a log.
  • actions/repo-hygiene/action.yml also calls setup-uv without a glob, and callers with no dependency files will still get the same warning. That action is outside this change, and its pins live in the action's own directory, outside the caller's workspace, so the same fix would not apply directly.

full review of 9095a134a5c8..8a288a151a5a. Run.

actionlint and shared-behaviour installed different tools under one cache
key, and setup-uv saves nothing on an exact hit, so whichever job saved
first kept the other's tools out of the cache, and that job downloaded
them on every run.  The job's name is now the key's suffix.

Signed-off-by: Gavin Lucas <Gavin@L337.org>
The action set up uv with setup-uv's default glob, which looks in the
caller's workspace for requirements and project files.  The script pins
its one dependency inline and lives in the action's directory, so in a
caller with no Python project files nothing matched, and every caller's
hygiene job warned that the cache would never be invalidated; quaffed's
does.  setup-uv hashes files outside the workspace, so the glob is now
the script itself, through github.action_path.

Signed-off-by: Gavin Lucas <Gavin@L337.org>
@GavinLucas GavinLucas changed the title Key setup-uv's cache on the file that pins the tools Key each uv cache on the file that pins its tools Nov 19, 2026
@github-actions

Copy link
Copy Markdown

Claude review: approve

Resolved

  • Shared cache key between actionlint and shared-behaviour (previous finding 1, maintainability): fixed. Both setup-uv steps now set cache-suffix: ${{ github.job }} (.github/workflows/premerge.yaml, the two with: blocks). The job id is now part of each key, so each job saves and restores its own tools. The github.job context is available in step with: inputs, so the expression is valid. The comment above each setting now says why.

Still open

None.

Declined

None.

New

None. The delta is the cache-suffix line and the extended comment in each of the two steps.

  • The comment says what the setting does and why, not what was measured, so it holds nothing that will go stale.
  • The repository has no CLAUDE.md or AGENTS.md, so there were no review rules to apply.
  • I did not check cache-suffix against setup-uv's source at the pinned SHA this round. It is a documented input, and the previous round read the same computeKeys code that appends it to the key.
  • I did not see a premerge run of this commit, so the behaviour is not confirmed from a log.
  • The repo-hygiene action's setup-uv call is outside this change, as the previous round noted.

delta review of 8a288a151a5a..393d457caad2. Run.

@GavinLucas

Copy link
Copy Markdown
Contributor Author

The shared key: confirmed and fixed in 393d457. setup-uv's key at the pinned commit ends in the suffix (computeKeys in restore-cache.ts), and each job now passes cache-suffix: ${{ github.job }}. The comment now gives that reason too.

Your note about repo-hygiene is the same warning, and it does appear in callers: quaffed's main hygiene job carries it. Fixed in 1e3449f by keying on the script itself through ${{ github.action_path }}, since setup-uv's hashFiles says it hashes files outside the workspace. That one can only be observed on a caller's run after the next release; the PR description says so.

@github-actions

Copy link
Copy Markdown

Claude review: approve

Resolved

  • repo-hygiene setup-uv cache warning (previous note, outside the earlier delta): fixed in actions/repo-hygiene/action.yml. The setup-uv step now sets cache-dependency-glob: ${{ github.action_path }}/check-repo-hygiene.py. The file exists at that path. It is the same file the later uv run --script "$GITHUB_ACTION_PATH/check-repo-hygiene.py" step runs, so the cache key follows the script that pins the dependencies. The github context, including action_path, is available in a composite action's step with: inputs.

Still open

None.

Declined

None.

New

None.

  • The new comment gives a rule and its reason, with no recorded state, so nothing in it will go stale.
  • I did not check against setup-uv's source that an absolute path outside the workspace is hashed. The comment and the reply both say it is. The PR description says it can only be seen on a caller's run after the next release.
  • I did not see a workflow run of this commit.
  • The repository has no CLAUDE.md or AGENTS.md, so there were no review rules to apply.

delta review of 393d457caad2..1e3449ff8311. Run.

@GavinLucas
GavinLucas merged commit 29b5ab9 into main Nov 19, 2026
10 checks passed
@GavinLucas
GavinLucas deleted the fix/setup-uv-cache-glob branch November 19, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant