mirror of https://github.com/actions/toolkit
parent
713902387e
commit
9d54cd22ea
|
@ -67,15 +67,16 @@ export function setOutput(name: string, value: string): void {}
|
|||
|
||||
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.
|
||||
|
||||
To mask a value in the logs, use `::set-secret`:
|
||||
To mask a value in the logs, use `::add-mask`:
|
||||
|
||||
```sh
|
||||
echo ::set-secret::BAR
|
||||
echo ::add-mask::mysecretvalue
|
||||
```
|
||||
|
||||
This is wrapped by the core method which both sets the value as a variable for future steps and registers the secret to mask
|
||||
This is wrapped by the core setSecret method
|
||||
|
||||
```javascript
|
||||
function exportSecret(name: string, val: string): void {}
|
||||
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`.
|
||||
|
|
|
@ -32,10 +32,12 @@ Since each step runs in a separate process, you can use `exportVariable` to add
|
|||
core.exportVariable('envVar', 'Val');
|
||||
```
|
||||
|
||||
Exporting a secret exports the variable but also registers the secret with the runner to ensure it is masked in logs.
|
||||
#### Setting a secret
|
||||
|
||||
Setting a secret registers the secret with the runner to ensure it is masked in logs.
|
||||
|
||||
```js
|
||||
core.exportSecret('myPassword', mypass);
|
||||
core.setSecret('myPassword');
|
||||
```
|
||||
|
||||
#### PATH Manipulation
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
# @actions/core Releases
|
||||
|
||||
### 1.1.2
|
||||
### 1.1.3
|
||||
|
||||
- set-secret is now available for use [#141](https://github.com/actions/toolkit/issues/141)
|
||||
- setSecret added to register a secret with the runner to be masked from the logs
|
||||
- exportSecret which was not implemented and never worked was removed after clarification from product.
|
||||
|
||||
### 1.1.1
|
||||
|
||||
|
|
|
@ -51,34 +51,10 @@ describe('@actions/core', () => {
|
|||
assertWriteCalls([`::set-env name=my var2,::var val%0D%0A${os.EOL}`])
|
||||
})
|
||||
|
||||
// it('exportSecret produces the correct commands and sets the env', () => {
|
||||
// core.exportSecret('my secret', 'secret val')
|
||||
// expect(process.env['my secret']).toBe('secret val')
|
||||
// assertWriteCalls([
|
||||
// `::set-env name=my secret,::secret val${os.EOL}`,
|
||||
// `::set-secret]secret val${os.EOL}`
|
||||
// ])
|
||||
// })
|
||||
|
||||
// it('exportSecret escapes secret names', () => {
|
||||
// core.exportSecret('special char secret \r\n];', 'special secret val')
|
||||
// expect(process.env['special char secret \r\n];']).toBe('special secret val')
|
||||
// assertWriteCalls([
|
||||
// `::set-env name=special char secret %0D%0A%5D%3B,::special secret val${
|
||||
// os.EOL
|
||||
// }`,
|
||||
// `::set-secret]special secret val${os.EOL}`
|
||||
// ])
|
||||
// })
|
||||
|
||||
// it('exportSecret escapes secret values', () => {
|
||||
// core.exportSecret('my secret2', 'secret val\r\n')
|
||||
// expect(process.env['my secret2']).toBe('secret val\r\n')
|
||||
// assertWriteCalls([
|
||||
// `::set-env name=my secret2,::secret val%0D%0A${os.EOL}`,
|
||||
// `::set-secret]secret val%0D%0A${os.EOL}`
|
||||
// ])
|
||||
// })
|
||||
it('setSecret produces the correct command', () => {
|
||||
core.setSecret('secret val')
|
||||
assertWriteCalls([`::add-mask::secret val${os.EOL}`])
|
||||
})
|
||||
|
||||
it('prependPath produces the correct commands and sets the env', () => {
|
||||
core.addPath('myPath')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@actions/core",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"description": "Actions core lib",
|
||||
"keywords": [
|
||||
"github",
|
||||
|
|
|
@ -31,7 +31,7 @@ export enum ExitCode {
|
|||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* sets env variable for this action and future actions in the job
|
||||
* Sets env variable for this action and future actions in the job
|
||||
* @param name the name of the variable to set
|
||||
* @param val the value of the variable
|
||||
*/
|
||||
|
@ -41,16 +41,11 @@ export function exportVariable(name: string, val: string): void {
|
|||
}
|
||||
|
||||
/**
|
||||
* exports the variable and registers a secret which will get masked from logs
|
||||
* @param name the name of the variable to set
|
||||
* @param val value of the secret
|
||||
* Registers a secret which will get masked from logs
|
||||
* @param secret value of the secret
|
||||
*/
|
||||
export function exportSecret(name: string, val: string): void {
|
||||
exportVariable(name, val)
|
||||
|
||||
// the runner will error with not implemented
|
||||
// leaving the function but raising the error earlier
|
||||
issueCommand('set-secret', {}, val)
|
||||
export function setSecret(secret: string): void {
|
||||
issueCommand('add-mask', {}, secret)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue