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

Show github annotation on specific errors. #106

Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ async fn push_new_release(
StatusCode::UNAUTHORIZED => {
let body = &release_metadata_post_response.bytes().await?;
let message = serde_json::from_slice::<String>(body)?;

return Err(Error::Unauthorized(message))?;
}
_ => {
Expand Down
14 changes: 14 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -15,4 +16,17 @@ impl Error {
Self::Unauthorized(_) | Self::Conflict { .. } => false,
}
}

/// Output a Github Actions annotation command if desired.
// 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 {
Error::Unauthorized(message) => {
println!("::error title=Unauthorized::{message}")
}
Error::Conflict { .. } => println!("::error title=Conflict::{self}"),
}
}
}
}
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ async fn main() -> color_eyre::Result<std::process::ExitCode> {

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::<Error>() {
known_error.maybe_github_actions_annotation()
}
Err(error)
}
}
}

#[derive(Debug, Clone, Copy, clap::ValueEnum, serde::Serialize, serde::Deserialize)]
Expand Down
Loading