mirror of https://github.com/actions/toolkit
starting on core
parent
917c389219
commit
780a5985b4
|
@ -1,11 +1,58 @@
|
||||||
# `@actions/core`
|
# `@actions/core`
|
||||||
|
|
||||||
> TODO: description
|
> Core functions for setting results, logging, registering secrets and exporting variables across actions
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
const core = require('@actions/core');
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
export function exportVariable(name: string, val: string, options?:im.ExportOptions);
|
||||||
|
|
||||||
// TODO: DEMONSTRATE API
|
/**
|
||||||
|
* registers a secret which will get masked from logs
|
||||||
|
* @param val value of the secret
|
||||||
|
*/
|
||||||
|
export function setSecret(val: string);
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// Results
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the action status to neutral
|
||||||
|
*/
|
||||||
|
export function setNeutral();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the action status to failed.
|
||||||
|
* When the action exits it will be with an exit code of 1
|
||||||
|
* @param message add error issue message
|
||||||
|
*/
|
||||||
|
export function setFailed(message: string);
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// Logging Commands
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes debug message to user log
|
||||||
|
* @param message debug message
|
||||||
|
*/
|
||||||
|
export function debug(message: string);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an error issue
|
||||||
|
* @param message error issue message
|
||||||
|
*/
|
||||||
|
export function error(message: string);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an warning issue
|
||||||
|
* @param message warning issue message
|
||||||
|
*/
|
||||||
|
export function warning(message: string);
|
||||||
```
|
```
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"name": "@actions/core",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": {
|
||||||
|
"version": "12.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.2.tgz",
|
||||||
|
"integrity": "sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@actions/core",
|
"name": "@actions/core",
|
||||||
"version": "1.0.0",
|
"version": "0.1.0",
|
||||||
"description": "Actions core lib",
|
"description": "Actions core lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"core",
|
"core",
|
||||||
|
@ -30,5 +30,8 @@
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^12.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
import im = require('./interfaces');
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
export function exportVariable(name: string, val: string, options?:im.ExportOptions) {
|
||||||
|
process.env[name] = val;
|
||||||
|
let props = {'name': name, 'isSecret': options? options.isSecret : false};
|
||||||
|
intm._issueCommand('set-variable', props, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* registers a secret which will get masked from logs
|
||||||
|
* @param val value of the secret
|
||||||
|
*/
|
||||||
|
export function setSecret(val: string) {
|
||||||
|
intm._issueCommand('set-secret', {}, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// Results
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the action status to neutral
|
||||||
|
*/
|
||||||
|
export function setNeutral() {
|
||||||
|
process.exitCode = im.ExitCode.Neutral;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the action status to failed.
|
||||||
|
* When the action exits it will be with an exit code of 1
|
||||||
|
* @param message add error issue message
|
||||||
|
*/
|
||||||
|
export function setFailed(message: string) {
|
||||||
|
process.exitCode = im.ExitCode.Failure;
|
||||||
|
error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
// Logging Commands
|
||||||
|
//
|
||||||
|
// error and warning issues do not take FileDetails because while possible,
|
||||||
|
// that's typically reserved for the agent and the problem matchers.
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes debug message to user log
|
||||||
|
* @param message debug message
|
||||||
|
*/
|
||||||
|
export function debug(message: string) {
|
||||||
|
intm._issueCommand('debug', {}, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an error issue
|
||||||
|
* @param message error issue message
|
||||||
|
*/
|
||||||
|
export function error(message: string) {
|
||||||
|
intm._issue('error', message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an warning issue
|
||||||
|
* @param message warning issue message
|
||||||
|
*/
|
||||||
|
export function warning(message: string) {
|
||||||
|
intm._issue('warning', message);
|
||||||
|
}
|
|
@ -1,17 +1,5 @@
|
||||||
export interface FileDetails {
|
|
||||||
/**
|
|
||||||
* Full path to the file causing the issue.
|
|
||||||
* Note: the agent will translate to the proper repo when posting
|
|
||||||
* the issue back to the timeline
|
|
||||||
*/
|
|
||||||
File: string,
|
|
||||||
Line: number,
|
|
||||||
Column: number
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The code to exit an action
|
* The code to exit an action
|
||||||
* Spec: https://github.com/github/dreamlifter/blob/master/docs/actions-model.md#exit-codes
|
|
||||||
*/
|
*/
|
||||||
export enum ExitCode {
|
export enum ExitCode {
|
||||||
/**
|
/**
|
||||||
|
@ -29,3 +17,11 @@ export enum ExitCode {
|
||||||
*/
|
*/
|
||||||
Neutral = 78
|
Neutral = 78
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for exportVariable options
|
||||||
|
*/
|
||||||
|
export interface ExportOptions {
|
||||||
|
/** Optional. Whether the variable should be marked as secret (will be masked from logs). Defaults to false */
|
||||||
|
isSecret?: boolean;
|
||||||
|
}
|
|
@ -3,16 +3,15 @@ import os = require('os');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commands
|
* Commands
|
||||||
* Spec: https://github.com/github/dreamlifter/blob/master/docs/actions-model.md#logging-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]definitelyNotAPassword!
|
* ##[set-secret name=mypassword]definatelyNotAPassword!
|
||||||
*/
|
*/
|
||||||
export function _issueCommand(command: string, properties: {[key: string]: string}, message: string) {
|
export function _issueCommand(command: string, properties: any, message: string) {
|
||||||
var cmd = new _Command(command, properties, message);
|
var cmd = new _Command(command, properties, message);
|
||||||
_writeLine(cmd.toString());
|
_writeLine(cmd.toString());
|
||||||
}
|
}
|
||||||
|
@ -67,6 +66,7 @@ export class _Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _commandFromString(commandLine: string) {
|
export function _commandFromString(commandLine: string) {
|
||||||
|
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) {
|
||||||
|
|
|
@ -1,73 +0,0 @@
|
||||||
import im = require('./interfaces');
|
|
||||||
import intm = require('./internal');
|
|
||||||
import process = require('process');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for exportVariable options
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fail the action
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
export function setFailure(message: string): void {
|
|
||||||
process.exitCode = im.ExitCode.Failure;
|
|
||||||
error(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
// Logging Commands
|
|
||||||
// https://github.com/github/dreamlifter/blob/master/docs/actions-model.md#logging-commands
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
Loading…
Reference in New Issue