Skip to content

Commit a5e7c0b

Browse files
echen67Emily Chen
and
Emily Chen
authored
WC-1559: Add alert when last deployed via API (#3727)
* WC-1559: Add alert when last deployed via API * WC-1559: Add test * WC-1559: Add changeset * WC-1559: Fix formatting --------- Co-authored-by: Emily Chen <[email protected]>
1 parent d017e9f commit a5e7c0b

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

.changeset/dirty-roses-appear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Warn user when the last deployment was via the API

packages/wrangler/src/__tests__/deploy.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
msw,
3737
mswSuccessDeployments,
3838
mswSuccessDeploymentScriptMetadata,
39+
mswSuccessDeploymentScriptAPI,
3940
} from "./helpers/msw";
4041
import { FileReaderSync } from "./helpers/msw/read-file-sync";
4142
import { runInTempDir } from "./helpers/run-in-tmp";
@@ -365,6 +366,22 @@ describe("deploy", () => {
365366
});
366367
});
367368

369+
describe("warnings", () => {
370+
it("should warn user when worker was last deployed from api", async () => {
371+
msw.use(...mswSuccessDeploymentScriptAPI);
372+
writeWranglerToml();
373+
writeWorkerSource();
374+
mockSubDomainRequest();
375+
mockUploadWorkerRequest();
376+
377+
await runWrangler("deploy ./index");
378+
379+
expect(std.warn).toMatch(
380+
/You are about to publish a Workers Service that was last updated via the script API/
381+
);
382+
});
383+
});
384+
368385
describe("environments", () => {
369386
it("should use legacy environments by default", async () => {
370387
writeWranglerToml({ env: { "some-env": {} } });

packages/wrangler/src/__tests__/helpers/msw/handlers/deployments.ts

+17
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ export const mswSuccessDeploymentScriptMetadata = [
9595
),
9696
];
9797

98+
export const mswSuccessDeploymentScriptAPI = [
99+
rest.get(
100+
"*/accounts/:accountId/workers/services/:scriptName",
101+
(_, res, ctx) => {
102+
return res.once(
103+
ctx.json(
104+
createFetchResult({
105+
default_environment: {
106+
script: { last_deployed_from: "api", tag: "MOCK-TAG" },
107+
},
108+
})
109+
)
110+
);
111+
}
112+
),
113+
];
114+
98115
export const mswSuccessDeploymentDetails = [
99116
rest.get(
100117
"*/accounts/:accountId/workers/deployments/by-script/:scriptTag/detail/:deploymentId",

packages/wrangler/src/__tests__/helpers/msw/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
mswSuccessDeployments,
55
mswSuccessDeploymentScriptMetadata,
66
mswSuccessDeploymentDetails,
7+
mswSuccessDeploymentScriptAPI,
78
} from "./handlers/deployments";
89
import { mswSuccessNamespacesHandlers } from "./handlers/namespaces";
910
import { mswSuccessOauthHandlers } from "./handlers/oauth";
@@ -49,4 +50,5 @@ export {
4950
mswSuccessDeploymentDetails,
5051
mswAccessHandlers,
5152
mswSuccessDeploymentScriptMetadata,
53+
mswSuccessDeploymentScriptAPI,
5254
};

packages/wrangler/src/deploy/deploy.ts

+7
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ export default async function deploy(props: Props): Promise<void> {
283283
if (!(await confirm("Would you like to continue?"))) {
284284
return;
285285
}
286+
} else if (default_environment.script.last_deployed_from === "api") {
287+
logger.warn(
288+
`You are about to publish a Workers Service that was last updated via the script API.\nEdits that have been made via the script API will be overridden by your local code and config.`
289+
);
290+
if (!(await confirm("Would you like to continue?"))) {
291+
return;
292+
}
286293
}
287294
} catch (e) {
288295
// code: 10090, message: workers.api.error.service_not_found

0 commit comments

Comments
 (0)