continuous-integration - 如何在github操作中使用pip缓存?

标签 continuous-integration github-actions

我在Github Actions中使用缓存的点数时遇到了一些问题。我的工作流程设置是

name: tests

on: [push, pull_request]

jobs:
  linux:

    runs-on: ubuntu-18.04
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.6, 3.7, 3.8]

    steps:
    - uses: actions/checkout@v1
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}
    - uses: actions/cache@v1
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
        restore-keys: |
          ${{ runner.os }}-pip-
    - name: Install
      if: steps.cache.outputs.cache-hit != 'true'
      run: |
        pip install pytest pytest-cov bandit sphinx recommonmark
        python -m pip install --upgrade pip
        pip install .
    - name: Test with pytest
      run: |
        pytest --disable-pytest-warnings --cov-report=xml --cov=chepy --cov-config=.coveragerc tests/
        coverage report -m
    - name: Test with bandit
      run: |
        bandit --recursive chepy/ --ignore-nosec --skip B101,B413,B303,B310,B112,B304,B320,B410,B404
    - name: Test docs
      run: |
        make -C docs/ clean html
    - name: Upload to codecov
      uses: codecov/codecov-action@v1.0.3
      with:
        token: ${{secrets.CODECOV_TOKEN}}
        file: ./coverage.xml

我遇到的问题是,在触发的后续操作中,它将不使用缓存,而是从pip重新安装。

如何使用缓存?

最佳答案

您忘记了在使用id的步骤中添加actions/cache。这是Install步骤中的条件起作用所必需的。

- uses: actions/cache@v1
  id:   cache
  with:
   ...

关于continuous-integration - 如何在github操作中使用pip缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59127258/

相关文章:

github - 当触发器是发布时,GitHub 的上传发布 Assets 操作的 upload_url?

github - 如何访问 Github Actions CI/CD 中的服务?

github - 有没有办法通过 GitHub 操作推送更改?

github - 如何通过gradle任务将jar发布到Internet上的某个地方?

flutter - 如何在 GitHub Actions CI/CD 中构建 Flutter

github-actions - 我应该使用 MarketPlace 操作而不是普通的 bash `cp` 命令来复制文件吗?

selenium - 在 AWS CI/CD 管道中运行 selenium 测试的最佳方法是什么

git - Travis-CI:将不同的分支部署到不同的服务器

entity-framework - 如何设置数据库连接字符串以从 Visual Studio Online 进行持续部署

jenkins - 如何读取 Jenkins Web Hook post 请求正文?