ci: cache .mypy_cache in the test matrix - #86
Merged
Conversation
An Actions audit across every repo in the account found `finances` was the only one caching `.mypy_cache`. Here mypy runs cold six times per CI run, once per matrix entry. The key includes the interpreter version: mypy's results depend on the Python version it analyses under, so without it the six matrix jobs would race for a single cache entry. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VHqcUw1PJ8Dvo2D5WUHbKM
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
An Actions usage audit across all ten repos in the account (2026-08-01..21) found that
financesis the only repo that caches.mypy_cache. Everywhere else mypy runs cold.This repo pays that cost six times per CI run — once per matrix entry — across a 6-version Python matrix.
What changed
Adds an
actions/cachestep for.mypy_cachebefore the mypy step.The cache key is the one part worth reviewing:
matrix.python-versionis in the key deliberately. mypy's results depend on the interpreter version it analyses under, so the six jobs must not share one entry — without it they'd race to write a single key, and five of the six would restore a cache built for a different Python.The rest mirrors the block in
finances:uv.lockpins the mypy version andpyproject.tomlholds its config, so either changing invalidates the cache rather than silently reusing results computed under different rules;github.shakeeps each run's key unique (Actions cache entries are immutable, so an existing key is never rewritten) whilerestore-keysfalls back to the newest entry for the same version+lock+config.The cache works here because
tests.ymlalready runs on push tomaster— a cache written by a PR run is scoped to that PR, and only a default-branch cache is readable from every new branch.Scope of the benefit
This is a wall-clock improvement rather than a billing one. The matrix means six jobs each bill a minimum of one rounded minute regardless, so shaving seconds off mypy won't reduce the bill unless a job is near the 60s line. It shortens the feedback loop and reduces the chance of jobs drifting over that line as the project grows.
Testing
Not run before opening this PR — the change adds one
uses:step and leaves every command untouched. This PR's own CI is the verification: the cache will miss across all six matrix entries on this run and populate on the first push tomaster.Generated by Claude Code