Say I have a GitHub actions workflow with 2 steps.
My
The cache
action can only cache the contents of a folder. So if there is such a folder, you may win some time by caching it.
For instance, if you use some imaginary package-installer
(like Python's pip
or virtualenv
, or NodeJS' npm
, or anything else that puts its files into a folder), you can win some time by doing it like this:
- uses: actions/cache@v2
id: cache-packages # give it a name for checking the cache hit-or-not
with:
path: ./packages/ # what we cache: the folder
key: ${{ runner.os }}-packages-${{ hashFiles('**/packages*.txt') }}
restore-keys: |
${{ runner.os }}-packages-
- run: package-installer packages.txt
if: steps.cache-packages.outputs.cache-hit != 'true'
So what's important here:
cache-packages
if
, steps.cache-packages.outputs.cache-hit != 'true'
./packages/
packages.txt
file changes, the cache will be rebuilt.For users of virtualenv
: if you need to activate some shell environment, you have to do it in every step. Like this:
- run: . ./environment/activate && command