Skip to content

smoke_test: Run git commit to work around cargo bug #9405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion crates/crates_io_smoke_test/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@
.map_err(Into::into)
}

#[allow(unstable_name_collisions)]
pub async fn package(project_path: &Path) -> anyhow::Result<()> {
Command::new("cargo")
.args(["package"])
.current_dir(project_path)
.env("CARGO_TERM_COLOR", "always")
.status()
.await?
.exit_ok()
.map_err(Into::into)
}

Check warning on line 28 in crates/crates_io_smoke_test/src/cargo.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/cargo.rs#L19-L28

Added lines #L19 - L28 were not covered by tests

#[allow(unstable_name_collisions)]
pub async fn publish(project_path: &Path, token: &SecretString) -> anyhow::Result<()> {
Command::new("cargo")
.args(["publish", "--registry", "staging", "--allow-dirty"])
.args(["publish", "--registry", "staging"])

Check warning on line 33 in crates/crates_io_smoke_test/src/cargo.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/cargo.rs#L33

Added line #L33 was not covered by tests
.current_dir(project_path)
.env("CARGO_TERM_COLOR", "always")
.env(
Expand Down
25 changes: 25 additions & 0 deletions crates/crates_io_smoke_test/src/git.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::exit_status_ext::ExitStatusExt;
use std::path::Path;
use tokio::process::Command;

#[allow(unstable_name_collisions)]
pub async fn add_all(project_path: &Path) -> anyhow::Result<()> {
Command::new("git")
.args(["add", "--all"])
.current_dir(project_path)
.status()
.await?
.exit_ok()
.map_err(Into::into)
}

Check warning on line 14 in crates/crates_io_smoke_test/src/git.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/git.rs#L6-L14

Added lines #L6 - L14 were not covered by tests

#[allow(unstable_name_collisions)]
pub async fn commit(project_path: &Path, message: &str) -> anyhow::Result<()> {
Command::new("git")
.args(["commit", "--message", message])
.current_dir(project_path)
.status()
.await?
.exit_ok()
.map_err(Into::into)
}

Check warning on line 25 in crates/crates_io_smoke_test/src/git.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/git.rs#L17-L25

Added lines #L17 - L25 were not covered by tests
39 changes: 28 additions & 11 deletions crates/crates_io_smoke_test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod api;
mod cargo;
mod exit_status_ext;
mod git;

#[macro_use]
extern crate tracing;
Expand Down Expand Up @@ -52,27 +53,34 @@
let old_version = krate.max_version;
let mut new_version = old_version.clone();

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

Check warning on line 57 in crates/crates_io_smoke_test/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/main.rs#L56-L57

Added lines #L56 - L57 were not covered by tests

info!("Creating temporary working folder…");
let tempdir = tempdir().context("Failed to create temporary working folder")?;
debug!(tempdir.path = %tempdir.path().display());
info!("Creating temporary working folder…");
let tempdir = tempdir().context("Failed to create temporary working folder")?;
debug!(tempdir.path = %tempdir.path().display());

Check warning on line 61 in crates/crates_io_smoke_test/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/main.rs#L59-L61

Added lines #L59 - L61 were not covered by tests

info!("Creating `{}` project…", options.crate_name);
let project_path = create_project(tempdir.path(), &options.crate_name, &new_version)
info!("Creating `{}` project…", options.crate_name);
let project_path = create_project(tempdir.path(), &options.crate_name, &new_version)
.await
.context("Failed to create project")?;

if options.skip_publish {
info!("Packaging crate file…");
cargo::package(&project_path)

Check warning on line 70 in crates/crates_io_smoke_test/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/main.rs#L63-L70

Added lines #L63 - L70 were not covered by tests
.await
.context("Failed to create project")?;
.context("Failed to run `cargo package`")?;

Check warning on line 72 in crates/crates_io_smoke_test/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/main.rs#L72

Added line #L72 was not covered by tests

info!("Skipping publish step");
} else {

Check warning on line 75 in crates/crates_io_smoke_test/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/main.rs#L74-L75

Added lines #L74 - L75 were not covered by tests
info!("Publishing to staging.crates.io…");
cargo::publish(&project_path, &options.token)
.await
.context("Failed to run `cargo publish`")?;
}

drop(tempdir);

Check warning on line 83 in crates/crates_io_smoke_test/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/main.rs#L82-L83

Added lines #L82 - L83 were not covered by tests
let version = new_version;
info!(%version, "Checking staging.crates.io API for the new version…");

Expand Down Expand Up @@ -217,5 +225,14 @@
.context("Failed to write `README.md` file content")?;
}

info!("Creating initial git commit…");
git::add_all(&project_path)
.await
.context("Failed to add initial changes to git")?;

Check warning on line 231 in crates/crates_io_smoke_test/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/main.rs#L228-L231

Added lines #L228 - L231 were not covered by tests

git::commit(&project_path, "initial commit")
.await
.context("Failed to commit initial changes")?;

Check warning on line 235 in crates/crates_io_smoke_test/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/crates_io_smoke_test/src/main.rs#L233-L235

Added lines #L233 - L235 were not covered by tests

Ok(project_path)
}