mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-01 07:13:16 +08:00
Be more lenient in accepting command inputs (#405)
* Be more lenient in accepting command inputs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {issue, issueCommand} from './command'
|
||||
import {issue, issueCommand, toCommandValue} from './command'
|
||||
|
||||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
@@ -33,11 +33,13 @@ export enum ExitCode {
|
||||
/**
|
||||
* 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 val the value of the variable. Non-string values will be converted to a string via JSON.stringify
|
||||
*/
|
||||
export function exportVariable(name: string, val: string): void {
|
||||
process.env[name] = val
|
||||
issueCommand('set-env', {name}, val)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function exportVariable(name: string, val: any): void {
|
||||
const convertedVal = toCommandValue(val)
|
||||
process.env[name] = convertedVal
|
||||
issueCommand('set-env', {name}, convertedVal)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,9 +80,10 @@ export function getInput(name: string, options?: InputOptions): string {
|
||||
* Sets the value of an output.
|
||||
*
|
||||
* @param name name of the output to set
|
||||
* @param value value to store
|
||||
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
|
||||
*/
|
||||
export function setOutput(name: string, value: string): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function setOutput(name: string, value: any): void {
|
||||
issueCommand('set-output', {name}, value)
|
||||
}
|
||||
|
||||
@@ -93,8 +96,9 @@ export function setOutput(name: string, value: string): void {
|
||||
* When the action exits it will be with an exit code of 1
|
||||
* @param message add error issue message
|
||||
*/
|
||||
export function setFailed(message: string): void {
|
||||
export function setFailed(message: string | Error): void {
|
||||
process.exitCode = ExitCode.Failure
|
||||
|
||||
error(message)
|
||||
}
|
||||
|
||||
@@ -119,18 +123,18 @@ export function debug(message: string): void {
|
||||
|
||||
/**
|
||||
* Adds an error issue
|
||||
* @param message error issue message
|
||||
* @param message error issue message. Errors will be converted to string via toString()
|
||||
*/
|
||||
export function error(message: string): void {
|
||||
issue('error', message)
|
||||
export function error(message: string | Error): void {
|
||||
issue('error', message instanceof Error ? message.toString() : message)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an warning issue
|
||||
* @param message warning issue message
|
||||
* @param message warning issue message. Errors will be converted to string via toString()
|
||||
*/
|
||||
export function warning(message: string): void {
|
||||
issue('warning', message)
|
||||
export function warning(message: string | Error): void {
|
||||
issue('warning', message instanceof Error ? message.toString() : message)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,9 +193,10 @@ export async function group<T>(name: string, fn: () => Promise<T>): Promise<T> {
|
||||
* Saves state for current action, the state can only be retrieved by this action's post job execution.
|
||||
*
|
||||
* @param name name of the state to store
|
||||
* @param value value to store
|
||||
* @param value value to store. Non-string values will be converted to a string via JSON.stringify
|
||||
*/
|
||||
export function saveState(name: string, value: string): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function saveState(name: string, value: any): void {
|
||||
issueCommand('save-state', {name}, value)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user