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