name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
no-dependencies:
name: No Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Reject normal and build dependencies
shell: bash
run: |
metadata=$(cargo metadata --format-version 1 --no-deps)
shipped=$(echo "$metadata" | jq -r '
.packages[] | select(.name == "uncore") | .dependencies[]
| select(.kind != "dev") | "\(.kind // "normal"): \(.name)"')
dev=$(echo "$metadata" | jq -r '
.packages[] | select(.name == "uncore") | .dependencies[]
| select(.kind == "dev") | .name')
if [ -n "$dev" ]; then
echo "Dev-dependencies (not shipped to consumers, allowed):"
echo "$dev" | sed 's/^/ /'
fi
if [ -n "$shipped" ]; then
echo "$shipped" | sed 's/^/ /'
echo "::error::uncore must have no normal or build dependencies — it is linked statically into three published cdylibs, so a dependency here is a dependency in all of them. See the crate docs' Scope section."
exit 1
fi
echo "No normal or build dependencies."
version-sync:
name: Version Consistency
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Verify Cargo.toml and html_root_url agree
shell: bash
run: |
manifest=$(grep -m1 '^version = ' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
doc_url=$(grep -m1 'html_root_url' src/lib.rs | sed 's|.*/uncore/\([^"]*\)".*|\1|')
echo "Cargo.toml: $manifest"
echo "lib.rs html_root_url: $doc_url"
if [ "$manifest" != "$doc_url" ]; then
echo "::error::Version mismatch — bump Cargo.toml and src/lib.rs's html_root_url together, or docs.rs will resolve intra-doc links against the wrong version."
exit 1
fi
echo "Versions match: $manifest"
test:
name: Test
needs: [no-dependencies, version-sync]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Run tests
run: cargo test
msrv:
name: MSRV
needs: [no-dependencies, version-sync]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Read rust-version from the manifest
id: msrv
shell: bash
run: |
version=$(grep -m1 '^rust-version = ' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
echo "toolchain=$version" >> "$GITHUB_OUTPUT"
echo "Declared MSRV: $version"
- name: Install the declared toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.msrv.outputs.toolchain }}
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-msrv-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-msrv-
- name: Run tests on the declared MSRV
run: cargo test
wasm:
name: Build for wasm32
needs: [no-dependencies, version-sync]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-wasm-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-wasm-
- name: Build
run: cargo build --target wasm32-unknown-unknown
lint:
name: Lint
needs: [no-dependencies, version-sync]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Check formatting
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
docs:
name: Docs
needs: [no-dependencies, version-sync]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Build documentation
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --no-deps
package:
name: Package
needs: [test, lint, docs]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Verify the crate packages cleanly
run: cargo publish --dry-run
- name: Show what would ship
run: cargo package --list