name: Tests
on:
push:
branches:
- main
tags:
- "**"
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: {}
defaults:
run:
shell: bash -euxo pipefail {0}
jobs:
build:
name: Build
uses: ./.github/workflows/build.yml
permissions:
contents: read
with:
stable: false
profile: dev
cache: ${{ (github.event_name == 'push' && github.ref_type == 'branch') || github.event_name == 'pull_request' }}
tests:
name: Tests
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with:
persist-credentials: false
- name: Determine Rust stable channel metadata
id: rust-stable-metadata
run: |
rust_stable_manifest="$(curl -fsSL https://static.rust-lang.org/dist/channel-rust-stable.toml)"
rust_stable_date="$(sed -En 's/^date = "(.+)"$/\1/p' <<< "$rust_stable_manifest")"
echo "rust_stable_date=$rust_stable_date" >> "$GITHUB_OUTPUT"
- name: Set up Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs |
sh -s -- -y --no-modify-path \
--default-toolchain stable
- name: Cache Cargo registry
if: (github.event_name == 'push' && github.ref_type == 'branch') || github.event_name == 'pull_request'
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: tests-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
tests-cargo-
- name: Cache build artifacts
id: cache-target
if: (github.event_name == 'push' && github.ref_type == 'branch') || github.event_name == 'pull_request'
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae with:
path: |
target
key: tests-target-${{ steps.rust-stable-metadata.outputs.rust_stable_date }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
tests-target-${{ steps.rust-stable-metadata.outputs.rust_stable_date }}-
- name: Run format check
run: cargo fmt --all --check
- name: Run build
run: cargo build --locked --all-targets --all-features
- name: Run Clippy
run: cargo clippy --locked --all-targets --all-features -- -D warnings
- name: Run tests
run: cargo test --locked --all-targets --all-features
- name: Build and check docs
run: RUSTDOCFLAGS="-D warnings" cargo doc --locked --all-features --no-deps
- name: Prune build artifacts for caching
if: >
github.event_name == 'push' && github.ref == 'refs/heads/main' &&
steps.cache-target.outputs.cache-hit != 'true'
run: cargo clean --locked --workspace