Add File Commands (#571)

* Add File Commands

* pr updates w/ feedback

* run format

* fix lint/format

* slight update with an example in the docs

* pr feedback
This commit is contained in:
Thomas Boop
2020-09-23 11:19:20 -04:00
committed by GitHub
parent da34bfb74d
commit 0759cdc230
6 changed files with 203 additions and 61 deletions

View File

@@ -1,4 +1,6 @@
import {issue, issueCommand, toCommandValue} from './command'
import {issue, issueCommand} from './command'
import {issueCommand as issueFileCommand} from './file-command'
import {toCommandValue} from './utils'
import * as os from 'os'
import * as path from 'path'
@@ -39,7 +41,15 @@ export enum ExitCode {
export function exportVariable(name: string, val: any): void {
const convertedVal = toCommandValue(val)
process.env[name] = convertedVal
issueCommand('set-env', {name}, convertedVal)
const filePath = process.env['GITHUB_ENV'] || ''
if (filePath) {
const delimiter = '_GitHubActionsFileCommandDelimeter_'
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`
issueFileCommand('ENV', commandValue)
} else {
issueCommand('set-env', {name}, convertedVal)
}
}
/**
@@ -55,7 +65,12 @@ export function setSecret(secret: string): void {
* @param inputPath
*/
export function addPath(inputPath: string): void {
issueCommand('add-path', {}, inputPath)
const filePath = process.env['GITHUB_PATH'] || ''
if (filePath) {
issueFileCommand('PATH', inputPath)
} else {
issueCommand('add-path', {}, inputPath)
}
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`
}