使用 GitHub Actions,在使用 Rust 的 cargo
构建时,我无法看到使用从以前的构建生成的缓存工件的显着改进。 .
我怀疑我忘记了以下代码中的某些内容,这可能是什么问题?
编辑:这里是 logs如果你想看看他们!
name: Rust
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Cargo Cache
uses: actions/cache@v1
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
${{ runner.os }}-cargo
- name: Cargo Target Cache
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.toml') }}
${{ runner.os }}-cargo-target
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose --all --features "strict"
- name: Run tests
run: cargo test --verbose --all --features "strict"
最佳答案
您可以一步缓存 target 和 .cargo 文件夹。这是我用于构建和测试后端 Web API 的设置示例。
name: Continuous Integration
on: [push, pull_request]
jobs:
build_and_test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:10.12-alpine
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: pongstars
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v2
- name: ⚡ Cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: 🔨 Build
uses: actions-rs/cargo@v1
with:
command: build
- name: Create env file
run: mv .env.example .env
- name: 🔎 Test
uses: actions-rs/cargo@v1
with:
command: test
- name: ⚙ Integration test
uses: actions-rs/cargo@v1
with:
command: test
args: --features "integration_tests"
关于rust - GitHub Actions 缓存 Rust 工件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64634535/