Skip to content

Commit c2fc606

Browse files
feat(vdev): check Cargo.lock for changes after cargo check/clippy (#24935)
* feat(vdev): check Cargo.lock for changes after cargo check/clippy * Only commit if no lockfile changes are detected
1 parent d38425a commit c2fc606

6 files changed

Lines changed: 57 additions & 12 deletions

File tree

Cargo.lock

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ vector-vrl-functions = { path = "lib/vector-vrl/functions", default-features = f
219219
vrl = { git = "https://github.com/vectordotdev/vrl.git", branch = "main", default-features = false, features = ["arbitrary", "cli", "test", "test_framework", "stdlib-base"] }
220220
mock_instant = { version = "0.6" }
221221
serial_test = { version = "3.2" }
222+
strum = { version = "0.28", features = ["derive"] }
222223

223224
[dependencies]
224225
cfg-if.workspace = true

lib/codecs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ serde_json.workspace = true
4242
serde-aux = { version = "4.5", optional = true }
4343
smallvec = { version = "1", default-features = false, features = ["union"] }
4444
snafu.workspace = true
45-
strum = { version = "0.26.3", features = ["derive"], optional = true }
45+
strum = { workspace = true, optional = true }
4646
syslog_loose = { version = "0.23", default-features = false, optional = true }
4747
tokio-util = { version = "0.7", default-features = false, features = ["codec"] }
4848
tokio = { workspace = true, features = ["full"] }

lib/vector-vrl/category/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ publish = false
77
license = "MPL-2.0"
88

99
[dependencies]
10-
strum = { version = "0.27", features = ["derive"] }
10+
strum.workspace = true

vdev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ tempfile.workspace = true
4242
toml.workspace = true
4343
toml_edit = "0.23"
4444
semver.workspace = true
45+
strum.workspace = true
4546
indoc.workspace = true
4647
git2 = { version = "0.20.4" }
4748
cfg-if.workspace = true

vdev/src/commands/check/rust.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use anyhow::Result;
2-
use std::ffi::OsString;
1+
use anyhow::{Result, bail};
2+
use std::{ffi::OsString, fs};
33

44
use crate::{
55
app,
6-
utils::{command::ChainArgs as _, git},
6+
utils::{command::ChainArgs as _, git, paths},
77
};
88

99
/// Check the Rust code for errors
@@ -20,11 +20,16 @@ pub struct Cli {
2020
fix: bool,
2121
}
2222

23+
#[derive(strum::Display, strum::AsRefStr, Clone, Copy, Debug)]
24+
#[strum(serialize_all = "lowercase")]
25+
enum Tool {
26+
Clippy,
27+
Check,
28+
}
29+
2330
impl Cli {
2431
/// Build the argument vector for cargo invocation.
25-
fn build_args(&self) -> Vec<OsString> {
26-
let tool = if self.clippy { "clippy" } else { "check" };
27-
32+
fn build_args(&self, tool: Tool) -> Vec<OsString> {
2833
let pre_args = if self.fix {
2934
vec!["--fix"]
3035
} else {
@@ -47,14 +52,30 @@ impl Cli {
4752
]
4853
};
4954

50-
[tool, "--workspace", "--all-targets"]
55+
[tool.as_ref(), "--workspace", "--all-targets"]
5156
.chain_args(feature_args)
5257
.chain_args(pre_args)
5358
.chain_args(clippy_args)
5459
}
5560

5661
pub fn exec(self) -> Result<()> {
57-
app::exec("cargo", self.build_args(), true)?;
62+
let lock_file = paths::find_repo_root()?.join("Cargo.lock");
63+
let lock_before = fs::read(&lock_file)?;
64+
65+
let tool = if self.clippy {
66+
Tool::Clippy
67+
} else {
68+
Tool::Check
69+
};
70+
71+
app::exec("cargo", self.build_args(tool), true)?;
72+
73+
let lock_after = fs::read(&lock_file)?;
74+
if lock_before != lock_after {
75+
bail!(
76+
"Cargo.lock was modified by `cargo {tool}`. Please commit the updated Cargo.lock."
77+
);
78+
}
5879

5980
// If --fix was used, check for changes and commit them.
6081
if self.fix {

0 commit comments

Comments
 (0)