Compare commits

...

6 Commits

Author SHA1 Message Date
Francesco Renzi c44e73f0a5 Catch multiple instances 2023-05-23 15:03:32 +01:00
Francesco Renzi 0e36a96ee5 Apply linting 2023-05-23 14:11:05 +01:00
Francesco Renzi 38e6785d19 Apply linting 2023-05-23 13:45:22 +01:00
Francesco Renzi 9fccf58073 Simplify regex 2023-05-23 13:29:06 +01:00
Francesco Renzi 63ffaaf25e Update docs/commands.md
Co-authored-by: John Wesley Walker III <81404201+jww3@users.noreply.github.com>
2023-05-23 13:28:09 +01:00
Francesco Renzi 5ccbd5f448 Add support for multi-line secrets in setSecret 2023-05-23 13:28:09 +01:00
3 changed files with 17 additions and 2 deletions

View File

@ -50,7 +50,9 @@ function setSecret(secret: string): void {}
Now, future logs containing BAR will be masked. E.g. running `echo "Hello FOO BAR World"` will now print `Hello FOO **** World`.
**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.
**WARNING** The add-mask command only supports single-line secrets. To register
a multi-line secret, the recommended practice is to register each line individually. Otherwise, it will
not be masked. `@actions/core >= 1.11.0` `setSecret` will perform this automatically.
**WARNING** 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`

View File

@ -164,6 +164,15 @@ describe('@actions/core', () => {
assertWriteCalls([`::add-mask::secret val${os.EOL}`])
})
it('setSecret splits multi line secrets into multiple commands', () => {
core.setSecret('first\nsecond\r\nthird')
assertWriteCalls([
`::add-mask::first${os.EOL}`,
`::add-mask::second${os.EOL}`,
`::add-mask::third${os.EOL}`
])
})
it('prependPath produces the correct commands and sets the env', () => {
const command = 'PATH'
createFileCommandFile(command)

View File

@ -97,7 +97,11 @@ export function exportVariable(name: string, val: any): void {
* @param secret value of the secret
*/
export function setSecret(secret: string): void {
issueCommand('add-mask', {}, secret)
for (const part of secret.split(/[\r\n]+/)) {
if (part) {
issueCommand('add-mask', {}, part)
}
}
}
/**