Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add stdout/err to plugin test action #331

Open
wants to merge 1 commit 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
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"