From 937a86c7e06c72ea2f6c1882136dff43df36d0a0 Mon Sep 17 00:00:00 2001 From: Simran Spiller Date: Sun, 31 Oct 2021 21:59:41 +0100 Subject: [PATCH 1/2] Actions: Add echo workflow command Fixes #7868 --- .../workflow-commands-for-github-actions.md | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/content/actions/learn-github-actions/workflow-commands-for-github-actions.md b/content/actions/learn-github-actions/workflow-commands-for-github-actions.md index f3d0c9c1bddf..b5ec4187e138 100644 --- a/content/actions/learn-github-actions/workflow-commands-for-github-actions.md +++ b/content/actions/learn-github-actions/workflow-commands-for-github-actions.md @@ -68,7 +68,7 @@ The following table shows which toolkit functions are available within a workflo | ----------------- | ------------- | | `core.addPath` | Accessible using environment file `GITHUB_PATH` | | `core.debug` | `debug` |{% ifversion fpt or ghes > 3.2 or ghae-issue-4929 or ghec %} -| `core.notice` | `notice` |{% endif %} +| `core.notice` | `notice` |{% endif %} | `core.error` | `error` | | `core.endGroup` | `endgroup` | | `core.exportVariable` | Accessible using environment file `GITHUB_ENV` | @@ -76,6 +76,7 @@ The following table shows which toolkit functions are available within a workflo | `core.getState` | Accessible using environment variable `STATE_{NAME}` | | `core.isDebug` | Accessible using environment variable `RUNNER_DEBUG` | | `core.saveState` | `save-state` | +| `core.setCommandEcho` | `echo` | | `core.setFailed` | Used as a shortcut for `::error` and `exit 1` | | `core.setOutput` | `set-output` | | `core.setSecret` | `add-mask` | @@ -246,6 +247,44 @@ jobs: {% endraw %} +## Echoing command outputs + +``` +::echo::on +::echo::off +``` + +The `echo` command lets you enable or disable echoing of workflow commands. For example, if you use the `set-output` command in a workflow, it sets an output parameter but the workflow run log does not show the command itself. If you enable command echoing, then the log shows the command output, like `::set-output name={name}::{value}`. + +Command echoing is disabled by default. A workflow command is echoed if any error occurs processing the command, however. + +You can enable command echoing globally by turning on step debug logging (`ACTIONS_STEP_DEBUG` secret). For more information, see "[Enabling debug logging](/actions/managing-workflow-runs/enabling-debug-logging)". In contrast, the `echo` command lets you enable command echoing more granular. + +The commands `debug`, `notice`, `warning`, and `error` do not support echoing because they print messages to the log anyway. + +### Example toggling command echoing + +```yaml +jobs: + workflow-command-job: + runs-on: ubuntu-latest + steps: + - name: toggle workflow command echoing + run: | + echo '::set-output name=action_echo::disabled' + echo '::echo::on' + echo '::set-output name=action_echo::enabled' + echo '::echo::off' + echo '::set-output name=action_echo::disabled' +``` + +Turns command echoing on and off and sets an output parameter in both states. Only the second `set-output` and `echo` commands will show in the log because command echoing is enabled when they are run. Command echoing is disabled when all other commands are run and they are thus not printed. The output parameter is set in all cases. + +``` +::set-output name=action_echo::enabled +::echo::off +``` + ## Sending values to the pre and post actions You can use the `save-state` command to create environment variables for sharing with your workflow's `pre:` or `post:` actions. For example, you can create a file with the `pre:` action, pass the file location to the `main:` action, and then use the `post:` action to delete the file. Alternatively, you could create a file with the `main:` action, pass the file location to the `post:` action, and also use the `post:` action to delete the file. From dccd75482cafec052403b4410e2421d344204daa Mon Sep 17 00:00:00 2001 From: Lucas Costi Date: Tue, 16 Nov 2021 13:38:20 +1000 Subject: [PATCH 2/2] Wording edits --- .../workflow-commands-for-github-actions.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/content/actions/learn-github-actions/workflow-commands-for-github-actions.md b/content/actions/learn-github-actions/workflow-commands-for-github-actions.md index 0c4eaf67bc8d..a1466d2ff0d6 100644 --- a/content/actions/learn-github-actions/workflow-commands-for-github-actions.md +++ b/content/actions/learn-github-actions/workflow-commands-for-github-actions.md @@ -254,13 +254,13 @@ jobs: ::echo::off ``` -The `echo` command lets you enable or disable echoing of workflow commands. For example, if you use the `set-output` command in a workflow, it sets an output parameter but the workflow run log does not show the command itself. If you enable command echoing, then the log shows the command output, like `::set-output name={name}::{value}`. +Enables or disables echoing of workflow commands. For example, if you use the `set-output` command in a workflow, it sets an output parameter but the workflow run's log does not show the command itself. If you enable command echoing, then the log shows the command, such as `::set-output name={name}::{value}`. -Command echoing is disabled by default. A workflow command is echoed if any error occurs processing the command, however. +Command echoing is disabled by default. However, a workflow command is echoed if there are any error occurs processing the command. -You can enable command echoing globally by turning on step debug logging (`ACTIONS_STEP_DEBUG` secret). For more information, see "[Enabling debug logging](/actions/managing-workflow-runs/enabling-debug-logging)". In contrast, the `echo` command lets you enable command echoing more granular. +The `add-mask`, `debug`, `warning`, and `error` commands do not support echoing because their outputs are already echoed to the log. -The commands `debug`, `notice`, `warning`, and `error` do not support echoing because they print messages to the log anyway. +You can also enable command echoing globally by turning on step debug logging using the `ACTIONS_STEP_DEBUG` secret. For more information, see "[Enabling debug logging](/actions/managing-workflow-runs/enabling-debug-logging)". In contrast, the `echo` workflow command lets you enable command echoing at a more granular level, rather than enabling it for every workflow in a repository. ### Example toggling command echoing @@ -278,13 +278,15 @@ jobs: echo '::set-output name=action_echo::disabled' ``` -Turns command echoing on and off and sets an output parameter in both states. Only the second `set-output` and `echo` commands will show in the log because command echoing is enabled when they are run. Command echoing is disabled when all other commands are run and they are thus not printed. The output parameter is set in all cases. +The step above prints the following lines to the log: ``` ::set-output name=action_echo::enabled ::echo::off ``` +Only the second `set-output` and `echo` workflow commands are included in the log because command echoing was only enabled when they were run. Even though it is not always echoed, the output parameter is set in all cases. + ## Sending values to the pre and post actions You can use the `save-state` command to create environment variables for sharing with your workflow's `pre:` or `post:` actions. For example, you can create a file with the `pre:` action, pass the file location to the `main:` action, and then use the `post:` action to delete the file. Alternatively, you could create a file with the `main:` action, pass the file location to the `post:` action, and also use the `post:` action to delete the file.