I tried to use this actions/cache@v2
to cache poetry venv. There are only two libraries pylint
and pytest
installed. It seems that installation was cached (cache size ~ 26MB). However, they couldn't be retrieved after cache hit.
The cache installed libraries are not found while run
poetry run pip list
Package Version
---------- -------
pip 20.1.1
setuptools 41.2.0
https://github.com/northtree/poetry-github-actions/runs/875926237?check_suite_focus=true#step:9:1
The YAML is here.
Could I know how to use actions/cache@v2
to cache poetry installation / virturalenv to avoid reinstalling dependencies.
The cache key uses contexts and expressions to generate a key that includes the runner's operating system and a SHA-256 hash of the package-lock. json file. When key matches an existing cache, it's called a cache hit, and the action restores the cached files to the path directory.
Get GitHub Actions cache usage for an organization Gets the total GitHub Actions cache usage for an organization. The data fetched using this API is refreshed approximately every 5 minutes, so values returned from this endpoint may take at least 5 minutes to get updated.
@northtree's answer is correct, but for anyone browsing, you should know that hte referenced action is no longer maintained.
For Poetry installs using versions >= 1.1.0 I'd recommend using this snippet to cache your Poetry dependencies:
...
- name: Install poetry
uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
...
More complete examples are documented here :)
In your YAML file you are using dschep/[email protected]
to install Poetry, which sets poetry config virtualenvs.create false
, which means that the current python interpreter/virtualenv is used. Because you're not activating a virtualenv anywhere poetry is just using the system python and there isn't a virtualenv inside the ~/.poetry
directory.
It should work if you set poetry config virtualenvs.create true
, e.g.:
- name: Install poetry
uses: dschep/[email protected]
- name: Configure poetry
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project false
poetry config cache-dir ~/.poetry
poetry config virtualenvs.path ~/.poetry/venv
NOTE: According to the docs for dschep/install-poetry-action
there is an option to set poetry config virtualenvs.create true
during install but it seems to be broken at the moment (see https://github.com/dschep/install-poetry-action/issues/11). In any case I personally prefer doing it in the same config block as everything else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With