You're only caching source tarballs and binary wheels downloaded by pip
. You're not caching:
- Installed Python packages (i.e., the
site-packages/
subdirectory of the active Python interpreter).
- Installed entry points (i.e., executable commands residing in the current
${PATH}
).
That isn't necessarily a bad thing. Merely downloading assets tends to consume a disproportionate share of scarce GitHub Actions (GA) minutes; caching assets trivially alleviates that issue.
In other words, remove the if: steps.pip-cache.outputs.cache-hit != 'true'
line to restore your GitHub Actions (GA) workflow to sanity.
But... I Want to Cache Installed Packages!
Challenge accepted. This is feasible – albeit more fragile. I'd advise just caching pip
downloads unless you've profiled the pip install
command to be a significant installation bottleneck.
Let's assume that you still want to do this. In this case, something resembling the following snippet should get you where you want to go:
- uses: 'actions/setup-python@v2'
with:
# CAUTION: Replace this hardcoded "3.7" string with the
# major and minor version of your desired Python interpreter.
python-version: "3.7"
- uses: 'actions/cache@v2'
id: cache
with:
# CAUTION: Replace this hardcoded "python3.7" dirname with
# the dirname providing your desired Python interpreter.
path: ${{ env.pythonLocation }}/lib/python3.7/site-packages/*
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
As noted, you'll want to manually replace the hardcoded 3.7
and python3.7
substrings above with something specific to your use case. That's one of several reasons why this is dangerously fragile. Another is that the ${{ env.pythonLocation }}
environment variable set by the setup-python
GitHub Action has been infamously undocumented for several years. </gulp>
(env.pythonLocation
documentation was added from v4.0.0.)
In theory, adding the above directly under your existing uses: actions/cache@v2
list item should suffice. Good luck and Godspeed as you travel into the terrifying unknown.