【问题标题】:How to cache a dependency insallation?如何缓存依赖项安装?
【发布时间】:2020-09-01 05:40:19
【问题描述】:

我目前正在尝试实现一个需要安装 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 步骤 s.t.他们不必每次都运行?

【问题讨论】:

  • 下载这个缓存的依赖项,解压缩并安装它,与下载源代码并构建它相比,您获得了多少速度?您可能需要考虑使用 docker 映像。看到这个answer

标签: github-actions


【解决方案1】:

我测试了以下内容:

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

一旦构建完成,我也会删除所有源文件。

【讨论】:

    猜你喜欢
    • 2017-12-17
    • 2019-01-04
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 2021-10-15
    • 2018-09-11
    • 2022-01-07
    • 1970-01-01
    相关资源
    最近更新 更多