我正在尝试缓存项目的python依赖项。为此,我的工作流中有以下配置:
- 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
这是有效的,我的意思是它加载缓存并跳过安装依赖项步骤,并恢复~/. ache/pip
目录。问题是当我尝试运行测试时,会出现以下错误:
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.
我缓存不正确的目录?或者我做错了什么?
注:此项目使用python2。Ubuntu 16.04上的7
如本文所述,您可以缓存整个虚拟环境:
- uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('dev-requirements.txt') }}