Update .changeset/itchy-buses-grow.md

Co-authored-by: Cina Saffary <itscina@gmail.com>
This commit is contained in:
Jacob M-G Evans 2023-08-10 10:30:50 -05:00 committed by Jacob M-G Evans
parent 74433eb31e
commit 88466ea5ae
No known key found for this signature in database
GPG key ID: 2A0C497CAB123094
2 changed files with 51 additions and 52 deletions

View file

@ -2,7 +2,7 @@
"wrangler-action": patch "wrangler-action": patch
--- ---
Additional Error Handling Added more error logging when a command fails to execute
Previously, we prevented any error logs from propagating too far to prevent leaking of any potentially sensitive information. However, this made it difficult for developers to debug their code. Previously, we prevented any error logs from propagating too far to prevent leaking of any potentially sensitive information. However, this made it difficult for developers to debug their code.
In this release, we have updated our error handling to allow for more error messaging from pre/post and custom commands. We still discourage the use of these commands for secrets or other sensitive information, but we believe this change will make it easier for developers to debug their code. In this release, we have updated our error handling to allow for more error messaging from pre/post and custom commands. We still discourage the use of these commands for secrets or other sensitive information, but we believe this change will make it easier for developers to debug their code.

View file

@ -56,10 +56,28 @@ function semverCompare(version1: string, version2: string) {
async function main() { async function main() {
installWrangler(); installWrangler();
authenticationSetup(); authenticationSetup();
await execCommands(getMultilineInput("preCommands"), "Pre"); await execCommands(getMultilineInput("preCommands"), "pre");
await uploadSecrets(); await uploadSecrets();
await wranglerCommands(); await wranglerCommands();
await execCommands(getMultilineInput("postCommands"), "Post"); await execCommands(getMultilineInput("postCommands"), "post");
}
async function runProcess(
command: Parameters<typeof execAsync>[0],
options: Parameters<typeof execAsync>[1],
) {
try {
const result = await execAsync(command, options);
result.stdout && info(result.stdout.toString());
result.stderr && error(result.stderr.toString());
return result;
} catch (err: any) {
err.stdout && info(err.stdout.toString());
err.stderr && error(err.stderr.toString());
throw err;
}
} }
function checkWorkingDirectory(workingDirectory = ".") { function checkWorkingDirectory(workingDirectory = ".") {
@ -100,7 +118,7 @@ async function execCommands(commands: string[], cmdType: string) {
if (!commands.length) { if (!commands.length) {
return; return;
} }
startGroup(`🚀 ${cmdType} Commands Group`); startGroup(`🚀 Running ${cmdType}Commands`);
const arrPromises = commands.map(async (command) => { const arrPromises = commands.map(async (command) => {
const cmd = command.startsWith("wrangler") const cmd = command.startsWith("wrangler")
@ -109,15 +127,16 @@ async function execCommands(commands: string[], cmdType: string) {
info(`🚀 Executing command: ${cmd}`); info(`🚀 Executing command: ${cmd}`);
return await execAsync(cmd, { return await runProcess(cmd, {
cwd: config["workingDirectory"], cwd: config["workingDirectory"],
env: process.env, env: process.env,
}); });
}); });
await Promise.all(arrPromises).catch((result) => { await Promise.all(arrPromises).catch((result) => {
error(`🚨 ${cmdType} Command failed`); result.stdout && info(result.stdout.toString());
setFailed(result); result.stderr && error(result.stderr.toString());
setFailed(`🚨 ${cmdType}Commands failed`);
}); });
endGroup(); endGroup();
} }
@ -149,7 +168,7 @@ async function legacyUploadSecrets(
const command = `echo ${getSecret( const command = `echo ${getSecret(
secret, secret,
)} | ${getNpxCmd()} wrangler secret put ${secret}`; )} | ${getNpxCmd()} wrangler secret put ${secret}`;
return environment ? command.concat(`--env ${environment}`) : command; return environment ? command.concat(` --env ${environment}`) : command;
}) })
.map( .map(
async (command) => async (command) =>
@ -219,63 +238,43 @@ function getVarArgs() {
return envVarArray.length > 0 ? `--var ${envVarArray.join(" ").trim()}` : ""; return envVarArray.length > 0 ? `--var ${envVarArray.join(" ").trim()}` : "";
} }
function defaultCommandBehavior() {
const environment = config["ENVIRONMENT"];
const wranglerVersion = config["WRANGLER_VERSION"];
const workingDirectory = config["workingDirectory"];
const deployCommand = semverCompare("2.20.0", wranglerVersion)
? "deploy"
: "publish";
info(`📌 No Wrangler commands were provided, executing default deployment.`);
if (environment.length === 0) {
execSync(
`${getNpxCmd()} wrangler ${deployCommand} ${getVarArgs()}`.trim(),
{
cwd: workingDirectory,
env: process.env,
},
);
} else {
execSync(
`${getNpxCmd()} wrangler ${deployCommand} --env ${environment} ${getVarArgs()}`.trim(),
{ cwd: workingDirectory, env: process.env },
);
}
endGroup();
}
async function wranglerCommands() { async function wranglerCommands() {
startGroup("🚀 Running Wrangler Commands");
const commands = config["COMMANDS"]; const commands = config["COMMANDS"];
const environment = config["ENVIRONMENT"]; const environment = config["ENVIRONMENT"];
if (!commands.length) { if (!commands.length) {
defaultCommandBehavior(); const wranglerVersion = config["WRANGLER_VERSION"];
return; const deployCommand = semverCompare("2.20.0", wranglerVersion)
? "deploy"
: "publish";
commands.push(deployCommand);
} }
startGroup("🚀 Executing Wrangler Commands");
const arrPromises = commands.map(async (command) => { const arrPromises = commands.map(async (command) => {
if (environment.length > 0 && !command.includes(`--env ${environment}`)) { if (environment.length > 0 && !command.includes(`--env`)) {
command.concat(`--env ${environment}`); command = command.concat(` --env ${environment}`);
} }
const result = await execAsync(
`${getNpxCmd()} wrangler ${command} ${getVarArgs()}`, 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"], cwd: config["workingDirectory"],
env: process.env, env: process.env,
}, });
);
info(result.stdout);
return result;
}); });
await Promise.all(arrPromises).catch((result) => { await Promise.all(arrPromises).catch((result) => {
error(`🚨 Command failed`); result.stdout && info(result.stdout.toString());
setFailed(result.stderr); result.stderr && error(result.stderr.toString());
setFailed(`🚨 Command failed`);
}); });
endGroup(); endGroup();