Skip to content

Commit 5aebbfc

Browse files
NicolappsConvex, Inc.
authored andcommitted
cli: don’t ignore --preview-create (#43484)
Currently, we ignore `--preview-create` when it is used with a non-preview deploy key. This behavior is unintuitive, because it leads users to believe that they are deploying to a preview deployment when they are in fact deploying to production. Instead, let’s throw an error in this situation. GitOrigin-RevId: 2c41b071175107d2e9233fd7c936c10f5977f907
1 parent 86b552d commit 5aebbfc

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22

33
## Unreleased
4+
- The `--preview-create` parameter for `npx convex deploy` will now error if
5+
used with a deploy key that is not a preview deploy key. Previously, the flag
6+
would be ignored in this situation, and `npx convex deploy` would deploy
7+
to the production deployment. If you were depending on this behavior, make
8+
sure to remove the `--preview-create` flag when deploying to production.
9+
10+
## 1.29.2
411

512
## 1.29.2
613

src/cli/deploy.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const deploy = new Command("deploy")
4444
.addOption(
4545
new Option(
4646
"--preview-create <name>",
47-
"The name to associate with this deployment if deploying to a newly created preview deployment. Defaults to the current Git branch name in Vercel, Netlify and GitHub CI. This is ignored if deploying to a production deployment.",
47+
"The name to associate with this deployment if deploying to a newly created preview deployment. Defaults to the current Git branch name in Vercel, Netlify and GitHub CI. This parameter can only be used with a preview deploy key (when used with another type of key, the command will return an error).",
4848
).conflicts("preview-name"),
4949
)
5050
.addOption(
@@ -147,6 +147,22 @@ Same format as .env.local or .env files, and overrides them.`,
147147
},
148148
);
149149
} else {
150+
if (cmdOptions.previewCreate !== undefined) {
151+
const source =
152+
deploymentSelection.kind === "deploymentWithinProject" &&
153+
deploymentSelection.targetProject.kind === "deploymentName"
154+
? `at ${chalk.blue.underline(`https://dashboard.convex.dev/dp/${deploymentSelection.targetProject.deploymentName}/settings#preview-deploy-keys`)}`
155+
: deploymentSelection.kind === "existingDeployment" &&
156+
deploymentSelection.deploymentToActOn.deploymentFields !== null
157+
? `at ${chalk.blue.underline(`https://dashboard.convex.dev/dp/${deploymentSelection.deploymentToActOn.deploymentFields.deploymentName}/settings#preview-deploy-keys`)}`
158+
: "on the dashboard";
159+
await ctx.crash({
160+
exitCode: 1,
161+
errorType: "fatal",
162+
printedMessage: `Preview deployments can only be created with preview deploy keys. Generate a preview deploy key ${source} and set the ${chalk.bold(`CONVEX_DEPLOY_KEY`)} environment variable with it.`,
163+
});
164+
}
165+
150166
await deployToExistingDeployment(ctx, {
151167
...cmdOptions,
152168
allowDeletingLargeIndexes:

0 commit comments

Comments
 (0)