Skip to content

Commit cd6314a

Browse files
committedMar 15, 2025··
Use wranglers secret:bulk on versions of wrangler prior to 3.60.0
1 parent ef1f9fb commit cd6314a

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed
 

‎.changeset/eighty-sloths-wave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler-action": patch
3+
---
4+
5+
Use `secret bulk` instead of deprecated `secret:bulk` command

‎src/wranglerAction.test.ts

+88-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as core from "@actions/core";
22
import * as exec from "@actions/exec";
33
import { describe, expect, it, vi } from "vitest";
4-
import { installWrangler } from "./wranglerAction";
4+
import { installWrangler, uploadSecrets } from "./wranglerAction";
55
import { getTestConfig } from "./test/test-utils";
66

77
describe("installWrangler", () => {
@@ -76,3 +76,90 @@ describe("installWrangler", () => {
7676
expect(infoSpy).toBeCalledWith("✅ Wrangler installed");
7777
});
7878
});
79+
80+
describe("uploadSecrets", () => {
81+
const testPackageManager = {
82+
install: "npm i",
83+
exec: "npx",
84+
execNoInstall: "npx --no-install",
85+
};
86+
87+
it("WRANGLER_VERSION < 3.4.0 uses wrangler secret put", async () => {
88+
vi.stubEnv("FAKE_SECRET", "FAKE_VALUE");
89+
const testConfig = getTestConfig({
90+
config: {
91+
WRANGLER_VERSION: "3.3.0",
92+
didUserProvideWranglerVersion: true,
93+
secrets: ["FAKE_SECRET"],
94+
},
95+
});
96+
vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => {
97+
expect(cmd).toBe("npx");
98+
expect(args).toStrictEqual([
99+
"wrangler",
100+
"secret",
101+
"put",
102+
"FAKE_SECRET",
103+
"--env",
104+
"dev",
105+
]);
106+
return 0;
107+
});
108+
const startGroup = vi.spyOn(core, "startGroup");
109+
const endGroup = vi.spyOn(core, "endGroup");
110+
111+
await uploadSecrets(testConfig, testPackageManager);
112+
expect(startGroup).toBeCalledWith("🔑 Uploading secrets...");
113+
expect(endGroup).toHaveBeenCalledOnce();
114+
});
115+
116+
it("WRANGLER_VERSION < 3.60.0 uses wrangler secret:bulk", async () => {
117+
vi.stubEnv("FAKE_SECRET", "FAKE_VALUE");
118+
const testConfig = getTestConfig({
119+
config: {
120+
WRANGLER_VERSION: "3.59.0",
121+
didUserProvideWranglerVersion: true,
122+
secrets: ["FAKE_SECRET"],
123+
},
124+
});
125+
vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => {
126+
expect(cmd).toBe("npx");
127+
expect(args).toStrictEqual(["wrangler", "secret:bulk", "--env", "dev"]);
128+
return 0;
129+
});
130+
const startGroup = vi.spyOn(core, "startGroup");
131+
const endGroup = vi.spyOn(core, "endGroup");
132+
133+
await uploadSecrets(testConfig, testPackageManager);
134+
expect(startGroup).toBeCalledWith("🔑 Uploading secrets...");
135+
expect(endGroup).toHaveBeenCalledOnce();
136+
});
137+
138+
it("WRANGLER_VERSION 3.61.0 uses wrangler secret bulk", async () => {
139+
vi.stubEnv("FAKE_SECRET", "FAKE_VALUE");
140+
const testConfig = getTestConfig({
141+
config: {
142+
WRANGLER_VERSION: "3.61.0",
143+
didUserProvideWranglerVersion: true,
144+
secrets: ["FAKE_SECRET"],
145+
},
146+
});
147+
vi.spyOn(exec, "exec").mockImplementation(async (cmd, args) => {
148+
expect(cmd).toBe("npx");
149+
expect(args).toStrictEqual([
150+
"wrangler",
151+
"secret",
152+
"bulk",
153+
"--env",
154+
"dev",
155+
]);
156+
return 0;
157+
});
158+
const startGroup = vi.spyOn(core, "startGroup");
159+
const endGroup = vi.spyOn(core, "endGroup");
160+
161+
await uploadSecrets(testConfig, testPackageManager);
162+
expect(startGroup).toBeCalledWith("🔑 Uploading secrets...");
163+
expect(endGroup).toHaveBeenCalledOnce();
164+
});
165+
});

‎src/wranglerAction.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { exec, execShell } from "./exec";
1313
import { PackageManager } from "./packageManagers";
1414
import { error, info, semverCompare } from "./utils";
1515
import { handleCommandOutputParsing } from "./commandOutputParsing";
16+
import semverLt from "semver/functions/lt";
1617

1718
export type WranglerActionConfig = z.infer<typeof wranglerActionConfig>;
1819
export const wranglerActionConfig = z.object({
@@ -265,7 +266,11 @@ async function uploadSecrets(
265266
);
266267
}
267268

268-
const args = ["wrangler", "secret", "bulk"];
269+
let args = ["wrangler", "secret", "bulk"];
270+
// if we're on a WRANGLER_VERSION prior to 3.60.0 use wrangler secret:bulk
271+
if (semverLt(config["WRANGLER_VERSION"], "3.60.0")) {
272+
args = ["wrangler", "secret:bulk"];
273+
}
269274

270275
if (environment) {
271276
args.push("--env", environment);

0 commit comments

Comments
 (0)
Please sign in to comment.