From e42d1af59d621278a2fed02f7d15d67c53a808a0 Mon Sep 17 00:00:00 2001 From: bubkoo Date: Sun, 27 Sep 2020 10:03:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20export=20environment=20vari?= =?UTF-8?q?bale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/action.ts | 6 ++++++ src/index.ts | 5 ++++- src/state.ts | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/action.ts b/src/action.ts index b554ade..436571f 100644 --- a/src/action.ts +++ b/src/action.ts @@ -11,8 +11,14 @@ export namespace Action { await Util.saveAppTokenToSecret(secretName, token) core.info(`Token save in secret "${secretName}"`) } + core.setSecret(token) core.setOutput('token', token) + + const variableName = core.getInput('VARIABLE_NAME') + if (variableName) { + core.exportVariable(variableName, token) + } } catch (e) { core.error(e) core.setFailed(e.message) diff --git a/src/index.ts b/src/index.ts index 3513773..3f4c52b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,11 @@ +import { getInput } from '@actions/core' import { State } from './state' import { Action } from './action' if (!State.isPost) { Action.run() } else { - Action.cleanup() + if (getInput('CLEAN_SECRET') === 'true') { + Action.cleanup() + } } diff --git a/src/state.ts b/src/state.ts index 5a16825..9601ca3 100644 --- a/src/state.ts +++ b/src/state.ts @@ -1,12 +1,12 @@ -import * as coreCommand from '@actions/core/lib/command' +import { getState, saveState } from '@actions/core' export namespace State { - export const isPost = !!process.env['STATE_isPost'] + export const isPost = !!getState('isPost') // Publish a variable so that when the POST action runs, it can determine // it should run the cleanup logic. This is necessary since we don't have // a separate entry point. if (!isPost) { - coreCommand.issueCommand('save-state', { name: 'isPost' }, 'true') + saveState('isPost', true) } }