Skip to content

Commit cfbf233

Browse files
committed
chore(releasing): Fix homebrew release script (vectordotdev#17131)
* rustfmt Signed-off-by: Jesse Szwedko <[email protected]> * 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 <[email protected]> * clippy and one more git cwd change Signed-off-by: Jesse Szwedko <[email protected]> * Move git config to after cd into homebrew repo Signed-off-by: Jesse Szwedko <[email protected]> --------- Signed-off-by: Jesse Szwedko <[email protected]>
1 parent 4bf6805 commit cfbf233

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

vdev/src/commands/release/homebrew.rs

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use anyhow::{Result};
2-
use std::env;
3-
use tempfile::TempDir;
41
use crate::git;
2+
use anyhow::Result;
53
use hex;
6-
use sha2::Digest;
4+
use regex;
75
use reqwest;
6+
use sha2::Digest;
7+
use std::env;
88
use std::path::Path;
9-
use regex;
9+
use tempfile::TempDir;
1010

1111
/// Releases latest version to the vectordotdev homebrew tap
1212
#[derive(clap::Args, Debug)]
@@ -19,33 +19,40 @@ impl Cli {
1919
let td = TempDir::new()?;
2020
env::set_current_dir(td.path())?;
2121

22-
// Set git configurations
23-
let config_values = &[
24-
("user.name", "vic"),
25-
("user.email", "[email protected]"),
26-
];
27-
git::set_config_values(config_values)?;
2822
let github_token = env::var("GITHUB_TOKEN")?;
2923

3024
// Clone the homebrew-brew repository
31-
let homebrew_repo = format!("https://{github_token}:[email protected]/vectordotdev/homebrew-brew");
25+
let homebrew_repo =
26+
format!("https://{github_token}:[email protected]/vectordotdev/homebrew-brew");
3227
git::clone(&homebrew_repo)?;
3328
env::set_current_dir("homebrew-brew")?;
3429

30+
// Set git configurations
31+
git::set_config_value("user.name", "vic")?;
32+
git::set_config_value("user.email", "[email protected]")?;
33+
3534
// Get package details for updating Formula/vector.rb
3635
let vector_version = env::var("VECTOR_VERSION")?;
3736
let package_url = format!("https://packages.timber.io/vector/{vector_version}/vector-{vector_version}-x86_64-apple-darwin.tar.gz");
38-
let package_sha256 = hex::encode(sha2::Sha256::digest(reqwest::blocking::get(&package_url)?.bytes()?));
37+
let package_sha256 = hex::encode(sha2::Sha256::digest(
38+
reqwest::blocking::get(&package_url)?.bytes()?,
39+
));
3940

4041
// Update content of Formula/vector.rb
41-
update_content("Formula/vector.rb", &package_url, &package_sha256, &vector_version)?;
42+
update_content(
43+
"Formula/vector.rb",
44+
&package_url,
45+
&package_sha256,
46+
&vector_version,
47+
)?;
4248

4349
// Check if there is any change in git index
4450
let has_changes = !git::check_git_repository_clean()?;
4551
if has_changes {
4652
let commit_message = format!("Release Vector {vector_version}");
4753
git::commit(&commit_message)?;
4854
}
55+
4956
git::push()?;
5057

5158
// Remove temporary directory
@@ -55,7 +62,12 @@ impl Cli {
5562
}
5663

5764
/// Open the vector.rb file and update the new content
58-
fn update_content<P>(file_path: P, package_url: &str, package_sha256: &str, vector_version: &str) -> Result<()>
65+
fn update_content<P>(
66+
file_path: P,
67+
package_url: &str,
68+
package_sha256: &str,
69+
vector_version: &str,
70+
) -> Result<()>
5971
where
6072
P: AsRef<Path>,
6173
{

vdev/src/git.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,11 @@ pub fn get_modified_files() -> Result<Vec<String>> {
9191
Ok(check_output(&args)?.lines().map(str::to_owned).collect())
9292
}
9393

94-
pub fn set_config_values(config_values: &[(&str, &str)]) -> Result<String> {
95-
let mut args = vec!["config"];
96-
97-
for (key, value) in config_values {
98-
args.push(key);
99-
args.push(value);
100-
}
101-
102-
check_output(&args)
94+
pub fn set_config_value(key: &str, value: &str) -> Result<String> {
95+
Command::new("git")
96+
.args(["config", key, value])
97+
.stdout(std::process::Stdio::null())
98+
.check_output()
10399
}
104100

105101
/// Checks if the current directory's repo is clean
@@ -113,12 +109,14 @@ pub fn check_git_repository_clean() -> Result<bool> {
113109

114110
/// Commits changes from the current repo
115111
pub fn commit(commit_message: &str) -> Result<String> {
116-
check_output(&["commit", "--all", "--message", commit_message])
112+
Command::new("git")
113+
.args(["commit", "--all", "--message", commit_message])
114+
.check_output()
117115
}
118116

119117
/// Pushes changes from the current repo
120118
pub fn push() -> Result<String> {
121-
check_output(&["push"])
119+
Command::new("git").args(["push"]).check_output()
122120
}
123121

124122
pub fn clone(repo_url: &str) -> Result<String> {

0 commit comments

Comments
 (0)