Skip to content

Commit 50d0dfb

Browse files
committed
Always bump at least the patch version in bump xtask
As long as the source code has changed. Previously, the command would do nothing if there weren't any conventional commits. * Commit the Cargo.lock in the version bump commit. * Simplify logic for deciding whether to bump minor or patch version.
1 parent 63fa0f2 commit 50d0dfb

File tree

1 file changed

+28
-62
lines changed

1 file changed

+28
-62
lines changed

xtask/src/bump.rs

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,6 @@ use indoc::indoc;
55
use semver::{BuildMetadata, Prerelease, Version};
66
use toml::Value;
77

8-
fn increment_patch(v: &mut Version) {
9-
v.patch += 1;
10-
v.pre = Prerelease::EMPTY;
11-
v.build = BuildMetadata::EMPTY;
12-
}
13-
14-
fn increment_minor(v: &mut Version) {
15-
v.minor += 1;
16-
v.patch = 0;
17-
v.pre = Prerelease::EMPTY;
18-
v.build = BuildMetadata::EMPTY;
19-
}
20-
218
pub fn get_latest_tag(repo: &Repository) -> Result<String, Box<dyn std::error::Error>> {
229
let mut tags = repo
2310
.tag_names(None)?
@@ -62,7 +49,8 @@ pub fn bump_versions() -> Result<(), Box<dyn std::error::Error>> {
6249
let mut diff_options = DiffOptions::new();
6350

6451
let current_version = Version::parse(&latest_tag)?;
65-
let mut next_version = None;
52+
let mut should_increment_patch = false;
53+
let mut should_increment_minor = false;
6654

6755
for oid in revwalk {
6856
let oid = oid?;
@@ -81,12 +69,12 @@ pub fn bump_versions() -> Result<(), Box<dyn std::error::Error>> {
8169
)?
8270
};
8371

84-
let mut update = false;
72+
let mut source_code_changed = false;
8573
diff.foreach(
8674
&mut |delta, _| {
8775
let path = delta.new_file().path().unwrap().to_str().unwrap();
8876
if path.ends_with("rs") || path.ends_with("js") || path.ends_with('c') {
89-
update = true;
77+
source_code_changed = true;
9078
}
9179
true
9280
},
@@ -95,7 +83,9 @@ pub fn bump_versions() -> Result<(), Box<dyn std::error::Error>> {
9583
None,
9684
)?;
9785

98-
if update {
86+
if source_code_changed {
87+
should_increment_patch = true;
88+
9989
let Some((prefix, _)) = message.split_once(':') else {
10090
continue;
10191
};
@@ -106,57 +96,32 @@ pub fn bump_versions() -> Result<(), Box<dyn std::error::Error>> {
10696
prefix
10797
};
10898

109-
match convention {
110-
"feat" | "feat!" => {
111-
let mut cur_version = current_version.clone();
112-
increment_minor(&mut cur_version);
113-
if let Some(ref ver) = next_version {
114-
if cur_version > *ver {
115-
next_version = Some(cur_version);
116-
}
117-
} else {
118-
next_version = Some(cur_version);
119-
}
120-
}
121-
"fix" | "refactor" if prefix.ends_with('!') => {
122-
let mut cur_version = current_version.clone();
123-
increment_minor(&mut cur_version);
124-
if let Some(ref ver) = next_version {
125-
if cur_version > *ver {
126-
next_version = Some(cur_version);
127-
}
128-
} else {
129-
next_version = Some(cur_version);
130-
}
131-
}
132-
"fix" | "refactor" => {
133-
let mut cur_version = current_version.clone();
134-
increment_patch(&mut cur_version);
135-
if let Some(ref ver) = next_version {
136-
if cur_version > *ver {
137-
next_version = Some(cur_version);
138-
}
139-
} else {
140-
next_version = Some(cur_version);
141-
}
142-
}
143-
_ => {}
99+
if ["feat", "feat!"].contains(&convention) || prefix.ends_with('!') {
100+
should_increment_minor = true;
144101
}
145102
}
146103
}
147104

148-
if let Some(ref next_version) = next_version {
149-
println!("Bumping from {current_version} to {next_version}");
150-
151-
update_crates(&current_version, next_version)?;
152-
153-
update_makefile(next_version)?;
154-
155-
update_npm(next_version)?;
156-
157-
tag_next_version(&repo, next_version)?;
105+
let mut version = current_version.clone();
106+
if should_increment_minor {
107+
version.minor += 1;
108+
version.patch = 0;
109+
version.pre = Prerelease::EMPTY;
110+
version.build = BuildMetadata::EMPTY;
111+
} else if should_increment_patch {
112+
version.patch += 1;
113+
version.pre = Prerelease::EMPTY;
114+
version.build = BuildMetadata::EMPTY;
115+
} else {
116+
return Err(format!("No source code changed since {current_version}").into());
158117
}
159118

119+
println!("Bumping from {current_version} to {version}");
120+
update_crates(&current_version, &version)?;
121+
update_makefile(&version)?;
122+
update_npm(&version)?;
123+
tag_next_version(&repo, &version)?;
124+
160125
Ok(())
161126
}
162127

@@ -170,6 +135,7 @@ fn tag_next_version(
170135

171136
for file in [
172137
"Cargo.toml",
138+
"Cargo.lock",
173139
"cli/Cargo.toml",
174140
"cli/config/Cargo.toml",
175141
"cli/loader/Cargo.toml",

0 commit comments

Comments
 (0)