2019-05-21 16:00:23 +00:00
|
|
|
import {ExitCode} from '@actions/exit'
|
2019-05-21 18:38:29 +00:00
|
|
|
import * as intm from './command'
|
2019-05-17 03:36:45 +00:00
|
|
|
|
2019-05-21 16:00:23 +00:00
|
|
|
/**
|
|
|
|
* Interface for getInput options
|
|
|
|
*/
|
|
|
|
export interface InputOptions {
|
|
|
|
/** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */
|
|
|
|
required?: boolean
|
|
|
|
}
|
|
|
|
|
2019-05-17 14:23:01 +00:00
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
// Variables
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
|
2019-05-17 03:36:45 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2019-05-17 14:23:01 +00:00
|
|
|
export function exportVariable(name: string, val: string) {
|
2019-05-20 23:17:56 +00:00
|
|
|
process.env[name] = val
|
2019-05-21 18:40:57 +00:00
|
|
|
intm.issueCommand('set-env', {name}, val)
|
2019-05-17 03:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-17 14:23:01 +00:00
|
|
|
* exports the variable and registers a secret which will get masked from logs
|
|
|
|
* @param name the name of the variable to set
|
2019-05-17 03:36:45 +00:00
|
|
|
* @param val value of the secret
|
|
|
|
*/
|
2019-05-21 18:38:29 +00:00
|
|
|
export function exportSecret(name: string, val: string) {
|
2019-05-20 23:17:56 +00:00
|
|
|
exportVariable(name, val)
|
2019-05-21 18:38:29 +00:00
|
|
|
intm.issueCommand('set-secret', {}, val)
|
2019-05-20 23:17:56 +00:00
|
|
|
}
|
2019-05-17 03:36:45 +00:00
|
|
|
|
2019-05-17 14:23:01 +00:00
|
|
|
/**
|
|
|
|
* Gets the value of an input. The value is also trimmed.
|
2019-05-20 23:17:56 +00:00
|
|
|
*
|
2019-05-17 14:23:01 +00:00
|
|
|
* @param name name of the input to get
|
|
|
|
* @param options optional. See InputOptions.
|
|
|
|
* @returns string
|
|
|
|
*/
|
2019-05-21 16:03:13 +00:00
|
|
|
export function getInput(name: string, options?: InputOptions): string {
|
2019-05-21 14:51:22 +00:00
|
|
|
const val: string =
|
|
|
|
process.env[`INPUT_${name.replace(' ', '_').toUpperCase()}`] || ''
|
2019-05-20 23:17:56 +00:00
|
|
|
if (options && options.required && !val) {
|
|
|
|
throw new Error(`Input required and not supplied: ${name}`)
|
|
|
|
}
|
2019-05-17 14:23:01 +00:00
|
|
|
|
2019-05-20 23:17:56 +00:00
|
|
|
return val.trim()
|
2019-05-17 14:23:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 03:36:45 +00:00
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
// Results
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the action status to neutral
|
|
|
|
*/
|
|
|
|
export function setNeutral() {
|
2019-05-21 16:00:23 +00:00
|
|
|
process.exitCode = ExitCode.Neutral
|
2019-05-17 03:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-20 23:17:56 +00:00
|
|
|
* Sets the action status to failed.
|
2019-05-17 03:36:45 +00:00
|
|
|
* When the action exits it will be with an exit code of 1
|
|
|
|
* @param message add error issue message
|
|
|
|
*/
|
|
|
|
export function setFailed(message: string) {
|
2019-05-21 16:00:23 +00:00
|
|
|
process.exitCode = ExitCode.Failure
|
2019-05-20 23:17:56 +00:00
|
|
|
error(message)
|
2019-05-17 03:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
// Logging Commands
|
|
|
|
//-----------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes debug message to user log
|
|
|
|
* @param message debug message
|
|
|
|
*/
|
|
|
|
export function debug(message: string) {
|
2019-05-21 18:38:29 +00:00
|
|
|
intm.issueCommand('debug', {}, message)
|
2019-05-17 03:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an error issue
|
|
|
|
* @param message error issue message
|
|
|
|
*/
|
|
|
|
export function error(message: string) {
|
2019-05-21 18:38:29 +00:00
|
|
|
intm.issue('error', message)
|
2019-05-17 03:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an warning issue
|
|
|
|
* @param message warning issue message
|
|
|
|
*/
|
|
|
|
export function warning(message: string) {
|
2019-05-21 18:38:29 +00:00
|
|
|
intm.issue('warning', message)
|
2019-05-17 03:36:45 +00:00
|
|
|
}
|