2020-11-12 16:30:46 +01:00
|
|
|
// For internal use, subject to change.
|
|
|
|
|
// We use any as a valid input type
|
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2026-01-30 13:31:20 +01:00
|
|
|
import * as crypto from 'crypto';
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as os from 'os';
|
|
|
|
|
import { toCommandValue } from './utils.js';
|
|
|
|
|
export function issueFileCommand(command, message) {
|
2020-11-12 16:30:46 +01:00
|
|
|
const filePath = process.env[`GITHUB_${command}`];
|
|
|
|
|
if (!filePath) {
|
|
|
|
|
throw new Error(`Unable to find environment variable for file command ${command}`);
|
|
|
|
|
}
|
|
|
|
|
if (!fs.existsSync(filePath)) {
|
|
|
|
|
throw new Error(`Missing file at path: ${filePath}`);
|
|
|
|
|
}
|
2026-01-30 13:31:20 +01:00
|
|
|
fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, {
|
2020-11-12 16:30:46 +01:00
|
|
|
encoding: 'utf8'
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-01-30 13:31:20 +01:00
|
|
|
export function prepareKeyValueMessage(key, value) {
|
2025-06-13 19:44:16 +02:00
|
|
|
const delimiter = `ghadelimiter_${crypto.randomUUID()}`;
|
2026-01-30 13:31:20 +01:00
|
|
|
const convertedValue = toCommandValue(value);
|
2022-10-21 16:52:45 +02:00
|
|
|
// 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.
|
|
|
|
|
if (key.includes(delimiter)) {
|
|
|
|
|
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
|
|
|
|
|
}
|
|
|
|
|
if (convertedValue.includes(delimiter)) {
|
|
|
|
|
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
|
|
|
|
|
}
|
|
|
|
|
return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`;
|
|
|
|
|
}
|
2020-11-12 16:30:46 +01:00
|
|
|
//# sourceMappingURL=file-command.js.map
|