Skip to content

Commit

Permalink
Build once and reuse the target directory
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed Dec 17, 2024
1 parent 935fd9f commit 63e863e
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,37 @@ env:
CARGO_TERM_COLOR: always

jobs:
build_and_test:
build:
name: Rust build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies installed with cargo
uses: actions/cache@v4
with:
path: |
./target/deps
~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Build binary
run: |
# the binary will be used by the cargo test
cargo build --all-targets --all-features
cargo test --no-run --all-targets --all-features
- name: Compress before uploading artifact to preserve permissions # https://github.com/actions/upload-artifact/tree/v4.4.3#permission-loss
run: tar -cvzf target.tgz target/
- uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: target
path: target.tgz
retention-days: 1
test:
name: Rust tests
runs-on: ubuntu-latest
needs: build
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -68,9 +96,11 @@ jobs:
~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Build binary
# the binary will be used by the next cargo test step
run: cargo build
- uses: actions/download-artifact@v4
with:
name: target
path: artifact
- run: tar -xvzf artifact/target.tgz && rm artifact/target.tgz
- name: Run cargo tests
env:
AMBER_TEST_STRATEGY: docker
Expand Down

0 comments on commit 63e863e

Please sign in to comment.