Skip to content

Commit

Permalink
Uploading plugins now yields the proper exit code in case of failure …
Browse files Browse the repository at this point in the history
…which is required for working in ci/cd pipelines
  • Loading branch information
ko1N committed Apr 2, 2024
1 parent 95a6cd9 commit 0b8ffb5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ which = "6.0"
crates_io_api = { version = "0.9.0", default-features = false, features = ["rustls"] }

# memflow-registry
#memflow-registry-client = { path = "../memflow-registry/memflow-registry-client" }
memflow-registry-client = { git = "https://github.com/memflow/memflow-registry" }
memflow-registry-client = { path = "../memflow-registry/memflow-registry-client" }
#memflow-registry-client = { git = "https://github.com/memflow/memflow-registry" }
sha256 = "1.5"

# source builds
Expand Down
62 changes: 38 additions & 24 deletions src/commands/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{path::Path, process::exit};

use clap::{Arg, ArgAction, ArgMatches, Command};
use memflow_registry_client::shared::SignatureGenerator;
use memflow_registry_client::shared::{structs::PluginUploadResponse, SignatureGenerator};

use crate::{
error::{Error, Result},
Expand Down Expand Up @@ -71,21 +71,24 @@ pub async fn handle(matches: &ArgMatches) -> Result<()> {
}
};

let mut success = true;
let mut exit_code = 0;

if !file {
// try to find the plugin first, then upload it to the registry
for plugin_uri in plugin_uris_or_files.iter() {
match util::find_local_plugin(plugin_uri).await {
Ok(plugin) => {
success = success
&& upload_plugin_file(
registry,
token.map(String::as_str),
priv_key_file,
&plugin.plugin_file_name,
)
.await
.is_ok();
if upload_plugin_file(
registry,
token.map(String::as_str),
priv_key_file,
&plugin.plugin_file_name,
)
.await
.is_err()
{
exit_code = 1;
}
}
Err(err) => {
println!(
Expand All @@ -100,23 +103,24 @@ pub async fn handle(matches: &ArgMatches) -> Result<()> {
} else {
for file_name in plugin_uris_or_files.iter() {
// upload a file directly
success = success
&& upload_plugin_file(
registry,
token.map(String::as_str),
priv_key_file,
file_name,
)
.await
.is_ok();
if upload_plugin_file(
registry,
token.map(String::as_str),
priv_key_file,
file_name,
)
.await
.is_err()
{
exit_code = 1;
}
}
}

// TODO: ideally we differentiate between hard- & soft errors on the backend site instead of returning an error code for a duplicated entry.
if success {
if exit_code == 0 {
Ok(())
} else {
exit(1)
exit(exit_code)
}
}

Expand All @@ -130,14 +134,24 @@ async fn upload_plugin_file<P: AsRef<Path>>(
let mut generator = SignatureGenerator::new(priv_key_file)?;
match memflow_registry_client::upload(registry, token, file_name.as_ref(), &mut generator).await
{
Ok(_) => {
Ok(PluginUploadResponse::Added) => {
println!(
"{} Uploaded plugin {:?}",
console::style("[=]").bold().dim().green(),
file_name.as_ref()
);
Ok(())
}
Ok(PluginUploadResponse::AlreadyExists) => {
println!(
"{} Plugin {:?} already exists with the same digest",
console::style("[-]").bold().dim().red(),
file_name.as_ref(),
);
Err(Error::AlreadyExists(
"plugin with the same digest was already added".to_owned(),
))
}
Err(msg) => {
println!(
"{} Unable to upload plugin {:?}: {}",
Expand Down

0 comments on commit 0b8ffb5

Please sign in to comment.