From 49dd720622ab2bcf0c4620e2b8f1fe14dfbd7313 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Tue, 1 Oct 2019 17:13:05 -0400 Subject: [PATCH] setSecret (#174) * setSecret --- README.md | 6 ++++-- RELEASES.md | 5 +++-- __tests__/lib.test.ts | 32 ++++---------------------------- package.json | 2 +- src/core.ts | 15 +++++---------- 5 files changed, 17 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 860dce3..026bb52 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/RELEASES.md b/RELEASES.md index d677f69..48f58a2 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -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 diff --git a/__tests__/lib.test.ts b/__tests__/lib.test.ts index 75bb04c..838f23b 100644 --- a/__tests__/lib.test.ts +++ b/__tests__/lib.test.ts @@ -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') diff --git a/package.json b/package.json index bad955b..a08bded 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@actions/core", - "version": "1.1.2", + "version": "1.1.3", "description": "Actions core lib", "keywords": [ "github", diff --git a/src/core.ts b/src/core.ts index 072f232..000cdd7 100644 --- a/src/core.ts +++ b/src/core.ts @@ -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) } /**