From 33b386802058ff6f6715a737790eed2fa80bdf29 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Tue, 11 Apr 2023 17:15:39 -0500 Subject: [PATCH] fix(releasing): Fix globbing of release artifacts for GitHub (#17114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since this was moved to vdev, we lost the automatic shell globbing. This introduces the `glob` crate to handle it. I tested it locally by swapping `gh` with `echo` and adding dummy files: ``` vector on  v0.29 [$!] is 📦 v0.29.0 via  v19.4.0 via 💎 v2.7.4 via 🦀 v1.66.1 on ☁️ ❯ touch target/artifacts/{foo,bar} vector on  v0.29 [$!] is 📦 v0.29.0 via  v19.4.0 via 💎 v2.7.4 via 🦀 v1.66.1 on ☁️ ❯ cargo vdev release github release --repo vectordotdev/vector create v0.29.0 --title v0.29.0 --notes [View release notes](https://vector.dev/releases/0.29.0) target/artifacts/bar target/artifacts/foo ``` Signed-off-by: Jesse Szwedko --- Cargo.lock | 1 + vdev/Cargo.toml | 1 + vdev/src/commands/release/github.rs | 40 +++++++++++++++++++---------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95d22ef06385c..089fbf49c9db2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9277,6 +9277,7 @@ dependencies = [ "confy", "directories 5.0.0", "dunce", + "glob", "hashlink", "hex", "indicatif", diff --git a/vdev/Cargo.toml b/vdev/Cargo.toml index bf673fb60c993..1a7be388d523a 100644 --- a/vdev/Cargo.toml +++ b/vdev/Cargo.toml @@ -19,6 +19,7 @@ confy = "0.5.1" directories = "5.0.0" # remove this when stabilized https://doc.rust-lang.org/stable/std/path/fn.absolute.html dunce = "1.0.3" +glob = { version = "0.3.1", default-features = false } hashlink = { version = "0.8.1", features = ["serde_impl"] } hex = "0.4.3" indicatif = { version = "0.17.3", features = ["improved_unicode"] } diff --git a/vdev/src/commands/release/github.rs b/vdev/src/commands/release/github.rs index 6816d2bbce870..c529b80635c46 100644 --- a/vdev/src/commands/release/github.rs +++ b/vdev/src/commands/release/github.rs @@ -1,6 +1,7 @@ use crate::app::CommandExt as _; use crate::util; -use anyhow::{Ok, Result}; +use anyhow::{anyhow, Ok, Result}; +use glob::glob; use std::process::Command; /// Uploads target/artifacts to GitHub releases @@ -10,21 +11,34 @@ pub struct Cli {} impl Cli { pub fn exec(self) -> Result<()> { + let artifacts = glob("target/artifacts/*") + .expect("failed to read glob pattern") + .collect::, _>>() + .map_err(|e| anyhow!("failed to read path: {}", e))? + .into_iter() + .map(|p| p.into_os_string().into_string()) + .collect::, _>>() + .map_err(|e| anyhow!("failed to turn path into string: {:?}", e))?; + let version = util::get_version()?; let mut command = Command::new("gh"); command.in_repo(); - command.args([ - "release", - "--repo", - "vectordotdev/vector", - "create", - &format!("v{version}"), - "--title", - &format!("v{version}"), - "--notes", - &format!("[View release notes](https://vector.dev/releases/{version})"), - "target/artifacts/*", - ]); + command.args( + [ + "release", + "--repo", + "vectordotdev/vector", + "create", + &format!("v{version}"), + "--title", + &format!("v{version}"), + "--notes", + &format!("[View release notes](https://vector.dev/releases/{version})"), + ] + .map(String::from) + .into_iter() + .chain(artifacts), + ); command.check_run()?; Ok(()) }