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

62 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-11-12 16:30:46 +01:00
"use strict";
// For internal use, subject to change.
2021-07-14 08:08:23 +02:00
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
2025-06-13 19:44:16 +02:00
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
2021-07-14 08:08:23 +02:00
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
2020-11-12 16:30:46 +01:00
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
2025-06-13 19:44:16 +02:00
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
2021-07-14 08:08:23 +02:00
__setModuleDefault(result, mod);
2020-11-12 16:30:46 +01:00
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
2022-10-21 16:52:45 +02:00
exports.prepareKeyValueMessage = exports.issueFileCommand = void 0;
2020-11-12 16:30:46 +01:00
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
2025-06-13 19:44:16 +02:00
const crypto = __importStar(require("crypto"));
2020-11-12 16:30:46 +01:00
const fs = __importStar(require("fs"));
const os = __importStar(require("os"));
const utils_1 = require("./utils");
2022-10-21 16:52:45 +02:00
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}`);
}
2025-06-13 19:44:16 +02:00
fs.appendFileSync(filePath, `${(0, utils_1.toCommandValue)(message)}${os.EOL}`, {
2020-11-12 16:30:46 +01:00
encoding: 'utf8'
});
}
2022-10-21 16:52:45 +02:00
exports.issueFileCommand = issueFileCommand;
function prepareKeyValueMessage(key, value) {
2025-06-13 19:44:16 +02:00
const delimiter = `ghadelimiter_${crypto.randomUUID()}`;
const convertedValue = (0, utils_1.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}`;
}
exports.prepareKeyValueMessage = prepareKeyValueMessage;
2020-11-12 16:30:46 +01:00
//# sourceMappingURL=file-command.js.map