Skip to content

Commit a6bf872

Browse files
authored
Merge pull request #1430 from actions/add-mask-docs
Update docs for setSecret
2 parents 37e09c5 + ae9272d commit a6bf872

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

docs/commands.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,18 @@ function setSecret(secret: string): void {}
5050

5151
Now, future logs containing BAR will be masked. E.g. running `echo "Hello FOO BAR World"` will now print `Hello FOO **** World`.
5252

53-
**WARNING** The add-mask and setSecret commands only support single line secrets. To register a multiline secrets you must register each line individually otherwise it will not be masked.
53+
**WARNING** The add-mask and setSecret commands only support single-line
54+
secrets or multi-line secrets that have been escaped. `@actions/core`
55+
`setSecret` will escape the string you provide by default. When an escaped
56+
multi-line string is provided the whole string and each of its lines
57+
individually will be masked. For example you can mask `first\nsecond\r\nthird`
58+
using:
59+
60+
```sh
61+
echo "::add-mask::first%0Asecond%0D%0Athird"
62+
```
63+
64+
This will mask `first%0Asecond%0D%0Athird`, `first`, `second` and `third`.
5465

5566
**WARNING** Do **not** mask short values if you can avoid it, it could render your output unreadable (and future steps' output as well).
5667
For example, if you mask the letter `l`, running `echo "Hello FOO BAR World"` will now print `He*********o FOO BAR Wor****d`

packages/core/__tests__/core.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ describe('@actions/core', () => {
161161

162162
it('setSecret produces the correct command', () => {
163163
core.setSecret('secret val')
164-
assertWriteCalls([`::add-mask::secret val${os.EOL}`])
164+
core.setSecret('multi\nline\r\nsecret')
165+
assertWriteCalls([
166+
`::add-mask::secret val${os.EOL}`,
167+
`::add-mask::multi%0Aline%0D%0Asecret${os.EOL}`
168+
])
165169
})
166170

167171
it('prependPath produces the correct commands and sets the env', () => {

0 commit comments

Comments
 (0)