Cache: pipenv example

Created on 14 Jan 2020  路  4Comments  路  Source: actions/cache

Does this work with pipenv?
And if so, could you add an example to the readme, similar to the pip example?

documentation good first issue help wanted

Most helpful comment

@guilhermearaujo Yes it can, if you're happy updating your lock for every minor release of python. However, you may find if you're using actions/setup-python that your minor version is no longer available after a release on your next run (As we discovered with 3.8.0). I'm fairly sure the list of available versions on https://help.github.com/en/actions/reference/software-installed-on-github-hosted-runners is out of date given 3.7.6 and 3.8.1 are the available versions.

All 4 comments

Far from ideal, but I managed to get it working using two caches:

# This one caches both pip and pipenv downloads
- name: Cache dependencies
  uses: actions/cache@v1
  with:
    path: ~/.cache
    key: ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}

# This will cache the whole virtualenv with built dependencies (and a lot more, though)
- name: Cache virtualenv
  uses: actions/cache@v1
  with:
    path: ~/.local/share/virtualenvs
    key: ${{ runner.os }}-venv-${{ hashFiles('**/Pipfile.lock') }}

I really dislike the virtualenv cache, since it's caching a lots of extra stuff, not only the dependencies. I am not sure what (terrible?) consequences this may cause, but I haven't had any issues with this settings in the past month

@guilhermearaujo It's also worth including the version of python within the key you're using if you aren't pinning this in your action. This way if github updates the minor release, as they have done recently, your cache will be updated too on the next run and not fail (as it did for me).

```yaml
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-virtualenvs-${{ hashFiles('Pipfile.lock') }}

@iwootten the Python version can be specified in the Pipfile, so in case we change it, the Pipfile.lock (and consequently its hash) will also change.

@guilhermearaujo Yes it can, if you're happy updating your lock for every minor release of python. However, you may find if you're using actions/setup-python that your minor version is no longer available after a release on your next run (As we discovered with 3.8.0). I'm fairly sure the list of available versions on https://help.github.com/en/actions/reference/software-installed-on-github-hosted-runners is out of date given 3.7.6 and 3.8.1 are the available versions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KhaledSakr picture KhaledSakr  路  3Comments

dcecile picture dcecile  路  6Comments

wrightak picture wrightak  路  4Comments

aleks-ivanov picture aleks-ivanov  路  5Comments

evandrocoan picture evandrocoan  路  3Comments