Notes on using pip cache with GitHub Actions
The directory for each OS is as follows (I haven't tried it, but in the case of Ubuntu, it can be cached to any path by specifying the environment variable "XDG_CACHE_HOME".)
# Unix
~/.cache/pip
# macOS
~/Library/Caches/pip
# Windows
<CSIDL_LOCAL_APPDATA>\pip\Cache
Create cache (assuming ubuntu is used)
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
Restore from cache
- name: Get pip cache
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- uses: actions/cache@v1
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
By the way, other languages also have samples written so that the formulas are easy to understand, so it is very easy to introduce.
If you don't want to use pip cache even if the package is written in requirements.txt, you need to install it with "--no-cache-dir" separately.
$ pip --no-cache-dir install [package name]
Skipping steps based on cache-hit
The presence or absence of a cache hit is held by a bool value called cache-hit. If there is no hit, you can easily implement the flow of deploying or continuing the subsequent processing.
■ pip install ■ [Cache Dependencies to Speed Up Workflow](https://help.github.com/ja/actions/automating-your-workflow-with-github-actions/caching-dependencies-to-speed-up -workflows) ■ I'm happy to be able to use the cache on GitHub Actions!
Recommended Posts