Files
send-mail/node_modules/@actions/core/lib/file-command.js

34 lines
1.4 KiB
JavaScript
Raw Normal View History

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 */
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}`);
}
fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, {
2020-11-12 16:30:46 +01:00
encoding: 'utf8'
});
}
export function prepareKeyValueMessage(key, value) {
2025-06-13 19:44:16 +02:00
const delimiter = `ghadelimiter_${crypto.randomUUID()}`;
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