如何缓存依赖项安装?

时间:2020-05-15 11:50:24

标签: github-actions

我目前正在尝试实施一个需要安装protobuf的工作流程。但是,在Ubuntu上,我必须自己编译。问题在于,这需要花费很多时间,因此我认为必须执行此步骤。

但是,我不确定如何使用actions/cache

以下是我如何安装protobuf和我的Python依赖项:

name: Service

on:
  push:
    branches: [develop, master]

jobs:
  test:
    runs-on: ubuntu-18.04
    steps:
      - name: Install protobuf-3.6.1
        run: |
          wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.tar.gz
          tar -xvf protobuf-all-3.6.1.tar.gz
          cd protobuf-3.6.1
          ./configure
          make
          make check
          sudo make install
          sudo ldconfig
      - uses: actions/checkout@v2
      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip setuptools
          pip install -r requirements.txt

我如何才能缓存这些run步骤他们不必每次都跑步吗?

1 个答案:

答案 0 :(得分:0)

我测试了以下内容:

name: Service
on:
  push:
    branches: [develop, master]

jobs:
  test:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
      - name: Load from cache
        id: protobuf
        uses: actions/cache@v1
        with:
          path: protobuf-3.6.1
          key: protobuf3
      - name: Compile protobuf-3.6.1
        if: steps.protobuf.outputs.cache-hit != 'true'
        run: |
          wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.tar.gz
          tar -xvf protobuf-all-3.6.1.tar.gz
          cd protobuf-3.6.1
          ./configure
          make
          make check
      - name: Install protobuf
        run: |
          cd protobuf-3.6.1
          sudo make install
          sudo ldconfig
      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip setuptools
          pip install -r requirements.txt

构建后,我还将删除所有源文件。