2019-09-09 15:58:49 +00:00
|
|
|
# :: Commands
|
|
|
|
|
|
|
|
The [core toolkit package](https://github.com/actions/toolkit/tree/master/packages/core) offers a number of convenience functions for
|
|
|
|
setting results, logging, registering secrets and exporting variables across actions. Sometimes, however, its useful to be able to do
|
|
|
|
these things in a script or other tool.
|
|
|
|
|
2019-10-01 16:56:09 +00:00
|
|
|
To allow this, we provide a special `::` syntax which, if logged to `stdout` on a new line, will allow the runner to perform special behavior on
|
2019-09-09 15:58:49 +00:00
|
|
|
your commands. The following commands are all supported:
|
|
|
|
|
|
|
|
### Set an environment variable
|
|
|
|
|
2019-09-25 01:08:02 +00:00
|
|
|
To set an environment variable for future out of process steps, use `::set-env`:
|
2019-09-09 15:58:49 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
echo ::set-env name=FOO::BAR
|
|
|
|
```
|
|
|
|
|
|
|
|
Running `$FOO` in a future step will now return `BAR`
|
|
|
|
|
2019-09-25 01:08:02 +00:00
|
|
|
This is wrapped by the core exportVariable method which sets for future steps but also updates the variable for this step
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
export function exportVariable(name: string, val: string): void {}
|
|
|
|
```
|
|
|
|
|
2019-09-09 15:58:49 +00:00
|
|
|
### PATH Manipulation
|
|
|
|
|
|
|
|
To prepend a string to PATH, use `::addPath`:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
echo ::add-path::BAR
|
|
|
|
```
|
|
|
|
|
|
|
|
Running `$PATH` in a future step will now return `BAR:{Previous Path}`;
|
|
|
|
|
2019-09-25 01:08:02 +00:00
|
|
|
This is wrapped by the core addPath method:
|
|
|
|
```javascript
|
|
|
|
export function addPath(inputPath: string): void {}
|
|
|
|
```
|
|
|
|
|
2019-09-09 15:58:49 +00:00
|
|
|
### Set outputs
|
|
|
|
|
|
|
|
To set an output for the step, use `::set-output`:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
echo ::set-output name=FOO::BAR
|
|
|
|
```
|
|
|
|
|
|
|
|
Running `steps.[step-id].outputs.FOO` in your Yaml will now give you `BAR`
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
steps:
|
|
|
|
- name: Set the value
|
|
|
|
id: step_one
|
|
|
|
run: echo ::set-output name=FOO::BAR
|
|
|
|
- name: Use it
|
|
|
|
run: echo ${{ steps.step_one.outputs.FOO }}
|
|
|
|
```
|
|
|
|
|
2019-09-25 01:08:02 +00:00
|
|
|
This is wrapped by the core setOutput method:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
export function setOutput(name: string, value: string): void {}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Register a secret
|
|
|
|
|
|
|
|
If a script or action does work to create a secret at runtime, it can be registered with the runner to be masked in logs.
|
2019-09-09 15:58:49 +00:00
|
|
|
|
2019-09-25 01:08:02 +00:00
|
|
|
To mask a value in the logs, use `::set-secret`:
|
2019-09-09 15:58:49 +00:00
|
|
|
|
|
|
|
```sh
|
2019-09-25 01:08:02 +00:00
|
|
|
echo ::set-secret::BAR
|
|
|
|
```
|
|
|
|
|
|
|
|
This is wrapped by the core method which both sets the value as a variable for future steps and registers the secret to mask
|
|
|
|
```javascript
|
|
|
|
function exportSecret(name: string, val: string): void {}
|
2019-09-09 15:58:49 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Now, future logs containing BAR will be masked. E.g. running `echo "Hello FOO BAR World"` will now print `Hello FOO **** World`.
|
|
|
|
|
|
|
|
CAUTION: Do **not** mask short values if you can avoid it, it could render your output unreadable (and future steps' output as well).
|
|
|
|
For example, if you mask the letter `l`, running `echo "Hello FOO BAR World"` will now print `He*********o FOO BAR Wor****d`
|
|
|
|
|
2019-09-25 01:08:02 +00:00
|
|
|
### Group and Ungroup Log Lines
|
|
|
|
|
|
|
|
Emitting a group with a title will instruct the logs to create a collapsable region up to the next ungroup command.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
echo ::group::my title
|
2019-09-25 02:14:11 +00:00
|
|
|
echo ::endgroup::
|
2019-09-25 01:08:02 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
This is wrapped by the core methods:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
function startGroup(name: string): void {}
|
|
|
|
function endGroup(): void {}
|
|
|
|
```
|
|
|
|
|
2019-09-09 15:58:49 +00:00
|
|
|
### Log Level
|
|
|
|
|
|
|
|
Finally, there are several commands to emit different levels of log output:
|
|
|
|
|
|
|
|
| log level | example usage |
|
|
|
|
|---|---|
|
|
|
|
| [debug](https://github.com/actions/toolkit/blob/master/docs/action-debugging.md) | `echo ::debug::My debug message` |
|
|
|
|
| warning | `echo ::warning::My warning message` |
|
2019-10-01 16:56:09 +00:00
|
|
|
| error | `echo ::error::My error message` |
|