Skip to content

Commit b0740a6

Browse files
committed
fix(release): make publish helper non-interactive
1 parent 3cc5df5 commit b0740a6

1 file changed

Lines changed: 20 additions & 30 deletions

File tree

scripts/publish.rs

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
extern crate toml;
44

5+
use std::env;
56
use std::fs;
6-
use std::io;
77
use std::process::Command;
88
use std::thread::sleep;
99
use std::time::Duration;
@@ -120,33 +120,29 @@ fn ensure_versions_are_unpublished(version: &str) -> Result<(), Box<dyn std::err
120120
Ok(())
121121
}
122122

123-
fn read_line_trimmed() -> Result<String, Box<dyn std::error::Error>> {
124-
let mut input = String::new();
125-
io::stdin().read_line(&mut input)?;
126-
Ok(input.trim().to_string())
127-
}
128-
129123
fn main() -> Result<(), Box<dyn std::error::Error>> {
130-
ensure_clean_worktree()?;
131-
132-
println!("Enter target version (e.g. 1.0.0):");
133-
let target_version = read_line_trimmed()?;
134-
if target_version.is_empty() {
135-
return Err("Target version cannot be empty".into());
124+
let args: Vec<String> = env::args().collect();
125+
if args.len() > 2 {
126+
return Err(format!(
127+
"Usage: {} [expected_version]",
128+
args.first().map(String::as_str).unwrap_or("publish.rs")
129+
)
130+
.into());
136131
}
137132

138-
println!("\nUpdating versions...");
139-
run(
140-
{
141-
let mut cmd = Command::new("cargo");
142-
cmd.args(["script", "scripts/update_version.rs", "--", &target_version]);
143-
cmd
144-
},
145-
"Version update",
146-
)?;
133+
ensure_clean_worktree()?;
147134

148135
let version = verify_versions_match()?;
149-
println!("✓ All publishable crates are aligned at version {version}");
136+
if let Some(expected_version) = args.get(1) {
137+
if expected_version != &version {
138+
return Err(format!(
139+
"Workspace is aligned at version {version}, expected {expected_version}"
140+
)
141+
.into());
142+
}
143+
}
144+
145+
println!("Publishing aligned workspace version {version}");
150146
ensure_versions_are_unpublished(&version)?;
151147
println!("✓ No publishable crate is already on crates.io at version {version}");
152148

@@ -209,13 +205,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
209205
}
210206
}
211207

212-
println!(
213-
"\nPublish readiness checks passed for version {version}. Type 'publish' to continue with actual publish:"
214-
);
215-
let confirm = read_line_trimmed()?;
216-
if confirm != "publish" {
217-
return Err("Publish aborted by user".into());
218-
}
208+
println!("\nPublish readiness checks passed for version {version}.");
219209

220210
for (idx, crate_name) in PUBLISH_ORDER.iter().enumerate() {
221211
println!("\nPublishing {crate_name}...");

0 commit comments

Comments
 (0)