簡體   English   中英

如何為 GitHub 操作緩存詩歌安裝

[英]How to cache poetry install for GitHub Actions

我嘗試使用這個actions/cache@v2來緩存詩歌 venv。 只安裝了pylintpytest這兩個庫。 似乎安裝已緩存(緩存大小 ~ 26MB)。 但是,緩存命中后無法檢索它們。

運行時找不到緩存安裝的庫

詩歌運行 pip 列表

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 以避免重新安裝依賴項。

緩存原生集成到actions/setup-python ( https://github.com/actions/setup-python#caching-packages-dependencies ):

steps:
- uses: actions/checkout@v3
- name: Install poetry
  run: pipx install poetry
- uses: actions/setup-python@v3
  with:
    python-version: '3.9'
    cache: 'poetry'
- run: poetry install
- run: poetry run pytest

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

此處記錄了更完整的示例:)

在您的 YAML 文件中,您使用dschep/install-poetry-action@v1.3安裝 Poetry,它設置了poetry config virtualenvs.create false ,這意味着使用當前的 python 解釋器/virtualenv。 因為您沒有在任何地方激活虛擬環境,詩歌只是使用系統 python 並且~/.poetry目錄中沒有虛擬環境。

如果您設置poetry config virtualenvs.create true ,它應該可以工作,例如:

    - name: Install poetry
      uses: dschep/install-poetry-action@v1.3

    - name: Configure poetry
      run: |
        poetry config virtualenvs.create true
        poetry config virtualenvs.in-project false
        poetry config cache-dir ~/.poetry
        poetry config virtualenvs.path ~/.poetry/venv

注意:根據dschep/install-poetry-action的文檔,有一個選項可以在安裝期間設置poetry config virtualenvs.create true ,但目前似乎已損壞(請參閱https://github.com/dschep/install -詩歌行動/問題/11 )。 無論如何,我個人更喜歡在與其他所有內容相同的配置塊中執行此操作。

您無需使用外部操作來安裝 Poetry,或設置虛擬環境。 poetry將模塊安裝到~/.cache/pypoetry ,所以:

    - name: Load cached venv
      id: cached-poetry-dependencies
      uses: actions/cache@v2
      with:
        path: |
          ~/.cache/pypoetry
          .venv
        key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

    - name: Install poetry no matter what
      run: |
        pip install poetry

    - name: Install requirements
      if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
      run: |
        poetry install

理論上應該可以緩存poetry的安裝,它安裝到~/poetry 不過,我找不到路。

然而,當你讀到這篇文章的時候,這個 PR 可能已經登陸了,所以你需要緩存 Poetry deps 就是actions/setup-python

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM