GitHub Actions: Faster Python runs with cached virtual environments (via) Adam Johnson shares his improved pattern for caching Python environments in GitHub Actions.
I've been using the pattern where you add cache: pip
to the actions/setup-python
block, but it has two disadvantages: if the tests fail the cache won't be saved at the end, and it still spends time installing the packages despite not needing to download them fresh since the wheels are in the cache.
Adam's pattern works differently: he caches the entire .venv/
folder between runs, avoiding the overhead of installing all of those packages. He also wraps the block that installs the packages between explicit actions/cache/restore
and actions/cache/save
steps to avoid the case where failed tests skip the cache persistence.
Recent articles
- Video scraping: extracting JSON data from a 35 second screen capture for less than 1/10th of a cent - 17th October 2024
- ChatGPT will happily write you a thinly disguised horoscope - 15th October 2024
- OpenAI DevDay: Let’s build developer tools, not digital God - 2nd October 2024