From 917c389219cf89dcc3bb0068f8f5b16d2b282627 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Thu, 16 May 2019 17:16:39 -0400 Subject: [PATCH] Match core to spec (still work to do) --- packages/core/__tests__/lib.test.ts | 24 +++++++++++- packages/core/package.json | 2 +- packages/core/src/internal.ts | 3 +- packages/core/src/lib.ts | 61 ++++++++++++++++++----------- 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/packages/core/__tests__/lib.test.ts b/packages/core/__tests__/lib.test.ts index 3917550c..012d0963 100644 --- a/packages/core/__tests__/lib.test.ts +++ b/packages/core/__tests__/lib.test.ts @@ -3,8 +3,28 @@ import * as core from '../src/lib' describe('@actions/core', () => { - it('needs tests', () => { - + it('tests exportVariable', () => { + // TODO + }); + + it('tests getInput', () => { + // TODO + }); + + it('tests setFailure', () => { + // TODO + }); + + it('tests error', () => { + // TODO + }); + + it('tests warning', () => { + // TODO + }); + + it('tests debug', () => { + // TODO }); }); diff --git a/packages/core/package.json b/packages/core/package.json index 1a922ff2..52200e5b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -7,7 +7,7 @@ "actions" ], "author": "Bryan MacFarlane ", - "homepage": "https://github.com/actions/toolkit/tree/master/packages/io", + "homepage": "https://github.com/actions/toolkit/tree/master/packages/core", "license": "MIT", "main": "lib/lib.js", "directories": { diff --git a/packages/core/src/internal.ts b/packages/core/src/internal.ts index 1d2e867c..38a7fd8e 100644 --- a/packages/core/src/internal.ts +++ b/packages/core/src/internal.ts @@ -10,7 +10,7 @@ import os = require('os'); * * Examples: * ##[warning]This is the user warning message - * ##[set-secret name=mypassword]definatelyNotAPassword! + * ##[set-secret name=mypassword]definitelyNotAPassword! */ export function _issueCommand(command: string, properties: {[key: string]: string}, message: string) { var cmd = new _Command(command, properties, message); @@ -67,7 +67,6 @@ export class _Command { } export function _commandFromString(commandLine: string) { - var preLen = CMD_PREFIX.length; var lbPos = commandLine.indexOf('['); var rbPos = commandLine.indexOf(']'); if (lbPos == -1 || rbPos == -1 || rbPos - lbPos < 3) { diff --git a/packages/core/src/lib.ts b/packages/core/src/lib.ts index 6b662560..68e97094 100644 --- a/packages/core/src/lib.ts +++ b/packages/core/src/lib.ts @@ -3,33 +3,53 @@ import intm = require('./internal'); import process = require('process'); /** - * 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 + * Interface for exportVariable options */ -export function setVariable(name: string, val: string) { +export interface ExportOptions { + /** Optional. Whether the variable should be marked as secret (will be masked from logs). Defaults to false */ + isSecret?: boolean; +} + +/** + * 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 + * @param options optional. See ExportOptions. + */ +export function exportVariable(name: string, val: string, options?: ExportOptions): void { + if (options && options.isSecret) { + intm._issueCommand('set-secret', {'name': name}, val); + } process.env[name] = val; intm._issueCommand('set-variable', {'name': name}, val); } /** - * sets a variable which will get masked from logs - * @param name name of the secret variable - * @param val value of the secret variable + * Interface for getInput options */ -export function setSecret(name: string, val: string) { - intm._issueCommand('set-secret', {'name': name}, val); - setVariable(name, val); -} +export interface InputOptions { + /** Optional. Whether the input is required. If required and not present, will throw. Defaults to false */ + required?: boolean; +} + +/** + * 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?: InputOptions): string | undefined { + // TODO - how are we passing in actions inputs? + return ''; +} -//----------------------------------------------------------------------- -// Results -//----------------------------------------------------------------------- /** * fail the action * @param message */ -export function fail(message: string) { +export function setFailure(message: string): void { process.exitCode = im.ExitCode.Failure; error(message); } @@ -38,19 +58,16 @@ export function fail(message: string) { // Logging Commands // https://github.com/github/dreamlifter/blob/master/docs/actions-model.md#logging-commands // -// error and warning issues do not take FileDetails because while possible, -// that's typically reserved for the agent and the problem matchers. -// //----------------------------------------------------------------------- -export function addPath(path: string) { - intm._issueCommand('add-path', {}, path); -} - export function error(message: string) { intm._issue('error', message); } export function warning(message: string) { intm._issue('warning', message); +} + +export function debug(message: string): void { + intm._issue('debug', message); } \ No newline at end of file