我尝试使用这个 actions/cache@v2
来缓存诗歌 venv。只安装了两个库 pylint
和 pytest
。安装似乎已被缓存(缓存大小 ~ 26MB)。但是,在缓存命中后无法检索它们。
运行时找不到缓存安装的库
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:1YAML 是 here 。
我可以知道如何使用
actions/cache@v2
来缓存诗歌安装/virturalenv 以避免重新安装依赖项。
最佳答案
@northtree 的回答是正确的,但是对于任何浏览的人,您应该知道 hte 引用的操作已不再维护。
对于使用版本 >= 1.1.0 的 Poetry 安装,我建议使用此代码段来缓存您的 Poetry 依赖项:
...
- name: Install poetry
uses: snok/install-poetry@v1.0.0
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'
...
记录了更完整的示例 here :)
关于continuous-integration - 如何为 GitHub Actions 缓存诗歌安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62977821/