1
0
Fork 0

update inputs and variables

pull/4/head
Bryan MacFarlane 2019-05-17 10:23:01 -04:00
parent d7423efd98
commit a97380e90d
3 changed files with 38 additions and 15 deletions

View File

@ -5,18 +5,24 @@
## Usage ## Usage
``` ```
//-----------------------------------------------------------------------
// Variables, Inputs and Outputs
//-----------------------------------------------------------------------
/** /**
* 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 name the name of the variable to set
* @param val the value of the variable * @param val the value of the variable
*/ */
export function exportVariable(name: string, val: string, options?:im.ExportOptions); export function exportVariable(name: string, val: string);
/** /**
* registers a secret which will get masked from logs * registers a secret which will get masked from logs
* @param val value of the secret * @param val value of the secret
*/ */
export function setSecret(val: string); export function setSecret(name: string, val: string);
// TODO: follow up and see if we need anything for outputs
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Results // Results

View File

@ -2,25 +2,46 @@ import im = require('./interfaces');
import intm = require('./internal'); import intm = require('./internal');
import process = require('process'); import process = require('process');
//-----------------------------------------------------------------------
// Variables
//-----------------------------------------------------------------------
/** /**
* 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 name the name of the variable to set
* @param val the value of the variable * @param val the value of the variable
*/ */
export function exportVariable(name: string, val: string, options?:im.ExportOptions) { export function exportVariable(name: string, val: string) {
process.env[name] = val; process.env[name] = val;
let props = {'name': name, 'isSecret': options? options.isSecret : false}; intm._issueCommand('set-variable', {'name': name}, val);
intm._issueCommand('set-variable', props, val);
} }
/** /**
* registers a secret which will get masked from logs * 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 * @param val value of the secret
*/ */
export function setSecret(val: string) { export function setSecret(name: string, val: string) {
exportVariable(name, val);
intm._issueCommand('set-secret', {}, val); intm._issueCommand('set-secret', {}, val);
} }
/**
* Gets the value of an input. The value is also trimmed.
*
* @param name name of the input to get
* @param options optional. See InputOptions.
* @returns string
*/
export function getInput(name: string, options?: im.InputOptions): string {
let val:string = process.env['INPUT_' + name];
if (options && options.required && !val) {
throw new Error(`Input required and not supplied: ${name}`);
}
return val;
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Results // Results
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -44,10 +65,6 @@ export function setFailed(message: string) {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Logging Commands // Logging Commands
//
// error and warning issues do not take FileDetails because while possible,
// that's typically reserved for the agent and the problem matchers.
//
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**

View File

@ -19,9 +19,9 @@ export enum ExitCode {
} }
/** /**
* Interface for exportVariable options * Interface for getInput options
*/ */
export interface ExportOptions { export interface InputOptions {
/** Optional. Whether the variable should be marked as secret (will be masked from logs). Defaults to false */ /** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */
isSecret?: boolean; required?: boolean;
} }