fix: Use wrangler secret put instead of deprecated secret:bulk command

`wrangler secret:bulk` is deprecated and will be removed in a future
version. This also improves logging in cases where a secret is failing
to upload because an environment variable with the same name already
exists (see: #240).
This commit is contained in:
Jacob Hands 2024-11-18 09:33:26 -06:00
parent ac2fd0ec8f
commit 0ca18d5d22
3 changed files with 2031 additions and 46 deletions

View file

@ -0,0 +1,7 @@
---
"wrangler-action": patch
---
fix: Use wrangler secret put instead of deprecated secret:bulk command
`wrangler secret:bulk` is deprecated and will be removed in a future version. This also improves logging in cases where a secret is failing to upload because an environment variable with the same name already exists (see: #240).

2013
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff

View file

@ -241,26 +241,6 @@ function getEnvVar(envVar: string) {
return value; return value;
} }
async function legacyUploadSecrets(
config: WranglerActionConfig,
packageManager: PackageManager,
secrets: string[],
environment?: string,
workingDirectory?: string,
) {
for (const secret of secrets) {
const args = ["wrangler", "secret", "put", secret];
if (environment) {
args.push("--env", environment);
}
await exec(packageManager.exec, args, {
cwd: workingDirectory,
silent: config["QUIET_MODE"],
input: Buffer.from(getSecret(secret)),
});
}
}
async function uploadSecrets( async function uploadSecrets(
config: WranglerActionConfig, config: WranglerActionConfig,
packageManager: PackageManager, packageManager: PackageManager,
@ -276,33 +256,18 @@ async function uploadSecrets(
startGroup(config, "🔑 Uploading secrets..."); startGroup(config, "🔑 Uploading secrets...");
try { try {
if (semverCompare(config["WRANGLER_VERSION"], "3.4.0")) { for (const secret of secrets) {
return legacyUploadSecrets( const args = ["wrangler", "secret", "put", secret];
config, if (environment) {
packageManager, args.push("--env", environment);
secrets, }
environment,
workingDirectory, await exec(packageManager.exec, args, {
); cwd: workingDirectory,
silent: config["QUIET_MODE"],
input: Buffer.from(getSecret(secret)),
});
} }
const args = ["wrangler", "secret:bulk"];
if (environment) {
args.push("--env", environment);
}
await exec(packageManager.exec, args, {
cwd: workingDirectory,
silent: config["QUIET_MODE"],
input: Buffer.from(
JSON.stringify(
Object.fromEntries(
secrets.map((secret) => [secret, getSecret(secret)]),
),
),
),
});
} catch (err: unknown) { } catch (err: unknown) {
if (err instanceof Error) { if (err instanceof Error) {
error(config, err.message); error(config, err.message);