Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Add stdout and stderr outputs #206

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
30 changes: 27 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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> {
Expand All @@ -30,7 +48,13 @@ async function main(): Promise<void> {
const actionInput = input.get();

try {
await run(actionInput);
const { stdout, stderr } = await run(actionInput);
core.startGroup("setting outputs");
console.log("stdout: ", stdout.slice(0, 50), "...");
core.setOutput("stdout", stdout);
console.log("stderr: ", stderr.slice(0, 50), "...");
core.setOutput("stderr", stderr);
core.endGroup();
} catch (error) {
core.setFailed((<Error>error).message);
}
Expand Down