continuous-integration - 如何为 GitHub Actions 缓存诗歌安装

标签 continuous-integration github-actions python-poetry

我尝试使用这个 actions/cache@v2 来缓存诗歌 venv。只安装了两个库 pylintpytest。安装似乎已被缓存(缓存大小 ~ 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:1
YAML 是 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/

相关文章:

git - 持续集成工作流思想

continuous-integration - 此作业卡住了,因为该项目没有在线分配任何运行者。进入运行者页面

github - (GitHub Actions) 将步骤分成两个连续的步骤

python - 包发布 (Python) 通过 Poetry 失败

unit-testing - 使用 Visual Studio Team Services VSTS 在 Visual Studio 测试中包含或排除测试程序集的正确语法是什么

android - 命令行中的模拟器并不总是具有属性 "dev.bootcomplete"

node.js - 运行单元测试管道时 Github 操作错误

python - 为什么使用 cron 安排的 Github Actions 工作流没有在正确的时间触发?

python - Windows WSL 的 Poetry 安装不起作用,忽略 $HOME

python - 如何在 IPython shell 中获取或激活虚拟环境?