Skip to content

Commit cb26947

Browse files
committed
Fix everything.
1 parent 6bcfb3e commit cb26947

3 files changed

Lines changed: 70 additions & 18 deletions

File tree

README.md

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ This Action:
4747
- `message`: The final rendered message.
4848
- `tag`: The final rendered tag (if any).
4949
- `only_upload` mode when you want to upload a version and deploy it separately.
50+
- `wrangler_command` lets you control exactly how Wrangler is invoked (e.g. `wrangler`, `npx wrangler@4`, `pnpm dlx wrangler@4`).
51+
- `working_directory` lets you target a specific folder in a monorepo when running Wrangler commands.
5052

5153
## How it works
5254

@@ -88,11 +90,13 @@ This upload-then-deploy flow is what enables meaningful messages to show up in C
8890
You must:
8991

9092
- Use Wrangler v4 (Versions API support required).
91-
- Ensure `wrangler` is available in your GitHub Actions runner:
92-
- Example:
93-
- `pnpm dlx wrangler@4 --version`
94-
- or `npx wrangler@4 --version`
95-
- or add Wrangler v4 as a dev dependency and use it from PATH.
93+
- Ensure you have a reliable way to invoke Wrangler v4:
94+
- - You specify this explicitly via the `wrangler_command` input.
95+
- - Examples:
96+
- - `wrangler`
97+
- - `npx wrangler@4`
98+
- - `pnpm dlx wrangler@4`
99+
- - No separate install step is required if your `wrangler_command` handles it.
96100
- Provide a Cloudflare API token:
97101
- With appropriate permissions for your Worker.
98102
- Passed via `secrets` to the `api_token` input.
@@ -117,6 +121,27 @@ All inputs are strings (as per GitHub Actions) unless noted; booleans are passed
117121
- Recommended: `secrets.CLOUDFLARE_API_TOKEN`.
118122
- Used to set `CLOUDFLARE_API_TOKEN` for the Wrangler commands.
119123

124+
- `wrangler_command` (required)
125+
- How to invoke Wrangler.
126+
- This is the base command (and optional leading arguments) that will be used for both upload and deploy.
127+
- Examples:
128+
- `wrangler`
129+
- `npx wrangler@4`
130+
- `pnpm dlx wrangler@4`
131+
- The Action splits this into:
132+
- Executable: first token
133+
- Base args: remaining tokens
134+
- Then runs:
135+
- `<wrangler_command> versions upload ...`
136+
- `<wrangler_command> versions deploy ...`
137+
138+
- `working_directory` (optional)
139+
- Working directory from which Wrangler commands will be executed.
140+
- If set, it is used as the `cwd` for both:
141+
- `versions upload`
142+
- `versions deploy`
143+
- Useful for monorepos where your Worker lives in a subfolder.
144+
120145
- `config` (required)
121146
- Path to the Wrangler configuration file.
122147
- Passed as:
@@ -241,6 +266,7 @@ jobs:
241266
uses: your-org/wrangler-version-deploy-action-with-metadata@v1
242267
with:
243268
api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
269+
wrangler_command: "pnpm dlx wrangler@4"
244270
config: "dist/server/wrangler.json"
245271
upload_args: "--env production"
246272
deploy_args: "--env production"
@@ -279,6 +305,7 @@ jobs:
279305
uses: your-org/wrangler-version-deploy-action-with-metadata@v1
280306
with:
281307
api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
308+
wrangler_command: "pnpm dlx wrangler@4"
282309
config: "wrangler.toml"
283310
upload_args: "--env staging"
284311
only_upload: "true"
@@ -327,7 +354,7 @@ You can combine outputs with other Actions to post deployment info back to PRs:
327354
});
328355
```
329356
+
330-
+### Example 4: Monorepo - Deploy Only When a Folder Changes
357+
### Example 4: Monorepo - Deploy Only When a Folder Changes
331358
+
332359
+In a monorepo, you often want to:
333360
+
@@ -365,16 +392,18 @@ You can combine outputs with other Actions to post deployment info back to PRs:
365392
+
366393
+ - run: pnpm dlx wrangler@4 --version
367394
+
368-
+ - name: Upload + deploy worker-app via Versions API with metadata
369-
+ id: cf_deploy
370-
+ uses: your-org/wrangler-version-deploy-action-with-metadata@v1
371-
+ with:
372-
+ api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
373-
+ config: "apps/worker-app/wrangler.toml"
374-
+ upload_args: "--env production"
375-
+ deploy_args: "--env production"
376-
+ message_template: "worker-app: {{repo}}@{{short_sha}} on {{branch}} (run {{run_number}})"
377-
+```
395+
- name: Upload + deploy worker-app via Versions API with metadata
396+
id: cf_deploy
397+
uses: your-org/wrangler-version-deploy-action-with-metadata@v1
398+
with:
399+
api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
400+
wrangler_command: "pnpm dlx wrangler@4"
401+
working_directory: "apps/worker-app"
402+
config: "wrangler.toml"
403+
upload_args: "--env production"
404+
deploy_args: "--env production"
405+
message_template: "worker-app: {{repo}}@{{short_sha}} on {{branch}} (run {{run_number}})"
406+
```
378407
379408
## Notes
380409

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ inputs:
99
api_token:
1010
description: "Cloudflare API token. Pass via secrets (e.g. secrets.CLOUDFLARE_API_TOKEN)."
1111
required: true
12+
wrangler_command:
13+
description: "Command used to invoke Wrangler (for example: wrangler, npx wrangler, pnpm dlx wrangler@4)."
14+
required: true
15+
working_directory:
16+
description: "Working directory from which Wrangler commands will be executed (useful for monorepos)."
17+
required: false
1218
config:
1319
description: "Path to the Wrangler configuration file (e.g. wrangler.toml or dist/server/wrangler.json). This will be passed as --config to both versions upload and versions deploy."
1420
required: true

src/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ interface DeployMetadata {
2525
async function run(): Promise<void> {
2626
try {
2727
const apiToken = core.getInput("api_token", { required: true });
28+
const wranglerCommandInput = core.getInput("wrangler_command", {
29+
required: true,
30+
});
31+
const workingDirectoryInput = core.getInput("working_directory") || "";
2832
const onlyUploadInput = core.getInput("only_upload") || "false";
2933
const onlyUpload = onlyUploadInput.toLowerCase() === "true";
3034
const config = core.getInput("config", { required: true });
@@ -36,6 +40,15 @@ async function run(): Promise<void> {
3640
const uploadArgsList = splitArgs(uploadArgsRaw);
3741
const deployArgsList = splitArgs(deployArgsRaw);
3842

43+
const workingDirectory =
44+
workingDirectoryInput.trim().length > 0
45+
? workingDirectoryInput.trim()
46+
: undefined;
47+
48+
const wranglerCommandParts = wranglerCommandInput.trim().split(/\s+/);
49+
const wranglerExec = wranglerCommandParts[0];
50+
const wranglerBaseArgs = wranglerCommandParts.slice(1);
51+
3952
if (!apiToken) {
4053
core.setFailed("Cloudflare API token (api_token) is required.");
4154
return;
@@ -80,6 +93,7 @@ async function run(): Promise<void> {
8093
// We assume the user is on Wrangler v4+ and that `versions` commands are available.
8194
// The actual Worker configuration (e.g. wrangler.toml) is controlled by the caller.
8295
const uploadArgs = [
96+
...wranglerBaseArgs,
8397
"versions",
8498
"upload",
8599
"--config",
@@ -98,6 +112,7 @@ async function run(): Promise<void> {
98112
...process.env,
99113
CLOUDFLARE_API_TOKEN: apiToken,
100114
},
115+
cwd: workingDirectory,
101116
listeners: {
102117
stdout: (data: Buffer) => {
103118
const text = data.toString();
@@ -113,7 +128,7 @@ async function run(): Promise<void> {
113128
};
114129

115130
const uploadExitCode = await exec.exec(
116-
"wrangler",
131+
wranglerExec,
117132
uploadArgs,
118133
uploadOptions,
119134
);
@@ -157,6 +172,7 @@ async function run(): Promise<void> {
157172

158173
// 3) Run `wrangler versions deploy <versionId>` non-interactively with the same message.
159174
const deployArgs = [
175+
...wranglerBaseArgs,
160176
"versions",
161177
"deploy",
162178
versionId,
@@ -177,6 +193,7 @@ async function run(): Promise<void> {
177193
...process.env,
178194
CLOUDFLARE_API_TOKEN: apiToken,
179195
},
196+
cwd: workingDirectory,
180197
listeners: {
181198
stdout: (data: Buffer) => {
182199
const text = data.toString();
@@ -192,7 +209,7 @@ async function run(): Promise<void> {
192209
};
193210

194211
const deployExitCode = await exec.exec(
195-
"wrangler",
212+
wranglerExec,
196213
deployArgs,
197214
deployOptions,
198215
);

0 commit comments

Comments
 (0)