我有一个使用 Cargo 包的 GitHub CI。但每次运行 CI 时,大约需要花费时间。 6 分钟即可构建软件包。有没有办法缓存二进制文件,以便下次运行时不必再次构建它?
这就是我的 CI 的样子。
name: "Verify the specs of concrete tests using bulloak"
on: "workflow_call"
jobs:
bulloak-check:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v4"
- name: "Install Rust"
uses: "actions-rs/toolchain@v1"
with:
toolchain: "stable"
- name: "Install bulloak or use the cached version"
run: "cargo install bulloak"
- name: "Verify the concrete tests"
run: "bulloak check test/integration/concrete/**/**.tree --skip-modifiers"
- name: "Bulloak summary"
run: |
echo "## Bulloak result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
您可以按以下方式缓存 Cargo 包(我已使用您的示例并将其修改为使用缓存):
name: "Verify the specs of concrete tests using bulloak"
on: "workflow_call"
jobs:
bulloak-check:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v4"
- name: "Install Rust"
uses: "actions-rs/toolchain@v1"
with:
toolchain: "stable"
- name: "Cache cargo"
id: cache-cargo
uses: "actions/cache@v4"
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
save-always: true
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: "Install bulloak or use the cached version"
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: "cargo install bulloak"
- name: "Verify the concrete tests"
run: "bulloak check test/integration/concrete/**/**.tree --skip-modifiers"
- name: "Bulloak summary"
run: |
echo "## Bulloak result" >> $GITHUB_STEP_SUMMARY
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY