From 4b5866e064435dd2968e8d12a39b8473fdd83161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Tue, 17 Sep 2024 17:42:08 +0200 Subject: [PATCH] Try to fix github action --- action.yaml | 12 ++++++------ src/main.rs | 30 ++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/action.yaml b/action.yaml index 583dc2d..853c672 100644 --- a/action.yaml +++ b/action.yaml @@ -1,16 +1,16 @@ -name: 'pear-reviewer' -description: 'Run pear-reviewer' +name: pear-reviewer +description: Run pear-reviewer runs: - using: "composite" + using: composite steps: - name: Check out code uses: actions/checkout@v4 - name: Run pear-reviewer id: run-pear-reviewer - uses: docker://ghcr.io/sapcc/pear-reviewer:latest - run: - pear-reviewer > $GITHUB_OUTPUT + uses: docker://ghcr.io/sapcc/pear-reviewer:edge + with: + args: repo - name: Find Comment uses: peter-evans/find-comment@v3 diff --git a/src/main.rs b/src/main.rs index fd0e7e9..d7f2670 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,8 +21,10 @@ mod helm_config; mod remote; mod repo; -use std::str; +use std::fs::File; +use std::io::Write; use std::sync::LazyLock; +use std::{env, str}; use anyhow::{anyhow, Context}; use api_clients::{ClientSet, RealClient}; @@ -186,14 +188,26 @@ fn find_values_yaml( Ok(changes) } +fn println_or_redirect(line: String) -> Result<(), anyhow::Error> { + if env::var("GITHUB_ACTIONS").is_ok() { + let path = env::var("GITHUB_OUTPUT").context("cannot find GITHUB_OUTPUT")?; + let mut file = File::create(path.clone()).with_context(|| format!("cannot write to $GITHUB_OUTPUT {path}"))?; + file.write_all((line + "\n").as_bytes())?; + } else { + println!("{line}"); + } + + Ok(()) +} + fn print_changes(repo_changeset: &[RepoChangeset]) -> Result<(), anyhow::Error> { for change in repo_changeset { - println!( + println_or_redirect(format!( "Name {} from {} moved from {} to {}", - change.name, change.remote.original, change.base_commit, change.head_commit - ); - println!("| Commit link | Pull Request link | Approvals | Reviewer's verdict |"); - println!("|-------------|-------------------|-----------|--------------------|"); + change.name, change.remote.original, change.base_commit, change.head_commit, + ))?; + println_or_redirect("| Commit link | Pull Request link | Approvals | Reviewer's verdict |".to_string())?; + println_or_redirect("|-------------|-------------------|-----------|--------------------|".to_string())?; for commit_change in &change.changes { let mut commit_links: Vec = vec![]; for commit in &commit_change.commits { @@ -208,7 +222,7 @@ fn print_changes(repo_changeset: &[RepoChangeset]) -> Result<(), any } let pr_link = commit_change.pr_link.clone(); - println!( + println_or_redirect(format!( "| {} | {} | {} | |", commit_links.join(" ,
"), match pr_link { @@ -226,7 +240,7 @@ fn print_changes(repo_changeset: &[RepoChangeset]) -> Result<(), any None => String::new(), }, commit_change.approvals.join(", "), - ); + ))?; } }