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;
}
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(
config: WranglerActionConfig,
packageManager: PackageManager,
@ -276,18 +256,8 @@ async function uploadSecrets(
startGroup(config, "🔑 Uploading secrets...");
try {
if (semverCompare(config["WRANGLER_VERSION"], "3.4.0")) {
return legacyUploadSecrets(
config,
packageManager,
secrets,
environment,
workingDirectory,
);
}
const args = ["wrangler", "secret:bulk"];
for (const secret of secrets) {
const args = ["wrangler", "secret", "put", secret];
if (environment) {
args.push("--env", environment);
}
@ -295,14 +265,9 @@ async function uploadSecrets(
await exec(packageManager.exec, args, {
cwd: workingDirectory,
silent: config["QUIET_MODE"],
input: Buffer.from(
JSON.stringify(
Object.fromEntries(
secrets.map((secret) => [secret, getSecret(secret)]),
),
),
),
input: Buffer.from(getSecret(secret)),
});
}
} catch (err: unknown) {
if (err instanceof Error) {
error(config, err.message);