diff --git a/tools/release-operator/src/github.rs b/tools/release-operator/src/github.rs index 7d8dbcbb2..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; @@ -69,8 +72,17 @@ 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<()> { + 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(()) } } 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(()) } }