From 70223cc08fc680315d78d0bdbc04d9cd9f986c64 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 6 Sep 2024 11:46:57 +0200 Subject: [PATCH] smoke_test: Set git username and email before committing On GitHub Actions the smoke test currently fails with: ``` Author identity unknown *** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. ``` This change adds the necessary git commands to our setup to hopefully make the `git commit` call succeed now. --- crates/crates_io_smoke_test/src/git.rs | 22 ++++++++++++++++++++++ crates/crates_io_smoke_test/src/main.rs | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/crates/crates_io_smoke_test/src/git.rs b/crates/crates_io_smoke_test/src/git.rs index 801c6cde19c..a47626afa25 100644 --- a/crates/crates_io_smoke_test/src/git.rs +++ b/crates/crates_io_smoke_test/src/git.rs @@ -2,6 +2,28 @@ use crate::exit_status_ext::ExitStatusExt; use std::path::Path; use tokio::process::Command; +#[allow(unstable_name_collisions)] +pub async fn set_user_name(project_path: &Path, name: &str) -> anyhow::Result<()> { + Command::new("git") + .args(["config", "user.name", name]) + .current_dir(project_path) + .status() + .await? + .exit_ok() + .map_err(Into::into) +} + +#[allow(unstable_name_collisions)] +pub async fn set_user_email(project_path: &Path, email: &str) -> anyhow::Result<()> { + Command::new("git") + .args(["config", "user.email", email]) + .current_dir(project_path) + .status() + .await? + .exit_ok() + .map_err(Into::into) +} + #[allow(unstable_name_collisions)] pub async fn add_all(project_path: &Path) -> anyhow::Result<()> { Command::new("git") diff --git a/crates/crates_io_smoke_test/src/main.rs b/crates/crates_io_smoke_test/src/main.rs index 891ad6d9baa..e3b3d7005b0 100644 --- a/crates/crates_io_smoke_test/src/main.rs +++ b/crates/crates_io_smoke_test/src/main.rs @@ -226,6 +226,14 @@ description = "test crate" } info!("Creating initial git commit…"); + git::set_user_name(&project_path, "crates-io-smoke-test") + .await + .context("Failed to set git user name")?; + + git::set_user_email(&project_path, "smoke-test@crates.io") + .await + .context("Failed to set git user email")?; + git::add_all(&project_path) .await .context("Failed to add initial changes to git")?;