From e4916b11f36616404bcd2e7672233b168716daef Mon Sep 17 00:00:00 2001 From: Thomas Boop Date: Fri, 10 Apr 2020 14:09:24 -0400 Subject: [PATCH 1/2] Add docs and wrapper for "echo" command --- docs/commands.md | 25 ++++++++++++++++++++++++- packages/core/__tests__/core.test.ts | 10 ++++++++++ packages/core/src/core.ts | 9 +++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/commands.md b/docs/commands.md index d1e438e253..316007f978 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -122,7 +122,7 @@ echo "::save-state name=FOO::foovalue" ### Log Level -Finally, there are several commands to emit different levels of log output: +There are several commands to emit different levels of log output: | log level | example usage | |---|---| @@ -130,6 +130,29 @@ Finally, there are several commands to emit different levels of log output: | warning | `echo "::warning::My warning message"` | | error | `echo "::error::My error message"` | +### Command Echoing +By default, the echoing of commands to stdout only occurs if [Step Debugging is enabled](./actions-debugging.md#How-to-Access-Step-Debug-Logs) + +You can enable or disable this for the current step by using the `echo` command. + +```bash +echo "::echo::on" +``` + +You can also disable echoing. + +```bash +echo "::echo::off" +``` + +This is wrapped by the core method: + +```javascript +function setCommandEcho(enable: boolean): void {} +``` + +The `add-mask`, `debug`, `warning` and `error` commands do not support echoing. + ### Command Prompt CMD processes the `"` character differently from other shells when echoing. In CMD, the above snippets should have the `"` characters removed in order to correctly process. For example, the set output command would be: ```cmd diff --git a/packages/core/__tests__/core.test.ts b/packages/core/__tests__/core.test.ts index d10e0590d8..2901065262 100644 --- a/packages/core/__tests__/core.test.ts +++ b/packages/core/__tests__/core.test.ts @@ -239,6 +239,16 @@ describe('@actions/core', () => { process.env['RUNNER_DEBUG'] = current } }) + + it('setCommandEcho can enable echoing', () => { + core.setCommandEcho(true) + assertWriteCalls([`::echo::on${os.EOL}`]) + }) + + it('setCommandEcho can disable echoing', () => { + core.setCommandEcho(false) + assertWriteCalls([`::echo::off${os.EOL}`]) + }) }) // Assert that process.stdout.write calls called only with the given arguments. diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index 85fc547a96..bdc11649e4 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -87,6 +87,15 @@ export function setOutput(name: string, value: any): void { issueCommand('set-output', {name}, value) } +/** + * Enables or disables the echoing of commands into stdout for the rest of the step. + * Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set. + * + */ +export function setCommandEcho(enable: boolean): void { + issue('echo', enable ? 'on' : 'off') +} + //----------------------------------------------------------------------- // Results //----------------------------------------------------------------------- From 4cd99b2e4e743b5768458dbbd6af94e0fad352ae Mon Sep 17 00:00:00 2001 From: Thomas Boop Date: Mon, 13 Apr 2020 11:51:39 -0400 Subject: [PATCH 2/2] Update parameter to enabled --- docs/commands.md | 2 +- packages/core/src/core.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 316007f978..186f4b24a9 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -148,7 +148,7 @@ echo "::echo::off" This is wrapped by the core method: ```javascript -function setCommandEcho(enable: boolean): void {} +function setCommandEcho(enabled: boolean): void {} ``` The `add-mask`, `debug`, `warning` and `error` commands do not support echoing. diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index bdc11649e4..0cf9f04ca7 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -92,8 +92,8 @@ export function setOutput(name: string, value: any): void { * Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set. * */ -export function setCommandEcho(enable: boolean): void { - issue('echo', enable ? 'on' : 'off') +export function setCommandEcho(enabled: boolean): void { + issue('echo', enabled ? 'on' : 'off') } //-----------------------------------------------------------------------