Skip to content

Latest commit

 

History

History
347 lines (266 loc) · 8.49 KB

run-result.md

File metadata and controls

347 lines (266 loc) · 8.49 KB

Run result

run() method of every run target returns a run result object (asyncFn target returns a Promise of run result).

const result1 = syncTarget.run(RunOptions.create());
const result2 = await asyncTarget.run(RunOptions.create());

Read GitHub documentation to learn more about possible action commands (which are parsed by the library and are available in result object).

🔹 commands.outputs

Object with action outputs (parsed both from stdout and from $GITHUB_OUTPUT file).

Example

Output set in JS action:

const core = require('@actions/core');
core.setOutput('out1', 'val1');

Output set in bash script (Docker action):

echo "out1=val1" >> "$GITHUB_OUTPUT"

Read outputs:

result.commands.outputs // {out1: 'val1'}

🔹 commands.errors

Array of "error" commands parsed from stdout.

Example

Error added in JS action:

const core = require('@actions/core');
core.error('msg');

Error added in bash script (Docker action):

echo "::error::msg"

Read errors:

result.commands.errors // ["msg"]

🔹 commands.warnings

Array of "warning" commands parsed from stdout.

Example

Warning added in JS action:

const core = require('@actions/core');
core.warning('msg');

Warning added in bash script (Docker action):

echo "::warning::msg"

Read warnings:

result.commands.warnings // ["msg"]

🔹 commands.notices

Array of "notice" commands parsed from stdout.

Example

Notice added in JS action:

const core = require('@actions/core');
core.notice('msg');

Notice added in bash script (Docker action):

echo "::notice::msg"

Read notices:

result.commands.notices // ["msg"]

🔹 commands.debugs

Array of "debug" commands parsed from stdout.

Example

Debug added in JS action:

const core = require('@actions/core');
core.debug('msg');

Debug added in bash script (Docker action):

echo "::debug::msg"

Read debug commands:

result.commands.debugs // ["msg"]

🔹 commands.secrets

Array of "add-mask" commands parsed from stdout.

Example

Secret added in JS action:

const core = require('@actions/core');
core.setSecret('password');

Secret added in bash script (Docker action):

echo "::add-mask::password"

Read secrets:

result.commands.secrets // ["password"]

🔹 commands.savedState

Object with saved state values (parsed both from stdout and from $GITHUB_STATE file)

Example

State saved in JS action:

const core = require('@actions/core');
core.saveState('stateName', 'value');

State saved in bash script (Docker action):

echo "stateName=value" >> $GITHUB_STATE

Read saved state names and values:

result.commands.savedState // {stateName: 'value'}

🔹 commands.echo

Echo command parsed from stdout ('on'|'off'|undefined).

Example

Echo set in JS action:

const core = require('@actions/core');
core.setCommandEcho(true);

Echo set in bash script (Docker action):

echo "::echo::on"

Read echo command value:

result.commands.echo // 'on'

🔹 commands.addedPaths

Array of "add path" commands (parsed both from stdout and from $GITHUB_PATH file).

Example

Add path in JS action:

const core = require('@actions/core');
core.addPath('some/path');

Add path in bash script (Docker action):

echo "some/path" >> "$GITHUB_PATH"

Read added path:

result.commands.addedPaths // ['some/path']

🔹 commands.exportedVars

Object with variables exported to workflow env (parsed both from stdout and from $GITHUB_ENV file).

Example

Export variable in JS action:

const core = require('@actions/core');
core.exportVariable('varName', 'varValue');

Export variable in bash script (Docker action):

# For multi-line values you need to use delimiters
echo "varName=varValue" >> "$GITHUB_PATH"

Read exported variables:

result.commands.exportedVars // {varName: 'varValue'}

🔹 exitCode

Exit code (number|undefined)

  • of a child process (for JS file and Docker targets)
  • code set to process.exitCode (for a single function target).

🔹 stdout

Data (string|undefined) intercepted from stdout of a tested action.

🔹 stderr

Data (string|undefined) intercepted from stderr of a tested action.

🔹 error

Error|undefined happened in a test.

  • Error from spawnSync result (for JS file and Docker targets)
  • Error thrown in syncFn and asyncFn targets or returned Promise rejected reason for asyncFn target.

🔹 durationMs

Duration of target execution in milliseconds (number). For asyncFn target counts as time passed from the moment of calling a function to the moment when Promise fulfills.

🔹 isTimedOut

true if a target execution took more time than timeout specified in timeoutMs property of options; false otherwise.

🔹 isSuccess

true if exitCode is 0 (or not set in function) and error is undefined; false otherwise.

🔹 tempDirPath

Path of a temp directory (accessible under RUNNER_TEMP inside tested action) that is still available after the action run. By default, it's undefined because faked dirs are deleted after run. For Docker target it contains a path of the host directory.

Can have value in case of:

  1. You asked not to delete faked temp dir after run:
    options.setFakeFsOptions({ rmFakedTempDirAfterRun: false }).
    You are supposed to call result.cleanUpFakedDirs() at the end of a test by yourself.
  2. You set existing directory as action temp dir: options.setTempDir('existing/path').

🔹 workspaceDirPath

Path of a workspace directory (accessible under GITHUB_WORKSPACE inside tested action) that is still available after the action run. By default, it's undefined because faked dirs are deleted after run. For Docker target it contains a path of the host directory.

Can have value in case of:

  1. You asked not to delete faked workspace dir after run:
    options.setFakeFsOptions({ rmFakedWorkspaceDirAfterRun: false }).
    You are supposed to call result.cleanUpFakedDirs() at the end of a test by yourself.
  2. You set existing directory as action temp dir: options.setWorkspaceDir('existing/path').

🔹 runnerWarnings

The property is an array of RunnerWarning) objects and contains warnings similar to ones produced by GitHub Runner.

By default, warning messages are printed to stderr at the end of the run. If you want to check them by yourself, you can disable this behavior by options.setOutputOptions({printRunnerWarnings: false}).

Read detailed description here.

🔹 cleanUpFakedDirs() method

Delete faked directories that still exist after run. It will not delete existing dirs set explicitly by options.setWorkspaceDir(...) and options.setTempDir(...) functions.

You have to call it only if you used rmFakedTempDirAfterRun: false or rmFakedWorkspaceDirAfterRun: false options for fake FS options.

Alternatively, you can set up calling global deleteAllFakedDirs() method after each test case in your test framework.

Example with Jest:

import {deleteAllFakedDirs} from 'github-action-ts-run-api';

afterEach(deleteAllFakedDirs);

🔸 fnResult

ONLY for asyncFn and syncFn targets

Contains a value returned by a tested function. In case of asyncFn target, it's a value that promise was fulfilled with.

🔸 spawnResult

ONLY for JS file and Docker targets

Contains a result of a spawning of child process:

  • node process for JS file targets
  • docker run for Docker target

🔸 buildSpawnResult

ONLY for Docker target

Contains a result of spawning of docker build. After a second and subsequent run() calls can be undefined, because image id has been cached.

🔸 isSuccessBuild

ONLY for Docker target

Indicates whether docker build command was successful.