mirror of https://github.com/actions/toolkit
Run linter
parent
e6cc6dc147
commit
97c1e7df5a
|
@ -1,6 +1,6 @@
|
||||||
import im = require('./interfaces');
|
import im = require('./interfaces')
|
||||||
import intm = require('./internal');
|
import intm = require('./internal')
|
||||||
import process = require('process');
|
import process = require('process')
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
// Variables
|
// Variables
|
||||||
|
@ -12,8 +12,8 @@ import process = require('process');
|
||||||
* @param val the value of the variable
|
* @param val the value of the variable
|
||||||
*/
|
*/
|
||||||
export function exportVariable(name: string, val: string) {
|
export function exportVariable(name: string, val: string) {
|
||||||
process.env[name] = val;
|
process.env[name] = val
|
||||||
intm._issueCommand('set-variable', {'name': name}, val);
|
intm._issueCommand('set-variable', {name: name}, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,24 +22,25 @@ export function exportVariable(name: string, val: string) {
|
||||||
* @param val value of the secret
|
* @param val value of the secret
|
||||||
*/
|
*/
|
||||||
export function setSecret(name: string, val: string) {
|
export function setSecret(name: string, val: string) {
|
||||||
exportVariable(name, val);
|
exportVariable(name, val)
|
||||||
intm._issueCommand('set-secret', {}, val);
|
intm._issueCommand('set-secret', {}, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of an input. The value is also trimmed.
|
* Gets the value of an input. The value is also trimmed.
|
||||||
*
|
*
|
||||||
* @param name name of the input to get
|
* @param name name of the input to get
|
||||||
* @param options optional. See InputOptions.
|
* @param options optional. See InputOptions.
|
||||||
* @returns string
|
* @returns string
|
||||||
*/
|
*/
|
||||||
export function getInput(name: string, options?: im.InputOptions): string {
|
export function getInput(name: string, options?: im.InputOptions): string {
|
||||||
let val: string = process.env['INPUT_' + name.replace(' ', '_').toUpperCase()] || '';
|
let val: string =
|
||||||
if (options && options.required && !val) {
|
process.env['INPUT_' + name.replace(' ', '_').toUpperCase()] || ''
|
||||||
throw new Error(`Input required and not supplied: ${name}`);
|
if (options && options.required && !val) {
|
||||||
}
|
throw new Error(`Input required and not supplied: ${name}`)
|
||||||
|
}
|
||||||
|
|
||||||
return val.trim();
|
return val.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -50,17 +51,17 @@ export function getInput(name: string, options?: im.InputOptions): string {
|
||||||
* Sets the action status to neutral
|
* Sets the action status to neutral
|
||||||
*/
|
*/
|
||||||
export function setNeutral() {
|
export function setNeutral() {
|
||||||
process.exitCode = im.ExitCode.Neutral;
|
process.exitCode = im.ExitCode.Neutral
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the action status to failed.
|
* Sets the action status to failed.
|
||||||
* When the action exits it will be with an exit code of 1
|
* When the action exits it will be with an exit code of 1
|
||||||
* @param message add error issue message
|
* @param message add error issue message
|
||||||
*/
|
*/
|
||||||
export function setFailed(message: string) {
|
export function setFailed(message: string) {
|
||||||
process.exitCode = im.ExitCode.Failure;
|
process.exitCode = im.ExitCode.Failure
|
||||||
error(message);
|
error(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -72,7 +73,7 @@ export function setFailed(message: string) {
|
||||||
* @param message debug message
|
* @param message debug message
|
||||||
*/
|
*/
|
||||||
export function debug(message: string) {
|
export function debug(message: string) {
|
||||||
intm._issueCommand('debug', {}, message);
|
intm._issueCommand('debug', {}, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,7 +81,7 @@ export function debug(message: string) {
|
||||||
* @param message error issue message
|
* @param message error issue message
|
||||||
*/
|
*/
|
||||||
export function error(message: string) {
|
export function error(message: string) {
|
||||||
intm._issue('error', message);
|
intm._issue('error', message)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,5 +89,5 @@ export function error(message: string) {
|
||||||
* @param message warning issue message
|
* @param message warning issue message
|
||||||
*/
|
*/
|
||||||
export function warning(message: string) {
|
export function warning(message: string) {
|
||||||
intm._issue('warning', message);
|
intm._issue('warning', message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,26 +2,26 @@
|
||||||
* The code to exit an action
|
* The code to exit an action
|
||||||
*/
|
*/
|
||||||
export enum ExitCode {
|
export enum ExitCode {
|
||||||
/**
|
/**
|
||||||
* A code indicating that the action was successful
|
* A code indicating that the action was successful
|
||||||
*/
|
*/
|
||||||
Success = 0,
|
Success = 0,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A code indicating that the action was a failure
|
* A code indicating that the action was a failure
|
||||||
*/
|
*/
|
||||||
Failure = 1,
|
Failure = 1,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A code indicating that the action is complete, but neither succeeded nor failed
|
* A code indicating that the action is complete, but neither succeeded nor failed
|
||||||
*/
|
*/
|
||||||
Neutral = 78
|
Neutral = 78
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for getInput options
|
* Interface for getInput options
|
||||||
*/
|
*/
|
||||||
export interface InputOptions {
|
export interface InputOptions {
|
||||||
/** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */
|
/** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */
|
||||||
required?: boolean;
|
required?: boolean
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,148 +1,151 @@
|
||||||
import os = require('os');
|
import os = require('os')
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
|
||||||
* Commands
|
* Commands
|
||||||
*
|
*
|
||||||
* Command Format:
|
* Command Format:
|
||||||
* ##[name key=value;key=value]message
|
* ##[name key=value;key=value]message
|
||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
* ##[warning]This is the user warning message
|
* ##[warning]This is the user warning message
|
||||||
* ##[set-secret name=mypassword]definatelyNotAPassword!
|
* ##[set-secret name=mypassword]definatelyNotAPassword!
|
||||||
*/
|
*/
|
||||||
export function _issueCommand(command: string, properties: any, message: string) {
|
export function _issueCommand(
|
||||||
var cmd = new _Command(command, properties, message);
|
command: string,
|
||||||
_writeLine(cmd.toString());
|
properties: any,
|
||||||
|
message: string
|
||||||
|
) {
|
||||||
|
var cmd = new _Command(command, properties, message)
|
||||||
|
_writeLine(cmd.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _issue(name: string, message: string) {
|
export function _issue(name: string, message: string) {
|
||||||
_issueCommand(name, {}, message);
|
_issueCommand(name, {}, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
let CMD_PREFIX = '##[';
|
let CMD_PREFIX = '##['
|
||||||
|
|
||||||
export class _Command {
|
export class _Command {
|
||||||
constructor(command: string, properties: any, message: string) {
|
constructor(command: string, properties: any, message: string) {
|
||||||
if (!command) {
|
if (!command) {
|
||||||
command = 'missing.command';
|
command = 'missing.command'
|
||||||
}
|
|
||||||
|
|
||||||
this.command = command;
|
|
||||||
this.properties = properties;
|
|
||||||
this.message = message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public command: string;
|
this.command = command
|
||||||
public message: string;
|
this.properties = properties
|
||||||
public properties: any;
|
this.message = message
|
||||||
|
}
|
||||||
|
|
||||||
public toString() {
|
public command: string
|
||||||
var cmdStr = CMD_PREFIX + this.command;
|
public message: string
|
||||||
|
public properties: any
|
||||||
|
|
||||||
if (this.properties && Object.keys(this.properties).length > 0) {
|
public toString() {
|
||||||
cmdStr += ' ';
|
var cmdStr = CMD_PREFIX + this.command
|
||||||
for (var key in this.properties) {
|
|
||||||
if (this.properties.hasOwnProperty(key)) {
|
if (this.properties && Object.keys(this.properties).length > 0) {
|
||||||
var val = this.properties[key];
|
cmdStr += ' '
|
||||||
if (val) {
|
for (var key in this.properties) {
|
||||||
// safely append the val - avoid blowing up when attempting to
|
if (this.properties.hasOwnProperty(key)) {
|
||||||
// call .replace() if message is not a string for some reason
|
var val = this.properties[key]
|
||||||
cmdStr += key + '=' + escape('' + (val || '')) + ';';
|
if (val) {
|
||||||
}
|
// safely append the val - avoid blowing up when attempting to
|
||||||
}
|
// call .replace() if message is not a string for some reason
|
||||||
}
|
cmdStr += key + '=' + escape('' + (val || '')) + ';'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
cmdStr += ']';
|
|
||||||
|
|
||||||
// safely append the message - avoid blowing up when attempting to
|
|
||||||
// call .replace() if message is not a string for some reason
|
|
||||||
let message: string = '' + (this.message || '');
|
|
||||||
cmdStr += escapedata(message);
|
|
||||||
|
|
||||||
return cmdStr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmdStr += ']'
|
||||||
|
|
||||||
|
// safely append the message - avoid blowing up when attempting to
|
||||||
|
// call .replace() if message is not a string for some reason
|
||||||
|
let message: string = '' + (this.message || '')
|
||||||
|
cmdStr += escapedata(message)
|
||||||
|
|
||||||
|
return cmdStr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _commandFromString(commandLine: string) {
|
export function _commandFromString(commandLine: string) {
|
||||||
var preLen = CMD_PREFIX.length;
|
var preLen = CMD_PREFIX.length
|
||||||
var lbPos = commandLine.indexOf('[');
|
var lbPos = commandLine.indexOf('[')
|
||||||
var rbPos = commandLine.indexOf(']');
|
var rbPos = commandLine.indexOf(']')
|
||||||
if (lbPos == -1 || rbPos == -1 || rbPos - lbPos < 3) {
|
if (lbPos == -1 || rbPos == -1 || rbPos - lbPos < 3) {
|
||||||
throw new Error('Invalid command brackets');
|
throw new Error('Invalid command brackets')
|
||||||
}
|
}
|
||||||
var cmdInfo = commandLine.substring(lbPos + 1, rbPos);
|
var cmdInfo = commandLine.substring(lbPos + 1, rbPos)
|
||||||
var spaceIdx = cmdInfo.indexOf(' ');
|
var spaceIdx = cmdInfo.indexOf(' ')
|
||||||
|
|
||||||
var command = cmdInfo;
|
var command = cmdInfo
|
||||||
var properties: {[key: string]: string} = {};
|
var properties: {[key: string]: string} = {}
|
||||||
|
|
||||||
if (spaceIdx > 0) {
|
if (spaceIdx > 0) {
|
||||||
command = cmdInfo.trim().substring(0, spaceIdx);
|
command = cmdInfo.trim().substring(0, spaceIdx)
|
||||||
var propSection = cmdInfo.trim().substring(spaceIdx+1);
|
var propSection = cmdInfo.trim().substring(spaceIdx + 1)
|
||||||
|
|
||||||
var propLines: string[] = propSection.split(';');
|
var propLines: string[] = propSection.split(';')
|
||||||
propLines.forEach(function (propLine: string) {
|
propLines.forEach(function(propLine: string) {
|
||||||
propLine = propLine.trim();
|
propLine = propLine.trim()
|
||||||
if (propLine.length > 0) {
|
if (propLine.length > 0) {
|
||||||
var eqIndex = propLine.indexOf('=');
|
var eqIndex = propLine.indexOf('=')
|
||||||
if (eqIndex == -1){
|
if (eqIndex == -1) {
|
||||||
throw new Error('Invalid property: ' + propLine);
|
throw new Error('Invalid property: ' + propLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
var key: string = propLine.substring(0, eqIndex);
|
var key: string = propLine.substring(0, eqIndex)
|
||||||
var val: string = propLine.substring(eqIndex+1);
|
var val: string = propLine.substring(eqIndex + 1)
|
||||||
|
|
||||||
properties[key] = unescape(val);
|
properties[key] = unescape(val)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let msg: string = unescapedata(commandLine.substring(rbPos + 1));
|
let msg: string = unescapedata(commandLine.substring(rbPos + 1))
|
||||||
var cmd = new _Command(command, properties, msg);
|
var cmd = new _Command(command, properties, msg)
|
||||||
return cmd;
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapedata(s: string) : string {
|
function escapedata(s: string): string {
|
||||||
return s.replace(/\r/g, '%0D')
|
return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A')
|
||||||
.replace(/\n/g, '%0A');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function unescapedata(s: string) : string {
|
function unescapedata(s: string): string {
|
||||||
return s.replace(/%0D/g, '\r')
|
return s.replace(/%0D/g, '\r').replace(/%0A/g, '\n')
|
||||||
.replace(/%0A/g, '\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function escape(s: string) : string {
|
function escape(s: string): string {
|
||||||
return s.replace(/\r/g, '%0D')
|
return s
|
||||||
.replace(/\n/g, '%0A')
|
.replace(/\r/g, '%0D')
|
||||||
.replace(/]/g, '%5D')
|
.replace(/\n/g, '%0A')
|
||||||
.replace(/;/g, '%3B');
|
.replace(/]/g, '%5D')
|
||||||
|
.replace(/;/g, '%3B')
|
||||||
}
|
}
|
||||||
|
|
||||||
function unescape(s: string) : string {
|
function unescape(s: string): string {
|
||||||
return s.replace(/%0D/g, '\r')
|
return s
|
||||||
.replace(/%0A/g, '\n')
|
.replace(/%0D/g, '\r')
|
||||||
.replace(/%5D/g, ']')
|
.replace(/%0A/g, '\n')
|
||||||
.replace(/%3B/g, ';');
|
.replace(/%5D/g, ']')
|
||||||
|
.replace(/%3B/g, ';')
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
// Streams: allow to override the stream
|
// Streams: allow to override the stream
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
|
|
||||||
let _outStream = process.stdout;
|
let _outStream = process.stdout
|
||||||
let _errStream = process.stderr;
|
let _errStream = process.stderr
|
||||||
|
|
||||||
export function _writeLine(str: string): void {
|
export function _writeLine(str: string): void {
|
||||||
_outStream.write(str + os.EOL);
|
_outStream.write(str + os.EOL)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _setStdStream(stdStream: NodeJS.WriteStream): void {
|
export function _setStdStream(stdStream: NodeJS.WriteStream): void {
|
||||||
_outStream = stdStream;
|
_outStream = stdStream
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _setErrStream(errStream: NodeJS.WriteStream): void {
|
export function _setErrStream(errStream: NodeJS.WriteStream): void {
|
||||||
_errStream = errStream;
|
_errStream = errStream
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue