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

Add docs and wrapper for "echo" command #411

Merged
merged 2 commits into from Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion docs/commands.md
Expand Up @@ -122,14 +122,37 @@ 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 |
|---|---|
| [debug](action-debugging.md) | `echo "::debug::My debug message"` |
| 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
Expand Down
10 changes: 10 additions & 0 deletions packages/core/__tests__/core.test.ts
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/core.ts
Expand Up @@ -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 {
thboop marked this conversation as resolved.
Show resolved Hide resolved
issue('echo', enable ? 'on' : 'off')
}

//-----------------------------------------------------------------------
// Results
//-----------------------------------------------------------------------
Expand Down