Skip to content

Commit 5bc5796

Browse files
authored
Merge pull request #9405 from Turbo87/smoky
smoke_test: Run `git commit` to work around cargo bug
2 parents 0e3362e + 334ee11 commit 5bc5796

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

crates/crates_io_smoke_test/src/cargo.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,22 @@ pub async fn new_lib(parent_path: &Path, name: &str) -> anyhow::Result<()> {
1515
.map_err(Into::into)
1616
}
1717

18+
#[allow(unstable_name_collisions)]
19+
pub async fn package(project_path: &Path) -> anyhow::Result<()> {
20+
Command::new("cargo")
21+
.args(["package"])
22+
.current_dir(project_path)
23+
.env("CARGO_TERM_COLOR", "always")
24+
.status()
25+
.await?
26+
.exit_ok()
27+
.map_err(Into::into)
28+
}
29+
1830
#[allow(unstable_name_collisions)]
1931
pub async fn publish(project_path: &Path, token: &SecretString) -> anyhow::Result<()> {
2032
Command::new("cargo")
21-
.args(["publish", "--registry", "staging", "--allow-dirty"])
33+
.args(["publish", "--registry", "staging"])
2234
.current_dir(project_path)
2335
.env("CARGO_TERM_COLOR", "always")
2436
.env(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::exit_status_ext::ExitStatusExt;
2+
use std::path::Path;
3+
use tokio::process::Command;
4+
5+
#[allow(unstable_name_collisions)]
6+
pub async fn add_all(project_path: &Path) -> anyhow::Result<()> {
7+
Command::new("git")
8+
.args(["add", "--all"])
9+
.current_dir(project_path)
10+
.status()
11+
.await?
12+
.exit_ok()
13+
.map_err(Into::into)
14+
}
15+
16+
#[allow(unstable_name_collisions)]
17+
pub async fn commit(project_path: &Path, message: &str) -> anyhow::Result<()> {
18+
Command::new("git")
19+
.args(["commit", "--message", message])
20+
.current_dir(project_path)
21+
.status()
22+
.await?
23+
.exit_ok()
24+
.map_err(Into::into)
25+
}

crates/crates_io_smoke_test/src/main.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod api;
22
mod cargo;
33
mod exit_status_ext;
4+
mod git;
45

56
#[macro_use]
67
extern crate tracing;
@@ -52,27 +53,34 @@ async fn main() -> anyhow::Result<()> {
5253
let old_version = krate.max_version;
5354
let mut new_version = old_version.clone();
5455

55-
if options.skip_publish {
56-
info!("Skipping publish step");
57-
} else {
58-
new_version.patch += 1;
59-
info!(%old_version, %new_version, "Calculated new version number");
56+
new_version.patch += 1;
57+
info!(%old_version, %new_version, "Calculated new version number");
6058

61-
info!("Creating temporary working folder…");
62-
let tempdir = tempdir().context("Failed to create temporary working folder")?;
63-
debug!(tempdir.path = %tempdir.path().display());
59+
info!("Creating temporary working folder…");
60+
let tempdir = tempdir().context("Failed to create temporary working folder")?;
61+
debug!(tempdir.path = %tempdir.path().display());
6462

65-
info!("Creating `{}` project…", options.crate_name);
66-
let project_path = create_project(tempdir.path(), &options.crate_name, &new_version)
63+
info!("Creating `{}` project…", options.crate_name);
64+
let project_path = create_project(tempdir.path(), &options.crate_name, &new_version)
65+
.await
66+
.context("Failed to create project")?;
67+
68+
if options.skip_publish {
69+
info!("Packaging crate file…");
70+
cargo::package(&project_path)
6771
.await
68-
.context("Failed to create project")?;
72+
.context("Failed to run `cargo package`")?;
6973

74+
info!("Skipping publish step");
75+
} else {
7076
info!("Publishing to staging.crates.io…");
7177
cargo::publish(&project_path, &options.token)
7278
.await
7379
.context("Failed to run `cargo publish`")?;
7480
}
7581

82+
drop(tempdir);
83+
7684
let version = new_version;
7785
info!(%version, "Checking staging.crates.io API for the new version…");
7886

@@ -217,5 +225,14 @@ description = "test crate"
217225
.context("Failed to write `README.md` file content")?;
218226
}
219227

228+
info!("Creating initial git commit…");
229+
git::add_all(&project_path)
230+
.await
231+
.context("Failed to add initial changes to git")?;
232+
233+
git::commit(&project_path, "initial commit")
234+
.await
235+
.context("Failed to commit initial changes")?;
236+
220237
Ok(project_path)
221238
}

0 commit comments

Comments
 (0)