Skip to content

Commit

Permalink
Merge pull request #409 from hendrikmaus/release-operator-align-outpu…
Browse files Browse the repository at this point in the history
…t-names

fix: align output names
  • Loading branch information
hannobraun authored Mar 29, 2022
2 parents 72459d2 + ad2b233 commit 267d7f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion release-operator/src/github.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::release::Outputs;
use cmd_lib::run_fun;
use serde::Deserialize;

Expand Down Expand Up @@ -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}");
}
Expand Down
21 changes: 18 additions & 3 deletions release-operator/src/release.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
use crate::{Actions, GitHub};
use regex::Regex;
use std::fmt::{Display, Formatter};

pub struct Release {
sha: String,
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 }
Expand Down Expand Up @@ -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(())
}
}

0 comments on commit 267d7f3

Please sign in to comment.