rust - GitHub Actions 缓存 Rust 工件

标签 rust github-actions

使用 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/

相关文章:

rust - 借用的值(value)活得不够长,需要静态生命周期

file - 如何从文件中获取随机行?

github-actions - Github Actions Rails Postgres 数据库 "test"不存在

winapi - 如何在windows-rs中获取IAudioSessionControl2?

rust - 如何按插入顺序对 map 进行排序?

rust - 如何使用new_type!宏来为氧化钠PublicKey和SecretKey设置更通用的类型?

ubuntu - 是否可以从 Github Actions 使用 dput 和 debuild ?

github - 有没有办法记录来自 Github Actions 的错误响应?

python - 如何从 Github 工作流程访问环境 secret ?

github - 发布 GitHub 页面时触发 GitHub 操作