name: rust
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
schedule:
- cron: '37 6 * * *'
workflow_dispatch:
inputs:
crates_repo:
description: "crates.io repo to publish to"
default: prod
required: true
options:
- prod
env:
CARGO_TERM_COLOR: always
CARGO_TERM_VERBOSE: true
RUST_BACKTRACE: full
crates_environment: &crates_environment ${{ case(inputs.crates_repo == 'prod', 'crates.io', startsWith(github.ref, 'refs/tags/'), 'crates.io', 'staging.crates.io') }}
is_tag_push: ${{ startsWith(github.ref, 'refs/tags/') }}
is_dispatch: ${{ github.event_name == 'workflow_dispatch' }}
prev_rust: &prev_rust 1.94.1
latest_rust: &latest_rust 1.95.0
defaults:
run:
shell: bash
jobs:
build_test:
strategy:
fail-fast: false
matrix:
is_pr_or_push:
- ${{github.event_name == 'pull_request' || github.event_name == 'push'}}
target:
- triple: x86_64-unknown-linux-gnu
runner: linux-x86_64-16cpu
- triple: aarch64-unknown-linux-gnu
runner: linux-arm64-16cpu
- triple: aarch64-apple-darwin
runner: macos-26
- triple: x86_64-pc-windows-gnu
runner: windows-8vcpu
- triple: x86_64-pc-windows-msvc
runner: windows-8vcpu
toolchain:
- version: *prev_rust
label: prev
- version: *latest_rust
label: latest
exclude:
- is_pr_or_push: true
target:
triple: aarch64-apple-darwin
name: test (rust ${{ matrix.toolchain.label }}, ${{ matrix.target.triple }})
runs-on: ${{ matrix.target.runner }}
env:
COMMON_FLAGS: --all-features --workspace
CARGO_BUILD_TARGET: ${{ matrix.target.triple }}
is_windows_gnu: ${{ endsWith(matrix.target.triple, '-windows-gnu') }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd - name: Setup rust
id: setup-rust
uses: ./.github/actions/setup-rust
with:
toolchain-version: ${{ matrix.toolchain.version }}
builder-triple: ${{ matrix.target.triple }}
components: clippy
- name: Lint lib targets (cargo clippy)
run: |-
cargo clippy \
$COMMON_FLAGS \
--no-deps \
--lib \
-- -D warnings
- name: Lint other targets (cargo clippy)
run: |-
cargo clippy \
$COMMON_FLAGS \
--no-deps \
--bins --tests --benches --examples \
-- -D warnings -A missing_docs
- name: Build (cargo build)
run: cargo build $COMMON_FLAGS --all-targets
- name: Test (cargo test), --all-features
run: |-
cargo test \
$COMMON_FLAGS \
${{ case(env.is_windows_gnu == 'true', '--exclude ts_python', '') }}
- name: Release build (cargo build --release)
if: ${{ runner.os != 'Windows' || github.event_name != 'pull_request' }}
run: cargo build $COMMON_FLAGS --release --all-targets
- name: Docs (cargo doc)
run: cargo doc $COMMON_FLAGS --no-deps
arch_independent:
name: arch-independent checks
runs-on: linux-x86_64-16cpu
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd - name: Setup rust
id: setup-rust
uses: ./.github/actions/setup-rust
with:
toolchain-version: nightly
builder-triple: x86_64-unknown-linux-gnu
components: rustfmt
- &binstall
name: binstall
uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 - name: Install cargo-deny
run: command -v cargo-deny || cargo binstall --no-confirm cargo-deny
- &cargo_ws
name: Install cargo-workspaces
run: command -v cargo-workspaces || cargo binstall --no-confirm cargo-workspaces
- name: Check for unused dependencies (cargo machete)
uses: bnjbvr/cargo-machete@main
with:
args: "--with-metadata"
- name: Dependency audit (cargo deny)
run: cargo deny --workspace --all-features check all
- name: Check formatting (cargo fmt)
run: cargo fmt --check
- name: Custom workspace checks
run: cargo run -p checks
- &dry_publish
name: Publish (Dry run)
run: cargo ws publish --dry-run --publish-as-is
publish:
name: publish
runs-on: linux-x86_64-16cpu
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
needs:
- build_test
- arch_independent
environment: *crates_environment
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- uses: rust-lang/crates-io-auth-action@bbd81622f20ce9e2dd9622e3218b975523e45bbe id: auth
with:
url: ${{ case(inputs.crates_repo == 'prod', 'https://crates.io', startsWith(github.ref, 'refs/tags/'), 'https://crates.io', 'https://staging.crates.io') }}
- name: Setup rust
id: setup-rust
uses: ./.github/actions/setup-rust
with:
toolchain-version: *latest_rust
builder-triple: x86_64-unknown-linux-gnu
- *binstall
- *cargo_ws
- name: Configure staging registry
if: inputs.crates_repo == 'staging'
run: |-
echo CARGO_REGISTRIES_STAGING_INDEX=https://staging.crates.io/index >> $GITHUB_ENV
echo CARGO_REGISTRY_DEFAULT=staging >> $GITHUB_ENV
- *dry_publish
- name: Publish
run: cargo ws publish --publish-as-is
env:
TS_FFI_BUILDRS_STRICT: 1
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}