Skip to content

Commit 85435e6

Browse files
bfopsjoshua-spacetime
authored andcommitted
Misc cleanups in tools/upgrade-version (#3370)
# Description of Changes * Make sure the user provides at least one of `--rust-and-cli`, `--typescript`, or `--csharp`, since providing none of them is a no-op as of #3308 * Do a semver-parsing of the arg before doing anything, and use that parsed version everywhere * Consolidate some version strings that we were computing in a few places # API and ABI breaking changes None # Expected complexity level and risk 1 # Testing - [x] Running `cargo bump-versions 1.5.0 --typescript --rust-and-cli --csharp` only shows a diff in the change dates --------- Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent 0842310 commit 85435e6

1 file changed

Lines changed: 43 additions & 25 deletions

File tree

tools/upgrade-version/src/main.rs

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(clippy::disallowed_macros)]
22

33
use chrono::{Datelike, Local};
4-
use clap::{Arg, Command};
4+
use clap::{Arg, ArgGroup, Command};
55
use duct::cmd;
66
use regex::Regex;
77
use semver::Version;
@@ -90,9 +90,26 @@ fn main() -> anyhow::Result<()> {
9090
.action(clap::ArgAction::SetTrue)
9191
.help("Also bump versions in C# SDK and templates"),
9292
)
93+
.arg(
94+
Arg::new("all")
95+
.long("all")
96+
.action(clap::ArgAction::SetTrue)
97+
.help("Update all targets (equivalent to --typescript --rust-and-cli --csharp)")
98+
.conflicts_with_all(["typescript", "rust-and-cli", "csharp"]),
99+
)
100+
.group(
101+
ArgGroup::new("update-targets")
102+
.args(["all", "typescript", "rust-and-cli", "csharp"])
103+
.required(true)
104+
.multiple(true),
105+
)
93106
.get_matches();
94107

95-
let version = matches.get_one::<String>("upgrade_version").unwrap();
108+
let unparsed_version_arg = matches.get_one::<String>("upgrade_version").unwrap();
109+
let semver = Version::parse(unparsed_version_arg).expect("Invalid semver provided to upgrade-version");
110+
let full_version = format!("{}.{}.{}", semver.major, semver.minor, semver.patch);
111+
let wildcard_patch = format!("{}.{}.*", semver.major, semver.minor);
112+
96113
if let Some(path) = matches.get_one::<PathBuf>("spacetime-path") {
97114
env::set_current_dir(path).ok();
98115
}
@@ -103,14 +120,14 @@ fn main() -> anyhow::Result<()> {
103120
anyhow::bail!("You must execute this binary from inside of the SpacetimeDB directory, or use --spacetime-path");
104121
}
105122

106-
if matches.get_flag("rust-and-cli") {
123+
if matches.get_flag("rust-and-cli") || matches.get_flag("all") {
107124
// Use `=` for dependency versions, to avoid issues where Cargo automatically rolls forward to later minor versions.
108125
// See https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#default-requirements.
109-
let dep_version = format!("={version}");
126+
let dep_version = format!("={full_version}");
110127

111128
// root Cargo.toml
112129
edit_toml("Cargo.toml", |doc| {
113-
doc["workspace"]["package"]["version"] = toml_edit::value(version);
130+
doc["workspace"]["package"]["version"] = toml_edit::value(full_version.clone());
114131
for (key, dep) in doc["workspace"]["dependencies"]
115132
.as_table_like_mut()
116133
.expect("workspace.dependencies is not a table")
@@ -128,26 +145,19 @@ fn main() -> anyhow::Result<()> {
128145
//
129146
// Note: This is meaningfully different than setting just major.minor.
130147
// See https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#default-requirements.
131-
let v = Version::parse(version).expect("Invalid semver provided to upgrade-version");
132-
let major_minor = format!("{}.{}.*", v.major, v.minor);
133-
doc["dependencies"]["spacetimedb"] = toml_edit::value(major_minor);
148+
doc["dependencies"]["spacetimedb"] = toml_edit::value(wildcard_patch.clone());
134149
})?;
135150

136-
process_license_file("LICENSE.txt", version);
137-
process_license_file("licenses/BSL.txt", version);
151+
process_license_file("LICENSE.txt", &full_version);
152+
process_license_file("licenses/BSL.txt", &full_version);
138153
cmd!("cargo", "check").run().expect("Cargo check failed!");
139154
}
140155

141-
if matches.get_flag("typescript") {
142-
rewrite_json_version_inplace("crates/bindings-typescript/package.json", version)?;
156+
if matches.get_flag("typescript") || matches.get_flag("all") {
157+
rewrite_json_version_inplace("crates/bindings-typescript/package.json", &full_version)?;
143158
}
144159

145-
if matches.get_flag("csharp") {
146-
// Compute various version forms
147-
let v = Version::parse(version).expect("Invalid semver provided to upgrade-version");
148-
let wildcard_patch = format!("{}.{}.*", v.major, v.minor);
149-
let assembly_version = format!("{}.{}.{}", v.major, v.minor, v.patch);
150-
160+
if matches.get_flag("csharp") || matches.get_flag("all") {
151161
// Helpers for XML edits
152162
fn rewrite_xml_tag_value(path: &str, tag: &str, new_value: &str) -> anyhow::Result<()> {
153163
let contents = fs::read_to_string(path)?;
@@ -196,13 +206,13 @@ fn main() -> anyhow::Result<()> {
196206

197207
// 1) Client SDK csproj
198208
let client_sdk = "sdks/csharp/SpacetimeDB.ClientSDK.csproj";
199-
rewrite_xml_tag_value(client_sdk, "Version", version)?;
200-
rewrite_xml_tag_value(client_sdk, "AssemblyVersion", &assembly_version)?;
209+
rewrite_xml_tag_value(client_sdk, "Version", &full_version)?;
210+
rewrite_xml_tag_value(client_sdk, "AssemblyVersion", &full_version)?;
201211
// Update SpacetimeDB.BSATN.Runtime dependency to major.minor.*
202212
rewrite_csproj_package_ref_version(client_sdk, "SpacetimeDB.BSATN.Runtime", &wildcard_patch)?;
203213

204214
// Also bump the C# SDK package.json version (preserve formatting)
205-
rewrite_json_version_inplace("sdks/csharp/package.json", version)?;
215+
rewrite_json_version_inplace("sdks/csharp/package.json", &full_version)?;
206216

207217
// 2) StdbModule.csproj files: SpacetimeDB.Runtime dependency -> major.minor
208218
let stdb_modules: &[&str] = &[
@@ -218,15 +228,23 @@ fn main() -> anyhow::Result<()> {
218228
rewrite_xml_tag_value(
219229
"crates/bindings-csharp/BSATN.Runtime/BSATN.Runtime.csproj",
220230
"Version",
221-
version,
231+
&full_version,
232+
)?;
233+
rewrite_xml_tag_value(
234+
"crates/bindings-csharp/Runtime/Runtime.csproj",
235+
"Version",
236+
&full_version,
222237
)?;
223-
rewrite_xml_tag_value("crates/bindings-csharp/Runtime/Runtime.csproj", "Version", version)?;
224238
rewrite_xml_tag_value(
225239
"crates/bindings-csharp/BSATN.Codegen/BSATN.Codegen.csproj",
226240
"Version",
227-
version,
241+
&full_version,
242+
)?;
243+
rewrite_xml_tag_value(
244+
"crates/bindings-csharp/Codegen/Codegen.csproj",
245+
"Version",
246+
&full_version,
228247
)?;
229-
rewrite_xml_tag_value("crates/bindings-csharp/Codegen/Codegen.csproj", "Version", version)?;
230248

231249
// 4) Template StdbModule._csproj: SpacetimeDB.Runtime dependency -> major.minor.*
232250
rewrite_csproj_package_ref_version(

0 commit comments

Comments
 (0)