From b6efc1c21d5297e24d4849b7069965b98fdd55c3 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 09:45:59 -0800 Subject: [PATCH 01/10] Add some test stuff --- src/cli/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index fe1f06f..7712b45 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -501,6 +501,14 @@ async fn push_new_release( error_if_release_conflicts: bool, include_output_paths: bool, ) -> color_eyre::Result<()> { + // FIXME(ANA): I am testing if this works and will remove this + if std::env::var("GITHUB_ACTIONS").is_ok() { + // Output a Github Actions annotation + println!("::error title=Unauthorized::Boogaloo"); + } + return Ok(()); + // Finished testing + let span = tracing::Span::current(); span.record("upload_name", tracing::field::display(upload_name.clone())); @@ -734,6 +742,12 @@ async fn push_new_release( StatusCode::UNAUTHORIZED => { let body = &release_metadata_post_response.bytes().await?; let message = serde_json::from_slice::(body)?; + + if std::env::var("GITHUB_ACTIONS").is_ok() { + // Output a Github Actions annotation + println!("::error title=Unauthorized::{message}"); + } + return Err(Error::Unauthorized(message))?; } _ => { From 8fe94daf683916ea3f4f0ab1bb0a3a28b320eb3a Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 10:09:15 -0800 Subject: [PATCH 02/10] Allow stuff --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 9596d35..7b294dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![allow(unreachable_code, unused_variables)] + use std::{fmt::Display, io::IsTerminal}; use clap::Parser; From 6be1761ebb7f5e124965234fa50cc650a1b8f358 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 10:16:43 -0800 Subject: [PATCH 03/10] Remove testing code --- src/cli/mod.rs | 8 -------- src/main.rs | 2 -- 2 files changed, 10 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 7712b45..d4dc023 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -501,14 +501,6 @@ async fn push_new_release( error_if_release_conflicts: bool, include_output_paths: bool, ) -> color_eyre::Result<()> { - // FIXME(ANA): I am testing if this works and will remove this - if std::env::var("GITHUB_ACTIONS").is_ok() { - // Output a Github Actions annotation - println!("::error title=Unauthorized::Boogaloo"); - } - return Ok(()); - // Finished testing - let span = tracing::Span::current(); span.record("upload_name", tracing::field::display(upload_name.clone())); diff --git a/src/main.rs b/src/main.rs index 7b294dd..9596d35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -#![allow(unreachable_code, unused_variables)] - use std::{fmt::Display, io::IsTerminal}; use clap::Parser; From e2a221aa1142109e32dce871cdb54530c611ba10 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 10:22:28 -0800 Subject: [PATCH 04/10] Add annotation for Conflict during error path as well. --- src/cli/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index d4dc023..1bfa17d 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -723,6 +723,12 @@ async fn push_new_release( revision = release_metadata.revision ); if error_if_release_conflicts { + + if std::env::var("GITHUB_ACTIONS").is_ok() { + // Output a Github Actions annotation + println!("::error title=Conflict::{upload_name}/{rolling_prefix_or_tag} already exists"); + } + return Err(Error::Conflict { upload_name, rolling_prefix_or_tag, From 8f02f1ee91a71c3f5f4fa183ae442f85f8d12149 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 10:33:50 -0800 Subject: [PATCH 05/10] fmt --- src/cli/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 1bfa17d..bc52907 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -723,7 +723,6 @@ async fn push_new_release( revision = release_metadata.revision ); if error_if_release_conflicts { - if std::env::var("GITHUB_ACTIONS").is_ok() { // Output a Github Actions annotation println!("::error title=Conflict::{upload_name}/{rolling_prefix_or_tag} already exists"); From 6b13c5fe3e012fcb2fd22edcca7dcaf8278514ed Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 12:05:41 -0800 Subject: [PATCH 06/10] Try a new way, with testing fixtures --- src/cli/mod.rs | 2 ++ src/error.rs | 8 ++++++++ src/main.rs | 12 +++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index bc52907..61a1e3b 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -260,6 +260,8 @@ impl FlakeHubPushCli { skip_all, )] pub(crate) async fn execute(self) -> color_eyre::Result { + return Err(Error::Unauthorized("Bean salad\nLook a newline".into()))?; + tracing::trace!(?self, "Executing"); let Self { host, diff --git a/src/error.rs b/src/error.rs index d3e4705..2eaa051 100644 --- a/src/error.rs +++ b/src/error.rs @@ -15,4 +15,12 @@ impl Error { Self::Unauthorized(_) | Self::Conflict { .. } => false, } } + pub(crate) fn maybe_github_actions_annotation(&self) { + if std::env::var("GITHUB_ACTIONS").is_ok() { + match self { + Error::Unauthorized(message) => println!("::error title=Unauthorized::< println!("::error title=Conflict::< color_eyre::Result { let cli = cli::FlakeHubPushCli::parse(); cli.instrumentation.setup()?; - cli.execute().await + + match cli.execute().await { + Ok(exit) => Ok(exit), + Err(error) => { + if let Some(known_error) = error.downcast_ref::() { + known_error.maybe_github_actions_annotation() + } + Err(error) + } + } } #[derive(Debug, Clone, Copy, clap::ValueEnum, serde::Serialize, serde::Deserialize)] From 2418cccee65cf451bce397a406cf6ad9c9296461 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 12:07:55 -0800 Subject: [PATCH 07/10] Fmt --- src/error.rs | 4 +++- src/main.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 2eaa051..7586864 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,7 +18,9 @@ impl Error { pub(crate) fn maybe_github_actions_annotation(&self) { if std::env::var("GITHUB_ACTIONS").is_ok() { match self { - Error::Unauthorized(message) => println!("::error title=Unauthorized::< { + println!("::error title=Unauthorized::< println!("::error title=Conflict::< color_eyre::Result { let cli = cli::FlakeHubPushCli::parse(); cli.instrumentation.setup()?; - + match cli.execute().await { Ok(exit) => Ok(exit), Err(error) => { From b1ad522a97d7644bb5f72b298816537f910e2804 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 12:13:27 -0800 Subject: [PATCH 08/10] No multiline, sad. --- src/error.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 7586864..4bb2aa1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,6 @@ #[derive(Debug, thiserror::Error)] pub(crate) enum Error { + /// Unauthorized, with a single line message detailing the nature of the problem. #[error("Unauthorized: {0}")] Unauthorized(String), #[error("{upload_name}/{rolling_prefix_or_tag} already exists")] @@ -15,13 +16,16 @@ impl Error { Self::Unauthorized(_) | Self::Conflict { .. } => false, } } + + /// Output a Github Actions annotation command if desired. + // Note: These may only be one line! pub(crate) fn maybe_github_actions_annotation(&self) { if std::env::var("GITHUB_ACTIONS").is_ok() { match self { Error::Unauthorized(message) => { - println!("::error title=Unauthorized::< println!("::error title=Conflict::< println!("::error title=Conflict::{self}"), } } } From a3137104ef782058c463a367e3d7e4dc19aa3299 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 12:20:19 -0800 Subject: [PATCH 09/10] Remove testing code again --- src/cli/mod.rs | 2 -- src/error.rs | 2 +- src/main.rs | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 61a1e3b..bc52907 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -260,8 +260,6 @@ impl FlakeHubPushCli { skip_all, )] pub(crate) async fn execute(self) -> color_eyre::Result { - return Err(Error::Unauthorized("Bean salad\nLook a newline".into()))?; - tracing::trace!(?self, "Executing"); let Self { host, diff --git a/src/error.rs b/src/error.rs index 4bb2aa1..d094fc9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,7 +18,7 @@ impl Error { } /// Output a Github Actions annotation command if desired. - // Note: These may only be one line! + // Note: These may only be one line! Any further lines will not be printed! pub(crate) fn maybe_github_actions_annotation(&self) { if std::env::var("GITHUB_ACTIONS").is_ok() { match self { diff --git a/src/main.rs b/src/main.rs index 0f7b6bc..918b824 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -#![allow(unused_variables, dead_code, unreachable_code)] use std::{fmt::Display, io::IsTerminal}; use clap::Parser; From 261f5c16d79f71a97364a9e34f2ced69191e0724 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 9 Feb 2024 12:21:59 -0800 Subject: [PATCH 10/10] Remove accidental double errors --- src/cli/mod.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index bc52907..ee1c3c2 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -723,11 +723,6 @@ async fn push_new_release( revision = release_metadata.revision ); if error_if_release_conflicts { - if std::env::var("GITHUB_ACTIONS").is_ok() { - // Output a Github Actions annotation - println!("::error title=Conflict::{upload_name}/{rolling_prefix_or_tag} already exists"); - } - return Err(Error::Conflict { upload_name, rolling_prefix_or_tag, @@ -740,11 +735,6 @@ async fn push_new_release( let body = &release_metadata_post_response.bytes().await?; let message = serde_json::from_slice::(body)?; - if std::env::var("GITHUB_ACTIONS").is_ok() { - // Output a Github Actions annotation - println!("::error title=Unauthorized::{message}"); - } - return Err(Error::Unauthorized(message))?; } _ => {