From 6988b27f15e12dd6df0813f26d4d7a113c5df274 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 14 Nov 2022 16:02:41 +0100 Subject: [PATCH 1/2] Return `Result` from `set_output` --- tools/release-operator/src/github.rs | 3 ++- tools/release-operator/src/release.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/release-operator/src/github.rs b/tools/release-operator/src/github.rs index 7d8dbcbb2..b3fed1d13 100644 --- a/tools/release-operator/src/github.rs +++ b/tools/release-operator/src/github.rs @@ -69,8 +69,9 @@ pub struct Actions; impl Actions { // Set an "output" in GitHub Actions - pub fn set_output(key: Outputs, value: &str) { + pub fn set_output(key: Outputs, value: &str) -> anyhow::Result<()> { log::debug!("setting output name={key} value={value}"); println!("\"{key}={value}\" >> $GITHUB_OUTPUT"); + Ok(()) } } diff --git a/tools/release-operator/src/release.rs b/tools/release-operator/src/release.rs index 248189803..143c8bfb9 100644 --- a/tools/release-operator/src/release.rs +++ b/tools/release-operator/src/release.rs @@ -62,15 +62,15 @@ impl Release { let tag = format!("v{tag}"); log::info!("detected release of {tag}"); - Actions::set_output(Outputs::ReleaseDetected, "true"); - Actions::set_output(Outputs::TagName, &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(Outputs::ReleaseDetected, "false"); + Actions::set_output(Outputs::ReleaseDetected, "false")?; Ok(()) } } From 280b420a317d0356f25ab1e984be2863774dac28 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 14 Nov 2022 16:07:37 +0100 Subject: [PATCH 2/2] Attempt setting job output correctly --- tools/release-operator/src/github.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/release-operator/src/github.rs b/tools/release-operator/src/github.rs index b3fed1d13..5125e6a7d 100644 --- a/tools/release-operator/src/github.rs +++ b/tools/release-operator/src/github.rs @@ -1,4 +1,7 @@ +use std::{env, fs::File, io::Write}; + use crate::release::Outputs; +use anyhow::anyhow; use cmd_lib::run_fun; use serde::Deserialize; @@ -70,8 +73,16 @@ pub struct Actions; impl Actions { // Set an "output" in GitHub Actions pub fn set_output(key: Outputs, value: &str) -> anyhow::Result<()> { + const GITHUB_OUTPUT: &str = "GITHUB_OUTPUT"; + + let output = env::var_os(GITHUB_OUTPUT).ok_or_else(|| { + anyhow!("Could not read environment variable {GITHUB_OUTPUT}") + })?; + let mut output = File::open(output)?; + log::debug!("setting output name={key} value={value}"); - println!("\"{key}={value}\" >> $GITHUB_OUTPUT"); + writeln!(output, "{key}={value}")?; + Ok(()) } }