diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index da63d037..c9ca9c36 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,27 +8,89 @@ on: branches: [ main ] pull_request: branches: [ main ] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: check-style: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - name: Report cargo version run: cargo --version - name: Report rustfmt version run: cargo fmt -- --version - name: Check style - run: cargo fmt -- --check + run: cargo fmt --all -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + - name: Report clippy version + run: cargo clippy --version + - name: Run clippy + run: cargo clippy --locked --workspace --all-targets --all-features -- -D warnings + + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + - name: Build documentation + run: cargo doc --locked --no-deps --all-features --workspace + env: + RUSTDOCFLAGS: -D warnings + # Runs everything, including the trybuild compile-fail test, under the + # toolchain pinned by rust-toolchain.toml. build-and-test: runs-on: ${{ matrix.os }} strategy: matrix: os: [ ubuntu-latest, windows-latest, macos-latest ] steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + - name: Build + run: cargo build --locked --workspace --tests --verbose + - name: Run tests + run: cargo test --locked --workspace --no-fail-fast --verbose + + msrv: + runs-on: ubuntu-latest + env: + # rust-toolchain.toml would otherwise override whatever + # dtolnay/rust-toolchain selects; this variable overrides + # rust-toolchain.toml, so this job really uses the MSRV compiler. + # Without it the job silently builds with the pinned toolchain and + # proves nothing. + RUSTUP_TOOLCHAIN: "1.97" + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable + with: + # Keep "1.97" (here and in RUSTUP_TOOLCHAIN above) in sync with + # rust-version in Cargo.toml. + toolchain: "1.97" + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + key: msrv + - name: Report cargo version + run: cargo --version + - name: Report rustc version + run: rustc --version - name: Build - run: cargo build --locked --tests --verbose + run: cargo build --locked --workspace --tests --verbose - name: Run tests - run: cargo test --locked --verbose + # test_compile_fail (trybuild) runs in build-and-test, on the + # pinned toolchain: it compares against compiler diagnostics, + # which drift between releases. + run: cargo test --locked --workspace --no-fail-fast --verbose -- --skip test_compile_fail diff --git a/Cargo.toml b/Cargo.toml index 4848b80c..ef67bd8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,9 @@ members = [ resolver = "2" +[workspace.package] +rust-version = "1.97" + [workspace.dependencies] typify = { version = "0.10.1", path = "typify" } typify-impl = { version = "0.10.1", path = "typify-impl" } diff --git a/cargo-typify/Cargo.toml b/cargo-typify/Cargo.toml index 7d89c0fc..c20050bf 100644 --- a/cargo-typify/Cargo.toml +++ b/cargo-typify/Cargo.toml @@ -8,6 +8,7 @@ repository = "https://github.com/oxidecomputer/typify" readme = "README.md" keywords = ["json", "schema", "cargo"] categories = ["api-bindings", "compilers"] +rust-version.workspace = true default-run = "cargo-typify" diff --git a/typify-impl/Cargo.toml b/typify-impl/Cargo.toml index bcbded6b..3679c1d0 100644 --- a/typify-impl/Cargo.toml +++ b/typify-impl/Cargo.toml @@ -6,6 +6,7 @@ license = "Apache-2.0" description = "typify backend implementation" repository = "https://github.com/oxidecomputer/typify" readme = "../README.md" +rust-version.workspace = true [dependencies] heck = { workspace = true } diff --git a/typify-macro/Cargo.toml b/typify-macro/Cargo.toml index f52a924d..1461c1f3 100644 --- a/typify-macro/Cargo.toml +++ b/typify-macro/Cargo.toml @@ -6,6 +6,7 @@ license = "Apache-2.0" description = "typify macro implementation" repository = "https://github.com/oxidecomputer/typify" readme = "../README.md" +rust-version.workspace = true [lib] proc-macro = true diff --git a/typify/Cargo.toml b/typify/Cargo.toml index 50283602..0a891d72 100644 --- a/typify/Cargo.toml +++ b/typify/Cargo.toml @@ -8,6 +8,7 @@ repository = "https://github.com/oxidecomputer/typify" readme = "../README.md" keywords = ["json", "schema", "proc_macro"] categories = ["api-bindings", "compilers"] +rust-version.workspace = true [features] default = ["macro"]