Skip to content

ci: cache .mypy_cache in the test matrix - #86

Merged
zoola969 merged 1 commit into
masterfrom
claude/mypy-cache
Aug 22, 2026
Merged

ci: cache .mypy_cache in the test matrix#86
zoola969 merged 1 commit into
masterfrom
claude/mypy-cache

Conversation

@zoola969

Copy link
Copy Markdown
Owner

Why

An Actions usage audit across all ten repos in the account (2026-08-01..21) found that finances is 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/cache step for .mypy_cache before the mypy step.

The cache key is the one part worth reviewing:

key: mypy-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('uv.lock', 'pyproject.toml') }}-${{ github.sha }}

matrix.python-version is 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.lock pins the mypy version and pyproject.toml holds its config, so either changing invalidates the cache rather than silently reusing results computed under different rules; github.sha keeps each run's key unique (Actions cache entries are immutable, so an existing key is never rewritten) while restore-keys falls back to the newest entry for the same version+lock+config.

The cache works here because tests.yml already runs on push to master — 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 to master.


Generated by Claude Code

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
@zoola969
zoola969 merged commit 5b12308 into master Aug 22, 2026
14 checks passed
@zoola969
zoola969 deleted the claude/mypy-cache branch August 22, 2026 03:56
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