Skip to content

Commit 4b4d123

Browse files
authored
Merge pull request #616 from peter-evans/update-distribution
Update distribution
2 parents ec774dd + 7b49fc1 commit 4b4d123

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

dist/index.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ const file_command_1 = __nccwpck_require__(717);
307307
const utils_1 = __nccwpck_require__(5278);
308308
const os = __importStar(__nccwpck_require__(2037));
309309
const path = __importStar(__nccwpck_require__(1017));
310-
const uuid_1 = __nccwpck_require__(5840);
311310
const oidc_utils_1 = __nccwpck_require__(8041);
312311
/**
313312
* The code to exit an action
@@ -337,20 +336,9 @@ function exportVariable(name, val) {
337336
process.env[name] = convertedVal;
338337
const filePath = process.env['GITHUB_ENV'] || '';
339338
if (filePath) {
340-
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
341-
// These should realistically never happen, but just in case someone finds a way to exploit uuid generation let's not allow keys or values that contain the delimiter.
342-
if (name.includes(delimiter)) {
343-
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
344-
}
345-
if (convertedVal.includes(delimiter)) {
346-
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
347-
}
348-
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
349-
file_command_1.issueCommand('ENV', commandValue);
350-
}
351-
else {
352-
command_1.issueCommand('set-env', { name }, convertedVal);
339+
return file_command_1.issueFileCommand('ENV', file_command_1.prepareKeyValueMessage(name, val));
353340
}
341+
command_1.issueCommand('set-env', { name }, convertedVal);
354342
}
355343
exports.exportVariable = exportVariable;
356344
/**
@@ -368,7 +356,7 @@ exports.setSecret = setSecret;
368356
function addPath(inputPath) {
369357
const filePath = process.env['GITHUB_PATH'] || '';
370358
if (filePath) {
371-
file_command_1.issueCommand('PATH', inputPath);
359+
file_command_1.issueFileCommand('PATH', inputPath);
372360
}
373361
else {
374362
command_1.issueCommand('add-path', {}, inputPath);
@@ -408,7 +396,10 @@ function getMultilineInput(name, options) {
408396
const inputs = getInput(name, options)
409397
.split('\n')
410398
.filter(x => x !== '');
411-
return inputs;
399+
if (options && options.trimWhitespace === false) {
400+
return inputs;
401+
}
402+
return inputs.map(input => input.trim());
412403
}
413404
exports.getMultilineInput = getMultilineInput;
414405
/**
@@ -441,8 +432,12 @@ exports.getBooleanInput = getBooleanInput;
441432
*/
442433
// eslint-disable-next-line @typescript-eslint/no-explicit-any
443434
function setOutput(name, value) {
435+
const filePath = process.env['GITHUB_OUTPUT'] || '';
436+
if (filePath) {
437+
return file_command_1.issueFileCommand('OUTPUT', file_command_1.prepareKeyValueMessage(name, value));
438+
}
444439
process.stdout.write(os.EOL);
445-
command_1.issueCommand('set-output', { name }, value);
440+
command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value));
446441
}
447442
exports.setOutput = setOutput;
448443
/**
@@ -571,7 +566,11 @@ exports.group = group;
571566
*/
572567
// eslint-disable-next-line @typescript-eslint/no-explicit-any
573568
function saveState(name, value) {
574-
command_1.issueCommand('save-state', { name }, value);
569+
const filePath = process.env['GITHUB_STATE'] || '';
570+
if (filePath) {
571+
return file_command_1.issueFileCommand('STATE', file_command_1.prepareKeyValueMessage(name, value));
572+
}
573+
command_1.issueCommand('save-state', { name }, utils_1.toCommandValue(value));
575574
}
576575
exports.saveState = saveState;
577576
/**
@@ -637,13 +636,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
637636
return result;
638637
};
639638
Object.defineProperty(exports, "__esModule", ({ value: true }));
640-
exports.issueCommand = void 0;
639+
exports.prepareKeyValueMessage = exports.issueFileCommand = void 0;
641640
// We use any as a valid input type
642641
/* eslint-disable @typescript-eslint/no-explicit-any */
643642
const fs = __importStar(__nccwpck_require__(7147));
644643
const os = __importStar(__nccwpck_require__(2037));
644+
const uuid_1 = __nccwpck_require__(5840);
645645
const utils_1 = __nccwpck_require__(5278);
646-
function issueCommand(command, message) {
646+
function issueFileCommand(command, message) {
647647
const filePath = process.env[`GITHUB_${command}`];
648648
if (!filePath) {
649649
throw new Error(`Unable to find environment variable for file command ${command}`);
@@ -655,7 +655,22 @@ function issueCommand(command, message) {
655655
encoding: 'utf8'
656656
});
657657
}
658-
exports.issueCommand = issueCommand;
658+
exports.issueFileCommand = issueFileCommand;
659+
function prepareKeyValueMessage(key, value) {
660+
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
661+
const convertedValue = utils_1.toCommandValue(value);
662+
// These should realistically never happen, but just in case someone finds a
663+
// way to exploit uuid generation let's not allow keys or values that contain
664+
// the delimiter.
665+
if (key.includes(delimiter)) {
666+
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
667+
}
668+
if (convertedValue.includes(delimiter)) {
669+
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
670+
}
671+
return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`;
672+
}
673+
exports.prepareKeyValueMessage = prepareKeyValueMessage;
659674
//# sourceMappingURL=file-command.js.map
660675

661676
/***/ }),

0 commit comments

Comments
 (0)