From 03012abe8b8528f56cfeb043814775cb684d0e52 Mon Sep 17 00:00:00 2001
From: Alexander Lyon <arlyon@me.com>
Date: Fri, 4 Mar 2022 09:40:16 +0000
Subject: [PATCH 1/2] Add stdout and stderr outputs

---
 action.yml  |  5 +++++
 src/main.ts | 26 +++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/action.yml b/action.yml
index 599fbce..d86b0b7 100644
--- a/action.yml
+++ b/action.yml
@@ -17,6 +17,11 @@ inputs:
   use-cross:
     description: Use cross instead of cargo
     default: false
+outputs:
+  stdout:
+    description: Standard out of the program
+  stderr:
+    description: Standard err of the program
 
 runs:
   using: 'node12'
diff --git a/src/main.ts b/src/main.ts
index 0e68de4..0453e9f 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -5,7 +5,9 @@ import * as core from "@actions/core";
 import * as input from "./input";
 import { Cargo, Cross } from "@actions-rs/core";
 
-export async function run(actionInput: input.Input): Promise<void> {
+export async function run(
+    actionInput: input.Input
+): Promise<{ code: number; stdout: string; stderr: string }> {
     let program;
     if (actionInput.useCross) {
         program = await Cross.getOrInstall();
@@ -20,7 +22,23 @@ export async function run(actionInput: input.Input): Promise<void> {
     args.push(actionInput.command);
     args = args.concat(actionInput.args);
 
-    await program.call(args);
+    let stdout = "";
+    let stderr = "";
+
+    const options = {
+        listeners: {
+            stdout: (data: Buffer) => {
+                stdout += data.toString();
+            },
+            stderr: (data: Buffer) => {
+                stderr += data.toString();
+            },
+        },
+    };
+
+    const code = await program.call(args, options);
+
+    return { code, stdout, stderr };
 }
 
 async function main(): Promise<void> {
@@ -30,7 +48,9 @@ async function main(): Promise<void> {
     const actionInput = input.get();
 
     try {
-        await run(actionInput);
+        const { stdout, stderr } = await run(actionInput);
+        core.setOutput("stdout", stdout);
+        core.setOutput("stdout", stderr);
     } catch (error) {
         core.setFailed((<Error>error).message);
     }

From 1f50d6efcaf775922f5bdf0309af25fb5373a6f3 Mon Sep 17 00:00:00 2001
From: Alexander Lyon <arlyon@me.com>
Date: Fri, 25 Mar 2022 09:59:22 +0000
Subject: [PATCH 2/2] Add group and print the outputs

---
 src/main.ts | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/main.ts b/src/main.ts
index 0453e9f..244164c 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -49,8 +49,12 @@ async function main(): Promise<void> {
 
     try {
         const { stdout, stderr } = await run(actionInput);
+        core.startGroup("setting outputs");
+        console.log("stdout: ", stdout.slice(0, 50), "...");
         core.setOutput("stdout", stdout);
-        core.setOutput("stdout", stderr);
+        console.log("stderr: ", stderr.slice(0, 50), "...");
+        core.setOutput("stderr", stderr);
+        core.endGroup();
     } catch (error) {
         core.setFailed((<Error>error).message);
     }