Skip to content

Commit

Permalink
Fix legacy secret input
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobMGEvans committed Jul 31, 2023
1 parent 7b1a0c5 commit c81f29d
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
endGroup,
startGroup,
} from "@actions/core";
import { execSync } from "node:child_process";
import { execSync, exec } from "node:child_process";
import { existsSync } from "node:fs";
import * as path from "node:path";
import * as util from "node:util";
const exec = util.promisify(require("node:child_process").exec);
const execAsync = util.promisify(exec);

const DEFAULT_WRANGLER_VERSION = "3.4.0";

Expand Down Expand Up @@ -97,7 +97,7 @@ async function execCommands(commands: string[], cmdType: string) {

info(`🚀 Executing command: ${npxCmd}`);

await exec(npxCmd, {
await execAsync(npxCmd, {
cwd: config["workingDirectory"],
env: process.env,
});
Expand All @@ -117,21 +117,26 @@ async function legacyUploadSecrets(
environment?: string,
workingDirectory?: string,
) {
const commands = secrets.map((secret) => {
const command = `${getNpxCmd()} wrangler secret put ${secret}`;
return environment ? command.concat(` --env ${environment}`) : command;
});

await Promise.all(
commands.map(
async (command) =>
await exec(command, {
cwd: workingDirectory,
env: process.env,
stdio: "ignore",
}),
),
);
try {
const arrPromises = secrets
.map((secret) => {
const command = `${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 {
setFailed(`🚨 Error uploading secrets`);
}
}

function semverCompare(version1: string, version2 = "3.4.0") {
Expand Down Expand Up @@ -244,7 +249,7 @@ async function wranglerCommands() {
}

const arrPromises = commands.map(async (command) => {
const result = await exec(`${getNpxCmd()} wrangler ${command}`, {
const result = await execAsync(`${getNpxCmd()} wrangler ${command}`, {
cwd: config["workingDirectory"],
env: process.env,
});
Expand Down

0 comments on commit c81f29d

Please sign in to comment.