diff --git a/src/index.ts b/src/index.ts index 20f5c2a7..ad80b46b 100755 --- a/src/index.ts +++ b/src/index.ts @@ -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"; @@ -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, }); @@ -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") { @@ -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, });