Skip to content

Rust CI

Rust CI #131

Workflow file for this run

name: Rust CI
on:
push:
branches: [ "**" ] # Triggers on all branches for push events
tags:
- 'v*.*.*' # Triggers on tag pushes matching semantic versioning
pull_request:
branches: [ "**" ] # Triggers on all branches for pull request events
# Optional: Run benchmarks on a schedule (e.g., nightly)
schedule:
- cron: "0 0 * * *" # every day at midnight
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Build
run: cargo build
- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Check Formatting
run: cargo fmt -- --check
- name: Run Tests
run: cargo test
benchmark:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [stable, beta, nightly]
needs: build # Ensure benchmarks run after a successful build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}-bench
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Build Benchmarks
run: cargo build --bench benchmark
- name: Run Benchmarks
run: |
cargo bench
# Optionally, move Criterion reports to a specific directory
mkdir -p benchmark_reports
cp -r target/criterion benchmark_reports-${{ matrix.os }}-${{ matrix.rust }}/
- name: Upload Benchmark Reports
uses: actions/upload-artifact@v4
with:
name: benchmark-reports
path: benchmark_reports-${{ matrix.os }}-${{ matrix.rust }}/
publish:
runs-on: ubuntu-latest
needs: build # Ensure publishing happens after a successful build
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Publish to Crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --token $CARGO_REGISTRY_TOKEN