Compare commits

..

1 Commits

Author SHA1 Message Date
github-actions[bot] c25aadc965 Automatic compilation 2023-08-17 16:13:31 +00:00
+114 -108
View File
@@ -2816,8 +2816,11 @@ var __webpack_exports__ = {};
// EXPORTS
__nccwpck_require__.d(__webpack_exports__, {
"kj": () => (/* binding */ authenticationSetup),
"ny": () => (/* binding */ checkWorkingDirectory),
"P8": () => (/* binding */ execCommands),
"wJ": () => (/* binding */ getNpxCmd),
"VH": () => (/* binding */ installWrangler),
"Wp": () => (/* binding */ semverCompare),
"cb": () => (/* binding */ uploadSecrets),
"cj": () => (/* binding */ wranglerCommands)
});
@@ -2830,38 +2833,6 @@ const external_node_child_process_namespaceObject = __WEBPACK_EXTERNAL_createReq
const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:fs");
;// CONCATENATED MODULE: external "node:path"
const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path");
;// CONCATENATED MODULE: ./src/utils.ts
function getNpxCmd() {
return process.env.RUNNER_OS === "Windows" ? "npx.cmd" : "npx";
}
/**
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
*/
function semverCompare(version1, version2) {
if (version2 === "latest")
return true;
const version1Parts = version1.split(".");
const version2Parts = version2.split(".");
for (const version1Part of version1Parts) {
const version2Part = version2Parts.shift();
if (version1Part !== version2Part && version2Part) {
return version1Part < version2Part ? true : false;
}
}
return false;
}
function checkWorkingDirectory(workingDirectory = ".") {
const normalizedPath = external_node_path_namespaceObject.normalize(workingDirectory);
if ((0,external_node_fs_namespaceObject.existsSync)(normalizedPath)) {
return normalizedPath;
}
else {
throw new Error(`Directory ${workingDirectory} does not exist.`);
}
}
;// CONCATENATED MODULE: external "node:util"
const external_node_util_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:util");
;// CONCATENATED MODULE: ./src/index.ts
@@ -2869,6 +2840,7 @@ const external_node_util_namespaceObject = __WEBPACK_EXTERNAL_createRequire(impo
const execAsync = external_node_util_namespaceObject.promisify(external_node_child_process_namespaceObject.exec);
const DEFAULT_WRANGLER_VERSION = "3.5.1";
/**
@@ -2885,6 +2857,9 @@ const config = {
COMMANDS: (0,core.getMultilineInput)("command"),
QUIET_MODE: (0,core.getBooleanInput)("quiet"),
};
function getNpxCmd() {
return process.env.RUNNER_OS === "Windows" ? "npx.cmd" : "npx";
}
function info(message, bypass) {
if (!config.QUIET_MODE || bypass) {
(0,core.info)(message);
@@ -2905,20 +2880,30 @@ function endGroup() {
(0,core.endGroup)();
}
}
/**
* A helper function to compare two semver versions. If the second arg is greater than the first arg, it returns true.
*/
function semverCompare(version1, version2) {
if (version2 === "latest")
return true;
const version1Parts = version1.split(".");
const version2Parts = version2.split(".");
for (const version1Part of version1Parts) {
const version2Part = version2Parts.shift();
if (version1Part !== version2Part && version2Part) {
return version1Part < version2Part ? true : false;
}
}
return false;
}
async function main() {
try {
installWrangler();
authenticationSetup();
await execCommands((0,core.getMultilineInput)("preCommands"), "pre");
await uploadSecrets();
await wranglerCommands();
await execCommands((0,core.getMultilineInput)("postCommands"), "post");
info("🏁 Wrangler Action completed", true);
}
catch (err) {
err instanceof Error && error(err.message);
(0,core.setFailed)("🚨 Action failed");
}
installWrangler();
authenticationSetup();
await execCommands((0,core.getMultilineInput)("preCommands"), "pre");
await uploadSecrets();
await wranglerCommands();
await execCommands((0,core.getMultilineInput)("postCommands"), "post");
info("🏁 Wrangler Action completed", true);
}
async function runProcess(command, options) {
try {
@@ -2930,12 +2915,26 @@ async function runProcess(command, options) {
catch (err) {
err.stdout && info(err.stdout.toString());
err.stderr && error(err.stderr.toString(), true);
throw new Error(`\`${command}\` returned non-zero exit code.`);
throw err;
}
}
function checkWorkingDirectory(workingDirectory = ".") {
try {
const normalizedPath = external_node_path_namespaceObject.normalize(workingDirectory);
if ((0,external_node_fs_namespaceObject.existsSync)(normalizedPath)) {
return normalizedPath;
}
else {
(0,core.setFailed)(`🚨 Directory ${workingDirectory} does not exist.`);
}
}
catch (error) {
(0,core.setFailed)(`🚨 While checking/creating directory ${workingDirectory} received ${error}`);
}
}
function installWrangler() {
if (config["WRANGLER_VERSION"].startsWith("1")) {
throw new Error(`Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`);
(0,core.setFailed)(`🚨 Wrangler v1 is no longer supported by this action. Please use major version 2 or greater`);
}
startGroup("📥 Installing Wrangler");
const command = `npm install wrangler@${config["WRANGLER_VERSION"]}`;
@@ -2953,47 +2952,52 @@ async function execCommands(commands, cmdType) {
return;
}
startGroup(`🚀 Running ${cmdType}Commands`);
try {
const arrPromises = commands.map(async (command) => {
const cmd = command.startsWith("wrangler")
? `${getNpxCmd()} ${command}`
: command;
info(`🚀 Executing command: ${cmd}`);
return await runProcess(cmd, {
cwd: config["workingDirectory"],
env: process.env,
});
const arrPromises = commands.map(async (command) => {
const cmd = command.startsWith("wrangler")
? `${getNpxCmd()} ${command}`
: command;
info(`🚀 Executing command: ${cmd}`);
return await runProcess(cmd, {
cwd: config["workingDirectory"],
env: process.env,
});
await Promise.all(arrPromises);
}
finally {
endGroup();
}
});
await Promise.all(arrPromises).catch((result) => {
result.stdout && info(result.stdout.toString());
result.stderr && error(result.stderr.toString(), true);
(0,core.setFailed)(`🚨 ${cmdType}Commands failed`);
});
endGroup();
}
/**
* A helper function to get the secret from the environment variables.
*/
function getSecret(secret) {
if (!secret) {
throw new Error("Secret name cannot be blank.");
(0,core.setFailed)("No secret provided");
}
const value = process.env[secret];
if (!value) {
throw new Error(`Value for secret ${secret} not found.`);
(0,core.setFailed)(`Secret ${secret} not found`);
}
return value;
}
async function legacyUploadSecrets(secrets, environment, workingDirectory) {
const arrPromises = secrets
.map((secret) => {
const command = `echo ${getSecret(secret)} | ${getNpxCmd()} wrangler secret put ${secret}`;
return environment ? command.concat(` --env ${environment}`) : command;
})
.map(async (command) => await execAsync(command, {
cwd: workingDirectory,
env: process.env,
}));
await Promise.all(arrPromises);
try {
const arrPromises = secrets
.map((secret) => {
const command = `echo ${getSecret(secret)} | ${getNpxCmd()} wrangler secret put ${secret}`;
return environment ? command.concat(` --env ${environment}`) : command;
})
.map(async (command) => await execAsync(command, {
cwd: workingDirectory,
env: process.env,
}));
await Promise.all(arrPromises);
}
catch {
(0,core.setFailed)(`🚨 Error uploading secrets`);
}
}
async function uploadSecrets() {
const secrets = config["secrets"];
@@ -3002,8 +3006,8 @@ async function uploadSecrets() {
if (!secrets.length) {
return;
}
startGroup("🔑 Uploading secrets...");
try {
startGroup("🔑 Uploading Secrets");
if (semverCompare(config["WRANGLER_VERSION"], "3.4.0"))
return legacyUploadSecrets(secrets, environment, workingDirectory);
const secretObj = secrets.reduce((acc, secret) => {
@@ -3021,9 +3025,8 @@ async function uploadSecrets() {
});
info(`✅ Uploaded secrets`);
}
catch (err) {
error(`❌ Upload failed`);
throw new Error(`Failed to upload secrets.`);
catch {
(0,core.setFailed)(`🚨 Error uploading secrets`);
}
finally {
endGroup();
@@ -3036,51 +3039,54 @@ function getVarArgs() {
return `${envVar}:${process.env[envVar]}`;
}
else {
throw new Error(`Value for var ${envVar} not found in environment.`);
(0,core.setFailed)(`🚨 ${envVar} not found in variables.`);
}
});
return envVarArray.length > 0 ? `--var ${envVarArray.join(" ").trim()}` : "";
}
async function wranglerCommands() {
startGroup("🚀 Running Wrangler Commands");
try {
const commands = config["COMMANDS"];
const environment = config["ENVIRONMENT"];
if (!commands.length) {
const wranglerVersion = config["WRANGLER_VERSION"];
const deployCommand = semverCompare("2.20.0", wranglerVersion)
? "deploy"
: "publish";
commands.push(deployCommand);
const commands = config["COMMANDS"];
const environment = config["ENVIRONMENT"];
if (!commands.length) {
const wranglerVersion = config["WRANGLER_VERSION"];
const deployCommand = semverCompare("2.20.0", wranglerVersion)
? "deploy"
: "publish";
commands.push(deployCommand);
}
const arrPromises = commands.map(async (command) => {
if (environment.length > 0 && !command.includes(`--env`)) {
command = command.concat(` --env ${environment}`);
}
const arrPromises = commands.map(async (command) => {
if (environment.length > 0 && !command.includes(`--env`)) {
command = command.concat(` --env ${environment}`);
}
const cmd = `${getNpxCmd()} wrangler ${command} ${(command.startsWith("deploy") || command.startsWith("publish")) &&
!command.includes(`--var`)
? getVarArgs()
: ""}`.trim();
info(`🚀 Executing command: ${cmd}`);
return await runProcess(cmd, {
cwd: config["workingDirectory"],
env: process.env,
});
const cmd = `${getNpxCmd()} wrangler ${command} ${(command.startsWith("deploy") || command.startsWith("publish")) &&
!command.includes(`--var`)
? getVarArgs()
: ""}`.trim();
info(`🚀 Executing command: ${cmd}`);
return await runProcess(cmd, {
cwd: config["workingDirectory"],
env: process.env,
});
await Promise.all(arrPromises);
}
finally {
endGroup();
}
});
await Promise.all(arrPromises).catch((result) => {
result.stdout && info(result.stdout.toString());
result.stderr && error(result.stderr.toString());
(0,core.setFailed)(`🚨 Command failed`);
});
endGroup();
}
main();
main().catch(() => (0,core.setFailed)("🚨 Action failed"));
})();
var __webpack_exports__authenticationSetup = __webpack_exports__.kj;
var __webpack_exports__checkWorkingDirectory = __webpack_exports__.ny;
var __webpack_exports__execCommands = __webpack_exports__.P8;
var __webpack_exports__getNpxCmd = __webpack_exports__.wJ;
var __webpack_exports__installWrangler = __webpack_exports__.VH;
var __webpack_exports__semverCompare = __webpack_exports__.Wp;
var __webpack_exports__uploadSecrets = __webpack_exports__.cb;
var __webpack_exports__wranglerCommands = __webpack_exports__.cj;
export { __webpack_exports__authenticationSetup as authenticationSetup, __webpack_exports__execCommands as execCommands, __webpack_exports__installWrangler as installWrangler, __webpack_exports__uploadSecrets as uploadSecrets, __webpack_exports__wranglerCommands as wranglerCommands };
export { __webpack_exports__authenticationSetup as authenticationSetup, __webpack_exports__checkWorkingDirectory as checkWorkingDirectory, __webpack_exports__execCommands as execCommands, __webpack_exports__getNpxCmd as getNpxCmd, __webpack_exports__installWrangler as installWrangler, __webpack_exports__semverCompare as semverCompare, __webpack_exports__uploadSecrets as uploadSecrets, __webpack_exports__wranglerCommands as wranglerCommands };