GitHub Actions has support for preserving the pip cache across builds, but, due to the fact that the GHA cache is not updated on an exact key match, caching the pip cache only works optimally if one’s repository contains a lock file giving the exact versions of all build & test dependencies in use. It’s my understanding (I could be wrong) that lock files generally shouldn’t be committed to repositories, and generating a lock file as part of a build requires downloading the relevant files from PyPI before cache restoration can even take place, defeating the point of the GHA cache.
The best way I’ve found so far to manage caching of the pip cache is this suggestion, which has one create a separate GHA cache for each run; the most recent cache is then restored at the start of each run and, and at the end of the run, the cache is saved with updates in a new GHA cache. This results in a series of ever-growing (mostly duplicate) caches being created until you hit the 5 GB limit, at which point old caches begin getting deleted. This could be better.
Has anyone figured out a decent setup for caching the pip cache on GitHub Actions?