Skip to content

Optimize GitHub Actions workflows #440

Optimize GitHub Actions workflows

Optimize GitHub Actions workflows #440

Workflow file for this run

on: [push, pull_request]
name: CI tests
jobs:
build:
name: Build project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
id: setup_rust
with:
components: "rustfmt, clippy"
- name: set RUSTC_CACHE_KEY
run: echo "RUSTC_CACHEKEY=${{ steps.setup_rust.outputs.cachekey }} >> $GITHUB_ENV"
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: "cargo-base-${{ env.RUSTC_CACHEKEY }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-base-${{ env.RUSTC_CACHEKEY }}
- run: cargo build
lint:
name: Run lints
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
id: setup_rust
with:
components: "rustfmt, clippy"
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: "cargo-lint-${{ env.RUSTC_CACHEKEY }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-lint-${{ env.RUSTC_CACHEKEY }}
cargo-base-${{ env.RUSTC_CACHEKEY }}
fail-on-cache-miss: true
- run: cargo fmt --all -- --check
- run: cargo check
- run: cargo clippy -- -D warnings
test-linux:
name: Test on Linux
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
id: setup_rust
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: "cargo-test-${{ env.RUSTC_CACHEKEY }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-test-${{ env.RUSTC_CACHEKEY }}
cargo-base-${{ env.RUSTC_CACHEKEY }}
fail-on-cache-miss: true
- run: cargo test
test-windows:
name: Test on Windows
runs-on: windows-latest
needs: build
steps:
- run: git config --system core.autocrlf false && git config --system core.eol lf
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
id: setup_rust
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: "cargo-windows-${{ env.RUSTC_CACHEKEY }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-windows-${{ env.RUSTC_CACHEKEY }}
cargo-base-${{ env.RUSTC_CACHEKEY }}
fail-on-cache-miss: true
- run: cargo test
coverage:
name: Code coverage
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
id: setup_rust
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: "cargo-coverage-${{ env.RUSTC_CACHEKEY }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-coverage-${{ env.RUSTC_CACHEKEY }}
cargo-base-${{ env.RUSTC_CACHEKEY }}
fail-on-cache-miss: true
- uses: actions-rs/[email protected]
with:
# Constrained by https://github.com/actions-rs/tarpaulin/pull/23
version: "0.22.0"
args: "--ignore-tests"
out-type: "Html"
- uses: actions/upload-artifact@v3
with:
name: tarpaulin-report
path: tarpaulin-report.html