mirror of
https://github.com/actions-rs/cargo.git
synced 2024-11-14 21:46:34 +02:00
Add stdout and stderr outputs
This commit is contained in:
parent
9e120dd99b
commit
03012abe8b
2 changed files with 28 additions and 3 deletions
|
@ -17,6 +17,11 @@ inputs:
|
||||||
use-cross:
|
use-cross:
|
||||||
description: Use cross instead of cargo
|
description: Use cross instead of cargo
|
||||||
default: false
|
default: false
|
||||||
|
outputs:
|
||||||
|
stdout:
|
||||||
|
description: Standard out of the program
|
||||||
|
stderr:
|
||||||
|
description: Standard err of the program
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
|
|
26
src/main.ts
26
src/main.ts
|
@ -5,7 +5,9 @@ import * as core from "@actions/core";
|
||||||
import * as input from "./input";
|
import * as input from "./input";
|
||||||
import { Cargo, Cross } from "@actions-rs/core";
|
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;
|
let program;
|
||||||
if (actionInput.useCross) {
|
if (actionInput.useCross) {
|
||||||
program = await Cross.getOrInstall();
|
program = await Cross.getOrInstall();
|
||||||
|
@ -20,7 +22,23 @@ export async function run(actionInput: input.Input): Promise<void> {
|
||||||
args.push(actionInput.command);
|
args.push(actionInput.command);
|
||||||
args = args.concat(actionInput.args);
|
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> {
|
async function main(): Promise<void> {
|
||||||
|
@ -30,7 +48,9 @@ async function main(): Promise<void> {
|
||||||
const actionInput = input.get();
|
const actionInput = input.get();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await run(actionInput);
|
const { stdout, stderr } = await run(actionInput);
|
||||||
|
core.setOutput("stdout", stdout);
|
||||||
|
core.setOutput("stdout", stderr);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed((<Error>error).message);
|
core.setFailed((<Error>error).message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue