首页 > 解决方案 > 如何为 GitHub Actions 缓存诗歌安装

问题描述

我试图用它actions/cache@v2来缓存诗歌 venv。只有两个库pylintpytest已安装。似乎安装已缓存(缓存大小 ~ 26MB)。但是,缓存命中后无法检索它们。

运行时找不到缓存安装的库

诗歌运行点子列表

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 在这里

我可以知道如何使用actions/cache@v2缓存诗歌安装/virturalenv 以避免重新安装依赖项。

标签: continuous-integrationgithub-actionspython-poetry

解决方案


@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'
...

此处记录了更完整的示例:)


推荐阅读