Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WC-1559: Add alert when last deployed via API #3727

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-roses-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

Warn user when the last deployment was via the API
17 changes: 17 additions & 0 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
msw,
mswSuccessDeployments,
mswSuccessDeploymentScriptMetadata,
mswSuccessDeploymentScriptAPI,
} from "./helpers/msw";
import { FileReaderSync } from "./helpers/msw/read-file-sync";
import { runInTempDir } from "./helpers/run-in-tmp";
Expand Down Expand Up @@ -365,6 +366,22 @@ describe("deploy", () => {
});
});

describe("warnings", () => {
it("should warn user when worker was last deployed from api", async () => {
msw.use(...mswSuccessDeploymentScriptAPI);
writeWranglerToml();
writeWorkerSource();
mockSubDomainRequest();
mockUploadWorkerRequest();

await runWrangler("deploy ./index");

expect(std.warn).toMatch(
/You are about to publish a Workers Service that was last updated via the script API/
);
});
});

describe("environments", () => {
it("should use legacy environments by default", async () => {
writeWranglerToml({ env: { "some-env": {} } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ export const mswSuccessDeploymentScriptMetadata = [
),
];

export const mswSuccessDeploymentScriptAPI = [
rest.get(
"*/accounts/:accountId/workers/services/:scriptName",
(_, res, ctx) => {
return res.once(
ctx.json(
createFetchResult({
default_environment: {
script: { last_deployed_from: "api", tag: "MOCK-TAG" },
},
})
)
);
}
),
];

export const mswSuccessDeploymentDetails = [
rest.get(
"*/accounts/:accountId/workers/deployments/by-script/:scriptTag/detail/:deploymentId",
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/__tests__/helpers/msw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
mswSuccessDeployments,
mswSuccessDeploymentScriptMetadata,
mswSuccessDeploymentDetails,
mswSuccessDeploymentScriptAPI,
} from "./handlers/deployments";
import { mswSuccessNamespacesHandlers } from "./handlers/namespaces";
import { mswSuccessOauthHandlers } from "./handlers/oauth";
Expand Down Expand Up @@ -49,4 +50,5 @@ export {
mswSuccessDeploymentDetails,
mswAccessHandlers,
mswSuccessDeploymentScriptMetadata,
mswSuccessDeploymentScriptAPI,
};
7 changes: 7 additions & 0 deletions packages/wrangler/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@
if (!(await confirm("Would you like to continue?"))) {
return;
}
} else if (default_environment.script.last_deployed_from === "api") {
logger.warn(
`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.`
);
if (!(await confirm("Would you like to continue?"))) {
return;

Check warning on line 291 in packages/wrangler/src/deploy/deploy.ts

View check run for this annotation

Codecov / codecov/patch

packages/wrangler/src/deploy/deploy.ts#L291

Added line #L291 was not covered by tests
}
}
} catch (e) {
// code: 10090, message: workers.api.error.service_not_found
Expand Down
Loading