UNPKG

12.6 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 return file_command_1.issueFileCommand('ENV', file_command_1.prepareKeyValueMessage(name, val));
67 }
68 command_1.issueCommand('set-env', { name }, convertedVal);
69}
70exports.exportVariable = exportVariable;
71/**
72 * Registers a secret which will get masked from logs
73 * @param secret value of the secret
74 */
75function setSecret(secret) {
76 command_1.issueCommand('add-mask', {}, secret);
77}
78exports.setSecret = setSecret;
79/**
80 * Prepends inputPath to the PATH (for this action and future actions)
81 * @param inputPath
82 */
83function addPath(inputPath) {
84 const filePath = process.env['GITHUB_PATH'] || '';
85 if (filePath) {
86 file_command_1.issueFileCommand('PATH', inputPath);
87 }
88 else {
89 command_1.issueCommand('add-path', {}, inputPath);
90 }
91 process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
92}
93exports.addPath = addPath;
94/**
95 * Gets the value of an input.
96 * Unless trimWhitespace is set to false in InputOptions, the value is also trimmed.
97 * Returns an empty string if the value is not defined.
98 *
99 * @param name name of the input to get
100 * @param options optional. See InputOptions.
101 * @returns string
102 */
103function getInput(name, options) {
104 const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || '';
105 if (options && options.required && !val) {
106 throw new Error(`Input required and not supplied: ${name}`);
107 }
108 if (options && options.trimWhitespace === false) {
109 return val;
110 }
111 return val.trim();
112}
113exports.getInput = getInput;
114/**
115 * Gets the values of an multiline input. Each value is also trimmed.
116 *
117 * @param name name of the input to get
118 * @param options optional. See InputOptions.
119 * @returns string[]
120 *
121 */
122function getMultilineInput(name, options) {
123 const inputs = getInput(name, options)
124 .split('\n')
125 .filter(x => x !== '');
126 if (options && options.trimWhitespace === false) {
127 return inputs;
128 }
129 return inputs.map(input => input.trim());
130}
131exports.getMultilineInput = getMultilineInput;
132/**
133 * Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
134 * Support boolean input list: `true | True | TRUE | false | False | FALSE` .
135 * The return value is also in boolean type.
136 * ref: https://yaml.org/spec/1.2/spec.html#id2804923
137 *
138 * @param name name of the input to get
139 * @param options optional. See InputOptions.
140 * @returns boolean
141 */
142function getBooleanInput(name, options) {
143 const trueValue = ['true', 'True', 'TRUE'];
144 const falseValue = ['false', 'False', 'FALSE'];
145 const val = getInput(name, options);
146 if (trueValue.includes(val))
147 return true;
148 if (falseValue.includes(val))
149 return false;
150 throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` +
151 `Support boolean input list: \`true | True | TRUE | false | False | FALSE\``);
152}
153exports.getBooleanInput = getBooleanInput;
154/**
155 * Sets the value of an output.
156 *
157 * @param name name of the output to set
158 * @param value value to store. Non-string values will be converted to a string via JSON.stringify
159 */
160// eslint-disable-next-line @typescript-eslint/no-explicit-any
161function setOutput(name, value) {
162 const filePath = process.env['GITHUB_OUTPUT'] || '';
163 if (filePath) {
164 return file_command_1.issueFileCommand('OUTPUT', file_command_1.prepareKeyValueMessage(name, value));
165 }
166 process.stdout.write(os.EOL);
167 command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value));
168}
169exports.setOutput = setOutput;
170/**
171 * Enables or disables the echoing of commands into stdout for the rest of the step.
172 * Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set.
173 *
174 */
175function setCommandEcho(enabled) {
176 command_1.issue('echo', enabled ? 'on' : 'off');
177}
178exports.setCommandEcho = setCommandEcho;
179//-----------------------------------------------------------------------
180// Results
181//-----------------------------------------------------------------------
182/**
183 * Sets the action status to failed.
184 * When the action exits it will be with an exit code of 1
185 * @param message add error issue message
186 */
187function setFailed(message) {
188 process.exitCode = ExitCode.Failure;
189 error(message);
190}
191exports.setFailed = setFailed;
192//-----------------------------------------------------------------------
193// Logging Commands
194//-----------------------------------------------------------------------
195/**
196 * Gets whether Actions Step Debug is on or not
197 */
198function isDebug() {
199 return process.env['RUNNER_DEBUG'] === '1';
200}
201exports.isDebug = isDebug;
202/**
203 * Writes debug message to user log
204 * @param message debug message
205 */
206function debug(message) {
207 command_1.issueCommand('debug', {}, message);
208}
209exports.debug = debug;
210/**
211 * Adds an error issue
212 * @param message error issue message. Errors will be converted to string via toString()
213 * @param properties optional properties to add to the annotation.
214 */
215function error(message, properties = {}) {
216 command_1.issueCommand('error', utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
217}
218exports.error = error;
219/**
220 * Adds a warning issue
221 * @param message warning issue message. Errors will be converted to string via toString()
222 * @param properties optional properties to add to the annotation.
223 */
224function warning(message, properties = {}) {
225 command_1.issueCommand('warning', utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
226}
227exports.warning = warning;
228/**
229 * Adds a notice issue
230 * @param message notice issue message. Errors will be converted to string via toString()
231 * @param properties optional properties to add to the annotation.
232 */
233function notice(message, properties = {}) {
234 command_1.issueCommand('notice', utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
235}
236exports.notice = notice;
237/**
238 * Writes info to log with console.log.
239 * @param message info message
240 */
241function info(message) {
242 process.stdout.write(message + os.EOL);
243}
244exports.info = info;
245/**
246 * Begin an output group.
247 *
248 * Output until the next `groupEnd` will be foldable in this group
249 *
250 * @param name The name of the output group
251 */
252function startGroup(name) {
253 command_1.issue('group', name);
254}
255exports.startGroup = startGroup;
256/**
257 * End an output group.
258 */
259function endGroup() {
260 command_1.issue('endgroup');
261}
262exports.endGroup = endGroup;
263/**
264 * Wrap an asynchronous function call in a group.
265 *
266 * Returns the same type as the function itself.
267 *
268 * @param name The name of the group
269 * @param fn The function to wrap in the group
270 */
271function group(name, fn) {
272 return __awaiter(this, void 0, void 0, function* () {
273 startGroup(name);
274 let result;
275 try {
276 result = yield fn();
277 }
278 finally {
279 endGroup();
280 }
281 return result;
282 });
283}
284exports.group = group;
285//-----------------------------------------------------------------------
286// Wrapper action state
287//-----------------------------------------------------------------------
288/**
289 * Saves state for current action, the state can only be retrieved by this action's post job execution.
290 *
291 * @param name name of the state to store
292 * @param value value to store. Non-string values will be converted to a string via JSON.stringify
293 */
294// eslint-disable-next-line @typescript-eslint/no-explicit-any
295function saveState(name, value) {
296 const filePath = process.env['GITHUB_STATE'] || '';
297 if (filePath) {
298 return file_command_1.issueFileCommand('STATE', file_command_1.prepareKeyValueMessage(name, value));
299 }
300 command_1.issueCommand('save-state', { name }, utils_1.toCommandValue(value));
301}
302exports.saveState = saveState;
303/**
304 * Gets the value of an state set by this action's main execution.
305 *
306 * @param name name of the state to get
307 * @returns string
308 */
309function getState(name) {
310 return process.env[`STATE_${name}`] || '';
311}
312exports.getState = getState;
313function getIDToken(aud) {
314 return __awaiter(this, void 0, void 0, function* () {
315 return yield oidc_utils_1.OidcClient.getIDToken(aud);
316 });
317}
318exports.getIDToken = getIDToken;
319/**
320 * Summary exports
321 */
322var summary_1 = require("./summary");
323Object.defineProperty(exports, "summary", { enumerable: true, get: function () { return summary_1.summary; } });
324/**
325 * @deprecated use core.summary
326 */
327var summary_2 = require("./summary");
328Object.defineProperty(exports, "markdownSummary", { enumerable: true, get: function () { return summary_2.markdownSummary; } });
329/**
330 * Path exports
331 */
332var path_utils_1 = require("./path-utils");
333Object.defineProperty(exports, "toPosixPath", { enumerable: true, get: function () { return path_utils_1.toPosixPath; } });
334Object.defineProperty(exports, "toWin32Path", { enumerable: true, get: function () { return path_utils_1.toWin32Path; } });
335Object.defineProperty(exports, "toPlatformPath", { enumerable: true, get: function () { return path_utils_1.toPlatformPath; } });
336//# sourceMappingURL=core.js.map
\No newline at end of file