Skip to content
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

chore(releasing): Fix homebrew release script #17131

Merged
merged 4 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 26 additions & 14 deletions vdev/src/commands/release/homebrew.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -20,32 +20,39 @@ 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
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()?;
if has_changes {
let commit_message = format!("Release Vector {vector_version}");
git::commit(&commit_message)?;
}

git::push()?;

// Remove temporary directory
Expand All @@ -55,7 +62,12 @@ impl Cli {
}

/// Open the vector.rb file and update the new content
fn update_content<P>(file_path: P, package_url: &str, package_sha256: &str, vector_version: &str) -> Result<()>
fn update_content<P>(
file_path: P,
package_url: &str,
package_sha256: &str,
vector_version: &str,
) -> Result<()>
where
P: AsRef<Path>,
{
Expand Down
20 changes: 9 additions & 11 deletions vdev/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,11 @@ pub fn get_modified_files() -> Result<Vec<String>> {
Ok(check_output(&args)?.lines().map(str::to_owned).collect())
}

pub fn set_config_values(config_values: &[(&str, &str)]) -> Result<String> {
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<String> {
Command::new("git")
.args(["config", key, value])
.stdout(std::process::Stdio::null())
.check_output()
}

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

/// Commits changes from the current repo
pub fn commit(commit_message: &str) -> Result<String> {
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<String> {
check_output(&["push"])
Command::new("git").args(["push"]).check_output()
}

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