Skip to content

Commit

Permalink
feat: ✨ export environment varibale
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Sep 27, 2020
1 parent e675890 commit e42d1af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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()
}
}
6 changes: 3 additions & 3 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit e42d1af

Please sign in to comment.