From cc4f0653db0b4c7f930eb4ab8f9229af33856ac1 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 12 Apr 2023 11:38:36 -0700 Subject: [PATCH 1/4] rustfmt Signed-off-by: Jesse Szwedko --- vdev/src/commands/release/homebrew.rs | 36 +++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/vdev/src/commands/release/homebrew.rs b/vdev/src/commands/release/homebrew.rs index f8ac81afbfa58..6a5ac4e4ac836 100644 --- a/vdev/src/commands/release/homebrew.rs +++ b/vdev/src/commands/release/homebrew.rs @@ -1,12 +1,12 @@ -use anyhow::{Result}; -use std::env; -use tempfile::TempDir; use crate::git; +use anyhow::Result; use hex; -use sha2::Digest; +use regex; use reqwest; +use sha2::Digest; +use std::env; use std::path::Path; -use regex; +use tempfile::TempDir; /// Releases latest version to the vectordotdev homebrew tap #[derive(clap::Args, Debug)] @@ -20,25 +20,30 @@ impl Cli { env::set_current_dir(td.path())?; // Set git configurations - let config_values = &[ - ("user.name", "vic"), - ("user.email", "vector@datadoghq.com"), - ]; + let config_values = &[("user.name", "vic"), ("user.email", "vector@datadoghq.com")]; git::set_config_values(config_values)?; let github_token = env::var("GITHUB_TOKEN")?; // Clone the homebrew-brew repository - let homebrew_repo = format!("https://{github_token}:x-oauth-basic@github.com/vectordotdev/homebrew-brew"); + let homebrew_repo = + format!("https://{github_token}:x-oauth-basic@github.com/vectordotdev/homebrew-brew"); git::clone(&homebrew_repo)?; env::set_current_dir("homebrew-brew")?; // Get package details for updating Formula/vector.rb let vector_version = env::var("VECTOR_VERSION")?; let package_url = format!("https://packages.timber.io/vector/{vector_version}/vector-{vector_version}-x86_64-apple-darwin.tar.gz"); - let package_sha256 = hex::encode(sha2::Sha256::digest(reqwest::blocking::get(&package_url)?.bytes()?)); + let package_sha256 = hex::encode(sha2::Sha256::digest( + reqwest::blocking::get(&package_url)?.bytes()?, + )); // Update content of Formula/vector.rb - update_content("Formula/vector.rb", &package_url, &package_sha256, &vector_version)?; + update_content( + "Formula/vector.rb", + &package_url, + &package_sha256, + &vector_version, + )?; // Check if there is any change in git index let has_changes = !git::check_git_repository_clean()?; @@ -55,7 +60,12 @@ impl Cli { } /// Open the vector.rb file and update the new content -fn update_content

(file_path: P, package_url: &str, package_sha256: &str, vector_version: &str) -> Result<()> +fn update_content

( + file_path: P, + package_url: &str, + package_sha256: &str, + vector_version: &str, +) -> Result<()> where P: AsRef, { From 8493dd2ae7f0aa3c6fb2b6b0568b2d0cd44ddd6a Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 12 Apr 2023 11:39:39 -0700 Subject: [PATCH 2/4] Fix hombrew release subcommand A few changes: * `git config` only takes one key/value at a time * The `git` commands here need to run in the context of the homebrew-repo so shouldn't use the `check_output` function which changes directory to `vector` Signed-off-by: Jesse Szwedko --- vdev/src/commands/release/homebrew.rs | 6 ++++-- vdev/src/git.rs | 17 ++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/vdev/src/commands/release/homebrew.rs b/vdev/src/commands/release/homebrew.rs index 6a5ac4e4ac836..c227e65b73cb2 100644 --- a/vdev/src/commands/release/homebrew.rs +++ b/vdev/src/commands/release/homebrew.rs @@ -20,8 +20,9 @@ impl Cli { env::set_current_dir(td.path())?; // Set git configurations - let config_values = &[("user.name", "vic"), ("user.email", "vector@datadoghq.com")]; - git::set_config_values(config_values)?; + git::set_config_value("user.name", "vic")?; + git::set_config_value("user.email", "vector@datadoghq.com")?; + let github_token = env::var("GITHUB_TOKEN")?; // Clone the homebrew-brew repository @@ -51,6 +52,7 @@ impl Cli { let commit_message = format!("Release Vector {vector_version}"); git::commit(&commit_message)?; } + git::push()?; // Remove temporary directory diff --git a/vdev/src/git.rs b/vdev/src/git.rs index 0da65d4217da4..0eebdfa2444f3 100644 --- a/vdev/src/git.rs +++ b/vdev/src/git.rs @@ -91,15 +91,8 @@ pub fn get_modified_files() -> Result> { Ok(check_output(&args)?.lines().map(str::to_owned).collect()) } -pub fn set_config_values(config_values: &[(&str, &str)]) -> Result { - let mut args = vec!["config"]; - - for (key, value) in config_values { - args.push(key); - args.push(value); - } - - check_output(&args) +pub fn set_config_value(key: &str, value: &str) -> Result { + check_output(&["config", key, value]) } /// Checks if the current directory's repo is clean @@ -113,12 +106,14 @@ pub fn check_git_repository_clean() -> Result { /// Commits changes from the current repo pub fn commit(commit_message: &str) -> Result { - check_output(&["commit", "--all", "--message", commit_message]) + Command::new("git") + .args(&["commit", "--all", "--message", commit_message]) + .check_output() } /// Pushes changes from the current repo pub fn push() -> Result { - check_output(&["push"]) + Command::new("git").args(&["push"]).check_output() } pub fn clone(repo_url: &str) -> Result { From 7282da2f52f4b3a2fc66648360382b8cb33e543d Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 12 Apr 2023 12:54:33 -0700 Subject: [PATCH 3/4] clippy and one more git cwd change Signed-off-by: Jesse Szwedko --- vdev/src/git.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vdev/src/git.rs b/vdev/src/git.rs index 0eebdfa2444f3..fb5ddbcd42091 100644 --- a/vdev/src/git.rs +++ b/vdev/src/git.rs @@ -92,7 +92,10 @@ pub fn get_modified_files() -> Result> { } pub fn set_config_value(key: &str, value: &str) -> Result { - check_output(&["config", key, value]) + Command::new("git") + .args(["config", key, value]) + .stdout(std::process::Stdio::null()) + .check_output() } /// Checks if the current directory's repo is clean @@ -107,13 +110,13 @@ pub fn check_git_repository_clean() -> Result { /// Commits changes from the current repo pub fn commit(commit_message: &str) -> Result { Command::new("git") - .args(&["commit", "--all", "--message", commit_message]) + .args(["commit", "--all", "--message", commit_message]) .check_output() } /// Pushes changes from the current repo pub fn push() -> Result { - Command::new("git").args(&["push"]).check_output() + Command::new("git").args(["push"]).check_output() } pub fn clone(repo_url: &str) -> Result { From d012d63c625b62c3e92a8c2ed3593d87b0bec270 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 12 Apr 2023 13:21:48 -0700 Subject: [PATCH 4/4] Move git config to after cd into homebrew repo Signed-off-by: Jesse Szwedko --- vdev/src/commands/release/homebrew.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vdev/src/commands/release/homebrew.rs b/vdev/src/commands/release/homebrew.rs index c227e65b73cb2..25f4c1b02ec4f 100644 --- a/vdev/src/commands/release/homebrew.rs +++ b/vdev/src/commands/release/homebrew.rs @@ -19,10 +19,6 @@ impl Cli { let td = TempDir::new()?; env::set_current_dir(td.path())?; - // Set git configurations - git::set_config_value("user.name", "vic")?; - git::set_config_value("user.email", "vector@datadoghq.com")?; - let github_token = env::var("GITHUB_TOKEN")?; // Clone the homebrew-brew repository @@ -31,6 +27,10 @@ impl Cli { git::clone(&homebrew_repo)?; env::set_current_dir("homebrew-brew")?; + // Set git configurations + git::set_config_value("user.name", "vic")?; + git::set_config_value("user.email", "vector@datadoghq.com")?; + // Get package details for updating Formula/vector.rb let vector_version = env::var("VECTOR_VERSION")?; let package_url = format!("https://packages.timber.io/vector/{vector_version}/vector-{vector_version}-x86_64-apple-darwin.tar.gz");