name: Rust CI
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
workflow_dispatch:
inputs:
run_release_build:
description: "Run release build job"
required: false
type: boolean
default: false
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Test on ${{ matrix.os }} (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- os: macos
arch: aarch64
runner: macos-14
target: aarch64-apple-darwin
- os: linux
arch: x86_64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: linux
arch: aarch64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-${{ matrix.arch }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-${{ matrix.arch }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-${{ matrix.arch }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt -- --check
- name: Run clippy
run: cargo clippy --target ${{ matrix.target }} -- -D warnings
- name: Build
run: cargo build --target ${{ matrix.target }} --verbose
- name: Run tests
run: cargo test --target ${{ matrix.target }} --verbose
- name: Run doc tests
run: cargo test --target ${{ matrix.target }} --doc --verbose
build-release:
name: Build release on ${{ matrix.os }} (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}
needs: test
if: github.event_name == 'workflow_dispatch' && github.event.inputs.run_release_build == 'true'
strategy:
matrix:
include:
- os: macos
arch: aarch64
runner: macos-14
target: aarch64-apple-darwin
- os: linux
arch: x86_64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: linux
arch: aarch64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build release
run: cargo build --target ${{ matrix.target }} --release --verbose
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.os }}-${{ matrix.arch }}
path: target/${{ matrix.target }}/release/*
if-no-files-found: warn