|
| 1 | +name: Rust Quality |
| 2 | + |
| 3 | +# Build, lint, and test the Rust bindings crate at rust-bindings/. |
| 4 | +# |
| 5 | +# The existing Python-side code_quality workflow covers Python tests and |
| 6 | +# transitively builds the Rust extension via `maturin develop`, but does |
| 7 | +# not run `cargo test` (which covers doctests and any pure-Rust unit |
| 8 | +# tests added to the bindings crate). |
| 9 | +# |
| 10 | +# The bindings' `openjd-*` dependencies come from crates.io at the |
| 11 | +# versions pinned in `rust-bindings/Cargo.toml`. There is no sibling |
| 12 | +# repository requirement — local-development overrides are documented |
| 13 | +# in a commented-out `[patch.crates-io]` block at the bottom of that |
| 14 | +# file. |
| 15 | + |
| 16 | +on: |
| 17 | + pull_request: |
| 18 | + branches: [ mainline, release, 'patch_*' ] |
| 19 | + workflow_call: |
| 20 | + inputs: |
| 21 | + branch: |
| 22 | + required: false |
| 23 | + type: string |
| 24 | + tag: |
| 25 | + required: false |
| 26 | + type: string |
| 27 | + |
| 28 | +# Cancel in-progress runs on PR pushes to save CI minutes and avoid |
| 29 | +# cache-save races (two concurrent runs trying to save to the same key). |
| 30 | +# Matches the pattern used in openjd-rs. |
| 31 | +concurrency: |
| 32 | + group: rust-quality-${{ github.workflow }}-${{ github.ref }} |
| 33 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 34 | + |
| 35 | +env: |
| 36 | + CARGO_INCREMENTAL: 0 |
| 37 | + CARGO_NET_RETRY: 10 |
| 38 | + RUSTUP_MAX_RETRIES: 10 |
| 39 | + RUST_BACKTRACE: 1 |
| 40 | + |
| 41 | +jobs: |
| 42 | + rust_quality: |
| 43 | + name: Rust (${{ matrix.os }}) |
| 44 | + strategy: |
| 45 | + fail-fast: false |
| 46 | + matrix: |
| 47 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 48 | + runs-on: ${{ matrix.os }} |
| 49 | + permissions: |
| 50 | + contents: read |
| 51 | + |
| 52 | + steps: |
| 53 | + - name: Checkout openjd-model-for-python |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + ref: ${{ inputs.branch || inputs.tag || github.ref }} |
| 57 | + |
| 58 | + - name: Install Rust toolchain |
| 59 | + uses: dtolnay/rust-toolchain@stable |
| 60 | + with: |
| 61 | + components: clippy, rustfmt |
| 62 | + |
| 63 | + # Include the rustc version in the cache key so that a toolchain |
| 64 | + # upgrade automatically invalidates the target/ cache (stale rustc |
| 65 | + # artifacts are one of the main reasons cache restore-key hits |
| 66 | + # produce slow rebuilds). |
| 67 | + - name: Compute rustc hash |
| 68 | + id: rustc |
| 69 | + shell: bash |
| 70 | + run: echo "hash=$(rustc --version --verbose | sha256sum | cut -c1-16)" >> "$GITHUB_OUTPUT" |
| 71 | + |
| 72 | + - name: Cache Cargo registry and build artifacts |
| 73 | + id: cache |
| 74 | + uses: actions/cache@v4 |
| 75 | + with: |
| 76 | + path: | |
| 77 | + ~/.cargo/registry/index |
| 78 | + ~/.cargo/registry/cache |
| 79 | + ~/.cargo/git/db |
| 80 | + target |
| 81 | + key: cargo-${{ matrix.os }}-${{ steps.rustc.outputs.hash }}-${{ hashFiles('Cargo.lock', 'rust-bindings/Cargo.toml') }} |
| 82 | + restore-keys: | |
| 83 | + cargo-${{ matrix.os }}-${{ steps.rustc.outputs.hash }}- |
| 84 | + cargo-${{ matrix.os }}- |
| 85 | +
|
| 86 | + # On a restore-key (non-exact) hit, target/ contains artifacts built |
| 87 | + # against a different Cargo.lock. Cargo will spend a long time |
| 88 | + # scanning fingerprints and discovering staleness, especially on |
| 89 | + # Windows. Starting from an empty target/ with a warm registry cache |
| 90 | + # is faster. |
| 91 | + - name: Discard stale target/ on restore-key-only hit |
| 92 | + if: steps.cache.outputs.cache-hit != 'true' |
| 93 | + shell: bash |
| 94 | + run: rm -rf target |
| 95 | + |
| 96 | + - name: cargo fmt --check |
| 97 | + run: cargo fmt --manifest-path rust-bindings/Cargo.toml --check |
| 98 | + |
| 99 | + - name: cargo build |
| 100 | + run: cargo build --manifest-path rust-bindings/Cargo.toml --all-targets |
| 101 | + |
| 102 | + - name: cargo clippy |
| 103 | + run: cargo clippy --manifest-path rust-bindings/Cargo.toml --all-targets -- -D warnings |
| 104 | + |
| 105 | + - name: cargo test |
| 106 | + run: cargo test --manifest-path rust-bindings/Cargo.toml |
| 107 | + |
| 108 | + - name: cargo test --doc |
| 109 | + # Runs separately from `cargo test` above so a docstring regression |
| 110 | + # (e.g. a Python example rustdoc tries to compile as Rust) is |
| 111 | + # clearly visible in the CI log. |
| 112 | + run: cargo test --manifest-path rust-bindings/Cargo.toml --doc |
| 113 | + |
| 114 | + cargo_doc: |
| 115 | + name: cargo doc -D warnings |
| 116 | + runs-on: ubuntu-latest |
| 117 | + permissions: |
| 118 | + contents: read |
| 119 | + steps: |
| 120 | + - name: Checkout openjd-model-for-python |
| 121 | + uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + ref: ${{ inputs.branch || inputs.tag || github.ref }} |
| 124 | + |
| 125 | + - name: Install Rust toolchain |
| 126 | + uses: dtolnay/rust-toolchain@stable |
| 127 | + |
| 128 | + - name: Compute rustc hash |
| 129 | + id: rustc |
| 130 | + shell: bash |
| 131 | + run: echo "hash=$(rustc --version --verbose | sha256sum | cut -c1-16)" >> "$GITHUB_OUTPUT" |
| 132 | + |
| 133 | + # Restore-only: rust_quality(ubuntu) owns the cache write. Saving |
| 134 | + # from here too would race with that job. |
| 135 | + - name: Restore Cargo cache (read-only) |
| 136 | + uses: actions/cache/restore@v4 |
| 137 | + with: |
| 138 | + path: | |
| 139 | + ~/.cargo/registry/index |
| 140 | + ~/.cargo/registry/cache |
| 141 | + ~/.cargo/git/db |
| 142 | + target |
| 143 | + key: cargo-ubuntu-latest-${{ steps.rustc.outputs.hash }}-${{ hashFiles('Cargo.lock', 'rust-bindings/Cargo.toml') }} |
| 144 | + restore-keys: | |
| 145 | + cargo-ubuntu-latest-${{ steps.rustc.outputs.hash }}- |
| 146 | + cargo-ubuntu-latest- |
| 147 | +
|
| 148 | + # Catches docstring breakages (broken intra-doc links, stale code |
| 149 | + # blocks, etc.) in pyclass `///` docs. |
| 150 | + - name: cargo doc |
| 151 | + run: cargo doc --manifest-path rust-bindings/Cargo.toml --no-deps |
| 152 | + env: |
| 153 | + RUSTDOCFLAGS: -D warnings |
| 154 | + |
| 155 | + cargo_deny: |
| 156 | + name: cargo-deny (licenses, advisories, bans, sources) |
| 157 | + runs-on: ubuntu-latest |
| 158 | + permissions: |
| 159 | + contents: read |
| 160 | + steps: |
| 161 | + - name: Checkout openjd-model-for-python |
| 162 | + uses: actions/checkout@v4 |
| 163 | + with: |
| 164 | + ref: ${{ inputs.branch || inputs.tag || github.ref }} |
| 165 | + |
| 166 | + - name: Install Rust toolchain |
| 167 | + uses: dtolnay/rust-toolchain@stable |
| 168 | + |
| 169 | + - name: Install cargo-deny |
| 170 | + run: cargo install cargo-deny --locked |
| 171 | + |
| 172 | + # Licenses, bans, and sources apply to every crate we compile, |
| 173 | + # including dev-dependencies, so scan the full graph. Advisories |
| 174 | + # are scoped to the normal dep graph (what actually ships in the |
| 175 | + # extension module). |
| 176 | + - name: cargo deny check licenses, bans, sources |
| 177 | + run: cargo deny --manifest-path rust-bindings/Cargo.toml check --config deny.toml licenses bans sources |
| 178 | + |
| 179 | + - name: cargo deny check advisories |
| 180 | + run: cargo deny --manifest-path rust-bindings/Cargo.toml check --config deny.toml advisories --exclude-dev |
| 181 | + |
| 182 | + third_party_licenses: |
| 183 | + name: THIRD-PARTY-LICENSES check |
| 184 | + runs-on: ubuntu-latest |
| 185 | + permissions: |
| 186 | + contents: read |
| 187 | + steps: |
| 188 | + - name: Checkout openjd-model-for-python |
| 189 | + uses: actions/checkout@v4 |
| 190 | + with: |
| 191 | + ref: ${{ inputs.branch || inputs.tag || github.ref }} |
| 192 | + |
| 193 | + - name: Install Rust toolchain |
| 194 | + uses: dtolnay/rust-toolchain@stable |
| 195 | + |
| 196 | + # cargo-about renders `about.hbs` using the workspace's Cargo.lock |
| 197 | + # and `about.toml`. The committed `THIRD-PARTY-LICENSES` is shipped |
| 198 | + # with every release, so it must stay in sync with the dependency |
| 199 | + # graph. The `cli` feature is required to actually build the |
| 200 | + # cargo-about binary; without it `cargo install` compiles the crate |
| 201 | + # but emits "none of the package's binaries are available" and |
| 202 | + # installs nothing. |
| 203 | + - name: Install cargo-about |
| 204 | + run: cargo install cargo-about --locked --features cli |
| 205 | + |
| 206 | + - name: Check THIRD-PARTY-LICENSES is up to date |
| 207 | + run: bash scripts/check_third_party_licenses.sh |
0 commit comments