From ab6335bf03a357f6787da58d502c1e270031e6b9 Mon Sep 17 00:00:00 2001 From: Hendrik Maus Date: Tue, 29 Mar 2022 09:53:25 +0200 Subject: [PATCH 1/2] fix: align output names when no release was detcetd, the output name was incorrect due to the usage of a stringly typed identifier. i implemented the outputs as an enum to overcome the issue. --- release-operator/src/github.rs | 3 ++- release-operator/src/release.rs | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/release-operator/src/github.rs b/release-operator/src/github.rs index f7f4c612d..7ad8c6fe2 100644 --- a/release-operator/src/github.rs +++ b/release-operator/src/github.rs @@ -1,5 +1,6 @@ use cmd_lib::run_fun; use serde::Deserialize; +use crate::release::Outputs; #[derive(Deserialize, Debug, Clone)] pub struct PullRequest { @@ -68,7 +69,7 @@ pub struct Actions; impl Actions { // Set an "output" in GitHub Actions - pub fn set_output(key: &str, value: &str) { + pub fn set_output(key: Outputs, value: &str) { log::debug!("setting output name={key} value={value}"); println!("::set-output name={key}::{value}"); } diff --git a/release-operator/src/release.rs b/release-operator/src/release.rs index b72f6d22d..cc8261860 100644 --- a/release-operator/src/release.rs +++ b/release-operator/src/release.rs @@ -1,3 +1,4 @@ +use std::fmt::{Display, Formatter}; use crate::{Actions, GitHub}; use regex::Regex; @@ -6,6 +7,20 @@ pub struct Release { label: String, } +pub enum Outputs { + ReleaseDetected, + TagName, +} + +impl Display for Outputs { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match &self { + Outputs::ReleaseDetected => write!(f, "release-detected"), + Outputs::TagName => write!(f, "tag-name"), + } + } +} + impl Release { pub fn new(sha: String, label: String) -> Self { Self { sha, label } @@ -37,14 +52,14 @@ impl Release { fn hit(&self, tag: &str) -> anyhow::Result<()> { log::info!("detected release of {tag}"); - Actions::set_output("release-detected", "true"); - Actions::set_output("tag-name", tag); + Actions::set_output(Outputs::ReleaseDetected, "true"); + Actions::set_output(Outputs::TagName, tag); Ok(()) } fn miss(&self) -> anyhow::Result<()> { log::info!("no release detected"); - Actions::set_output("release-created", "false"); + Actions::set_output(Outputs::ReleaseDetected, "false"); Ok(()) } } From ad2b233b8e7ad4198f44e6901e98530084c649a1 Mon Sep 17 00:00:00 2001 From: Hendrik Maus Date: Tue, 29 Mar 2022 09:55:23 +0200 Subject: [PATCH 2/2] refactor: run cargo fmt --- release-operator/src/github.rs | 2 +- release-operator/src/release.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/release-operator/src/github.rs b/release-operator/src/github.rs index 7ad8c6fe2..55c52e6d0 100644 --- a/release-operator/src/github.rs +++ b/release-operator/src/github.rs @@ -1,6 +1,6 @@ +use crate::release::Outputs; use cmd_lib::run_fun; use serde::Deserialize; -use crate::release::Outputs; #[derive(Deserialize, Debug, Clone)] pub struct PullRequest { diff --git a/release-operator/src/release.rs b/release-operator/src/release.rs index cc8261860..adf66aed4 100644 --- a/release-operator/src/release.rs +++ b/release-operator/src/release.rs @@ -1,6 +1,6 @@ -use std::fmt::{Display, Formatter}; use crate::{Actions, GitHub}; use regex::Regex; +use std::fmt::{Display, Formatter}; pub struct Release { sha: String,