UNPKG

11.3 kBJavaScriptView Raw
1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5}) : (function(o, m, k, k2) {
6 if (k2 === undefined) k2 = k;
7 o[k2] = m[k];
8}));
9var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 Object.defineProperty(o, "default", { enumerable: true, value: v });
11}) : function(o, v) {
12 o["default"] = v;
13});
14var __importStar = (this && this.__importStar) || function (mod) {
15 if (mod && mod.__esModule) return mod;
16 var result = {};
17 if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 __setModuleDefault(result, mod);
19 return result;
20};
21var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23 return new (P || (P = Promise))(function (resolve, reject) {
24 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27 step((generator = generator.apply(thisArg, _arguments || [])).next());
28 });
29};
30Object.defineProperty(exports, "__esModule", { value: true });
31exports.getIDToken = exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.notice = exports.warning = exports.error = exports.debug = exports.isDebug = exports.setFailed = exports.setCommandEcho = exports.setOutput = exports.getBooleanInput = exports.getMultilineInput = exports.getInput = exports.addPath = exports.setSecret = exports.exportVariable = exports.ExitCode = void 0;
32const command_1 = require("./command");
33const file_command_1 = require("./file-command");
34const utils_1 = require("./utils");
35const os = __importStar(require("os"));
36const path = __importStar(require("path"));
37const oidc_utils_1 = require("./oidc-utils");
38/**
39 * The code to exit an action
40 */
41var ExitCode;
42(function (ExitCode) {
43 /**
44 * A code indicating that the action was successful
45 */
46 ExitCode[ExitCode["Success"] = 0] = "Success";
47 /**
48 * A code indicating that the action was a failure
49 */
50 ExitCode[ExitCode["Failure"] = 1] = "Failure";
51})(ExitCode = exports.ExitCode || (exports.ExitCode = {}));
52//-----------------------------------------------------------------------
53// Variables
54//-----------------------------------------------------------------------
55/**
56 * Sets env variable for this action and future actions in the job
57 * @param name the name of the variable to set
58 * @param val the value of the variable. Non-string values will be converted to a string via JSON.stringify
59 */
60// eslint-disable-next-line @typescript-eslint/no-explicit-any
61function exportVariable(name, val) {
62 const convertedVal = utils_1.toCommandValue(val);
63 process.env[name] = convertedVal;
64 const filePath = process.env['GITHUB_ENV'] || '';
65 if (filePath) {
66 const delimiter = '_GitHubActionsFileCommandDelimeter_';
67 const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
68 file_command_1.issueCommand('ENV', commandValue);
69 }
70 else {
71 command_1.issueCommand('set-env', { name }, convertedVal);
72 }
73}
74exports.exportVariable = exportVariable;
75/**
76 * Registers a secret which will get masked from logs
77 * @param secret value of the secret
78 */
79function setSecret(secret) {
80 command_1.issueCommand('add-mask', {}, secret);
81}
82exports.setSecret = setSecret;
83/**
84 * Prepends inputPath to the PATH (for this action and future actions)
85 * @param inputPath
86 */
87function addPath(inputPath) {
88 const filePath = process.env['GITHUB_PATH'] || '';
89 if (filePath) {
90 file_command_1.issueCommand('PATH', inputPath);
91 }
92 else {
93 command_1.issueCommand('add-path', {}, inputPath);
94 }
95 process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
96}
97exports.addPath = addPath;
98/**
99 * Gets the value of an input.
100 * Unless trimWhitespace is set to false in InputOptions, the value is also trimmed.
101 * Returns an empty string if the value is not defined.
102 *
103 * @param name name of the input to get
104 * @param options optional. See InputOptions.
105 * @returns string
106 */
107function getInput(name, options) {
108 const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '';
109 if (options && options.required && !val) {
110 throw new Error(`Input required and not supplied: ${name}`);
111 }
112 if (options && options.trimWhitespace === false) {
113 return val;
114 }
115 return val.trim();
116}
117exports.getInput = getInput;
118/**
119 * Gets the values of an multiline input. Each value is also trimmed.
120 *
121 * @param name name of the input to get
122 * @param options optional. See InputOptions.
123 * @returns string[]
124 *
125 */
126function getMultilineInput(name, options) {
127 const inputs = getInput(name, options)
128 .split('\n')
129 .filter(x => x !== '');
130 return inputs;
131}
132exports.getMultilineInput = getMultilineInput;
133/**
134 * Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
135 * Support boolean input list: `true | True | TRUE | false | False | FALSE` .
136 * The return value is also in boolean type.
137 * ref: https://yaml.org/spec/1.2/spec.html#id2804923
138 *
139 * @param name name of the input to get
140 * @param options optional. See InputOptions.
141 * @returns boolean
142 */
143function getBooleanInput(name, options) {
144 const trueValue = ['true', 'True', 'TRUE'];
145 const falseValue = ['false', 'False', 'FALSE'];
146 const val = getInput(name, options);
147 if (trueValue.includes(val))
148 return true;
149 if (falseValue.includes(val))
150 return false;
151 throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` +
152 `Support boolean input list: \`true | True | TRUE | false | False | FALSE\``);
153}
154exports.getBooleanInput = getBooleanInput;
155/**
156 * Sets the value of an output.
157 *
158 * @param name name of the output to set
159 * @param value value to store. Non-string values will be converted to a string via JSON.stringify
160 */
161// eslint-disable-next-line @typescript-eslint/no-explicit-any
162function setOutput(name, value) {
163 process.stdout.write(os.EOL);
164 command_1.issueCommand('set-output', { name }, value);
165}
166exports.setOutput = setOutput;
167/**
168 * Enables or disables the echoing of commands into stdout for the rest of the step.
169 * Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set.
170 *
171 */
172function setCommandEcho(enabled) {
173 command_1.issue('echo', enabled ? 'on' : 'off');
174}
175exports.setCommandEcho = setCommandEcho;
176//-----------------------------------------------------------------------
177// Results
178//-----------------------------------------------------------------------
179/**
180 * Sets the action status to failed.
181 * When the action exits it will be with an exit code of 1
182 * @param message add error issue message
183 */
184function setFailed(message) {
185 process.exitCode = ExitCode.Failure;
186 error(message);
187}
188exports.setFailed = setFailed;
189//-----------------------------------------------------------------------
190// Logging Commands
191//-----------------------------------------------------------------------
192/**
193 * Gets whether Actions Step Debug is on or not
194 */
195function isDebug() {
196 return process.env['RUNNER_DEBUG'] === '1';
197}
198exports.isDebug = isDebug;
199/**
200 * Writes debug message to user log
201 * @param message debug message
202 */
203function debug(message) {
204 command_1.issueCommand('debug', {}, message);
205}
206exports.debug = debug;
207/**
208 * Adds an error issue
209 * @param message error issue message. Errors will be converted to string via toString()
210 * @param properties optional properties to add to the annotation.
211 */
212function error(message, properties = {}) {
213 command_1.issueCommand('error', utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
214}
215exports.error = error;
216/**
217 * Adds a warning issue
218 * @param message warning issue message. Errors will be converted to string via toString()
219 * @param properties optional properties to add to the annotation.
220 */
221function warning(message, properties = {}) {
222 command_1.issueCommand('warning', utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
223}
224exports.warning = warning;
225/**
226 * Adds a notice issue
227 * @param message notice issue message. Errors will be converted to string via toString()
228 * @param properties optional properties to add to the annotation.
229 */
230function notice(message, properties = {}) {
231 command_1.issueCommand('notice', utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
232}
233exports.notice = notice;
234/**
235 * Writes info to log with console.log.
236 * @param message info message
237 */
238function info(message) {
239 process.stdout.write(message + os.EOL);
240}
241exports.info = info;
242/**
243 * Begin an output group.
244 *
245 * Output until the next `groupEnd` will be foldable in this group
246 *
247 * @param name The name of the output group
248 */
249function startGroup(name) {
250 command_1.issue('group', name);
251}
252exports.startGroup = startGroup;
253/**
254 * End an output group.
255 */
256function endGroup() {
257 command_1.issue('endgroup');
258}
259exports.endGroup = endGroup;
260/**
261 * Wrap an asynchronous function call in a group.
262 *
263 * Returns the same type as the function itself.
264 *
265 * @param name The name of the group
266 * @param fn The function to wrap in the group
267 */
268function group(name, fn) {
269 return __awaiter(this, void 0, void 0, function* () {
270 startGroup(name);
271 let result;
272 try {
273 result = yield fn();
274 }
275 finally {
276 endGroup();
277 }
278 return result;
279 });
280}
281exports.group = group;
282//-----------------------------------------------------------------------
283// Wrapper action state
284//-----------------------------------------------------------------------
285/**
286 * Saves state for current action, the state can only be retrieved by this action's post job execution.
287 *
288 * @param name name of the state to store
289 * @param value value to store. Non-string values will be converted to a string via JSON.stringify
290 */
291// eslint-disable-next-line @typescript-eslint/no-explicit-any
292function saveState(name, value) {
293 command_1.issueCommand('save-state', { name }, value);
294}
295exports.saveState = saveState;
296/**
297 * Gets the value of an state set by this action's main execution.
298 *
299 * @param name name of the state to get
300 * @returns string
301 */
302function getState(name) {
303 return process.env[`STATE_${name}`] || '';
304}
305exports.getState = getState;
306function getIDToken(aud) {
307 return __awaiter(this, void 0, void 0, function* () {
308 return yield oidc_utils_1.OidcClient.getIDToken(aud);
309 });
310}
311exports.getIDToken = getIDToken;
312//# sourceMappingURL=core.js.map
\No newline at end of file