Skip to content

Commit

Permalink
fix: add stdout/err to plugin test action
Browse files Browse the repository at this point in the history
fixes Set outputs for plugin-test action asdf-vm#330
  • Loading branch information
kameshsampath committed Jun 28, 2021
1 parent b797cb8 commit 13294fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
22 changes: 21 additions & 1 deletion lib/plugin-test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import * as core from "@actions/core";
import * as exec from "@actions/exec";
import { setupAsdf } from "../setup";

const stdoutLines: string[] = [];
const stderrLines: string[] = [];
const debugLines: string[] = [];

export async function pluginTest(): Promise<void> {
await setupAsdf();
const command = core.getInput("command", { required: true });
Expand All @@ -11,6 +15,18 @@ export async function pluginTest(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
process.env.GITHUB_REPOSITORY!.split("/")[1]
).replace("asdf-", "");
const options: exec.ExecOptions = {};
options.listeners = {
stdline: (line: string) => {
stdoutLines.push(line.replace(/(?:\r\n|\r|\n)/g, ""));
},
errline: (line: string) => {
stderrLines.push(line.replace(/(?:\r\n|\r|\n)/g, ""));
},
debug: (line: string) => {
debugLines.push(line.replace(/(?:\r\n|\r|\n)/g, ""));
},
};
const giturl =
core.getInput("giturl", { required: false }) ||
`https://github.com/${process.env.GITHUB_REPOSITORY}`;
Expand All @@ -26,13 +42,17 @@ export async function pluginTest(): Promise<void> {
"--asdf-plugin-gitref",
gitref,
command,
]);
],
options);
}

export async function pluginTestAll(): Promise<void> {
const githubToken = core.getInput("github_token", { required: false });
core.exportVariable("GITHUB_API_TOKEN", githubToken);
core.startGroup("Test plugin");
await pluginTest();
core.setOutput("stdout", { lines: stdoutLines });
core.setOutput("stderr", { lines: stderrLines });
core.setOutput("debug", { lines: debugLines });
core.endGroup();
}
14 changes: 10 additions & 4 deletions plugin-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ runs:
main: main.js
inputs:
command:
description:
Command used to test your plugin tool. Something with --version or --help
description: Command used to test your plugin tool. Something with --version or --help
required: true
plugin:
description: Plugin name to use. Defaults to repository name without asdf-
Expand All @@ -20,8 +19,7 @@ inputs:
description: Plugin repository. Defaults to current github repository
required: false
gitref:
description:
Branch or commit from repository to test. Defaults to current commit.
description: Branch or commit from repository to test. Defaults to current commit.
required: false
asdf_branch:
description: asdf branch to clone
Expand All @@ -31,3 +29,11 @@ inputs:
description: Token used to avoid rate limit when asdf calls the GitHub API
required: false
default: ${{ github.token }}

outputs:
stdout:
description: "An array of stdout lines the test command"
stderr:
description: "An array of stderr of the test command"
debug:
description: "An array of debug lines of the test command"

0 comments on commit 13294fb

Please sign in to comment.