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
步骤,因为它们不必每次都运行?
解决方案
我测试了以下内容:
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
构建完成后,我还将删除所有源文件。
推荐阅读
- google-sheets - 如何让 Google 表格忽略某些单元格中的数据?
- 3d - 旋转时子实体扭曲 - AFrame
- python - selenium.common.exceptions.TimeoutException:当我尝试使用 python 单击按钮时会出现此错误
- sql - 从两个 XML 列中选择并匹配值
- javascript - 下载联系表格 7 上的 pdf 在新标签中提交
- matlab - 为什么内核的大小应该是奇数?
- c# - 将数据集转换为通用列表
- elasticsearch - 如何扩展有状态集的 PVC?
- google-apps-script - 连接到 Google 表格的 Slack Webhooks 获取下一行
- python - 在 Pandas 中每小时按项目分组并计数项目