Skip to content

Commit 56f5097

Browse files
Prevent dirty Cargo.lock changes from install (#18693)
Spawning from #18689 Example CI failure that will stop people from leaving stray `Cargo.lock` changes behind, ``` Error: Cargo.lock has uncommitted changes after install. Please run 'poetry install --extras all' and commit the Cargo.lock changes. ```
1 parent 797fa57 commit 56f5097

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

.github/workflows/tests.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,43 @@ jobs:
263263

264264
- run: cargo clippy --all-features -- -D warnings
265265

266+
lint-rust:
267+
runs-on: ubuntu-latest
268+
needs: changes
269+
if: ${{ needs.changes.outputs.rust == 'true' }}
270+
271+
steps:
272+
- name: Checkout repository
273+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
274+
275+
- name: Install Rust
276+
uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # master
277+
with:
278+
toolchain: ${{ env.RUST_VERSION }}
279+
- uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0
280+
281+
- name: Setup Poetry
282+
uses: matrix-org/setup-python-poetry@5bbf6603c5c930615ec8a29f1b5d7d258d905aa4 # v2.0.0
283+
with:
284+
# Install like a normal project from source with all optional dependencies
285+
extras: all
286+
install-project: "true"
287+
poetry-version: "2.1.1"
288+
289+
- name: Ensure `Cargo.lock` is up to date (no stray changes after install)
290+
# The `::error::` syntax is using GitHub Actions' error annotations, see
291+
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions
292+
run: |
293+
if git diff --quiet Cargo.lock; then
294+
echo "Cargo.lock is up to date"
295+
else
296+
echo "::error::Cargo.lock has uncommitted changes after install. Please run 'poetry install --extras all' and commit the Cargo.lock changes."
297+
git diff --exit-code Cargo.lock
298+
exit 1
299+
fi
300+
301+
# This job is split from `lint-rust` because it requires a nightly Rust toolchain
302+
# for some of the unstable options we use in `.rustfmt.toml`.
266303
lint-rustfmt:
267304
runs-on: ubuntu-latest
268305
needs: changes
@@ -274,7 +311,8 @@ jobs:
274311
- name: Install Rust
275312
uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # master
276313
with:
277-
# We use nightly so that it correctly groups together imports
314+
# We use nightly so that we can use some unstable options that we use in
315+
# `.rustfmt.toml`.
278316
toolchain: nightly-2025-04-23
279317
components: rustfmt
280318
- uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0
@@ -309,6 +347,7 @@ jobs:
309347
- check-lockfile
310348
- lint-clippy
311349
- lint-clippy-nightly
350+
- lint-rust
312351
- lint-rustfmt
313352
- lint-readme
314353
runs-on: ubuntu-latest
@@ -327,6 +366,7 @@ jobs:
327366
lint-pydantic
328367
lint-clippy
329368
lint-clippy-nightly
369+
lint-rust
330370
lint-rustfmt
331371
lint-readme
332372

.rustfmt.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
# Unstable options are only available on a nightly toolchain and must be opted into
2+
unstable_features = true
3+
4+
# `group_imports` is an unstable option that requires nightly Rust toolchain. Tracked by
5+
# https://github.com/rust-lang/rustfmt/issues/5083
16
group_imports = "StdExternalCrate"

changelog.d/18693.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevent dirty `Cargo.lock` changes from install.

0 commit comments

Comments
 (0)