Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache is not being correctly loaded in Github actions

I'm trying to cache the python dependencies of my project. To do that, I have this configuration in my workflow:

      - uses: actions/cache@v2
        id: cache
        with:
          path: ~/.cache/pip
          key: pip-${{ runner.os }}-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('**/requirements_dev.txt') }}
          restore-keys: pip-${{ runner.os }}

      - name: Install apt dependencies
        run: |
          sudo apt-get update
          sudo apt-get install gdal-bin

      - name: Install dependencies
        if: steps.cache.outputs.cache-hit != 'true'
        run: |
          pip install --upgrade pip==9.0.1
          pip install -r requirements.txt
          pip install -r requirements_dev.txt

This works, by 'works' I mean that it loads the cache and skip the 'Install dependencies step' and it restores the ~/.cache/pip directory. The problem is that when I try to run the tests, the following error appears:

  File "manage.py", line 7, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Error: Process completed with exit code 1.

Am I caching the incorrect directory? Or what am I doing wrong?

Note: this project is using python2.7 on Ubuntu 16.04

like image 888
Antonio Gamiz Delgado Avatar asked Feb 13 '26 02:02

Antonio Gamiz Delgado


1 Answers

As it explains here, you can cache the whole virtual environment:

- uses: actions/cache@v2
  with:
    path: ${{ env.pythonLocation }}
    key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('dev-requirements.txt') }}

like image 171
Antonio Gamiz Delgado Avatar answered Feb 15 '26 16:02

Antonio Gamiz Delgado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!