Skip to content

Commit 61357d3

Browse files
committed
only try to sync parent env vars for preview deployments
1 parent 2e46524 commit 61357d3

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.$slug.import.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export async function action({ params, request }: ActionFunctionArgs) {
4747
})),
4848
});
4949

50+
// Only sync parent variables if this is a branch environment
5051
if (environment.parentEnvironmentId && body.parentVariables) {
5152
const parentResult = await repository.create(environment.project.id, {
5253
override: typeof body.override === "boolean" ? body.override : false,

packages/cli-v3/src/commands/deploy.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
195195

196196
const branch =
197197
options.env === "preview" ? getBranch({ specified: options.branch, gitMeta }) : undefined;
198+
198199
if (options.env === "preview" && !branch) {
199200
throw new Error(
200201
"Didn't auto-detect preview branch, so you need to specify one. Pass --branch <branch>."
@@ -318,10 +319,9 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
318319
}
319320

320321
const hasVarsToSync =
321-
buildManifest.deploy.sync &&
322-
((buildManifest.deploy.sync.env && Object.keys(buildManifest.deploy.sync.env).length > 0) ||
323-
(buildManifest.deploy.sync.parentEnv &&
324-
Object.keys(buildManifest.deploy.sync.parentEnv).length > 0));
322+
Object.keys(buildManifest.deploy.sync?.env || {}).length > 0 ||
323+
// Only sync parent variables if this is a branch environment
324+
(branch && Object.keys(buildManifest.deploy.sync?.parentEnv || {}).length > 0);
325325

326326
if (hasVarsToSync) {
327327
const childVars = buildManifest.deploy.sync?.env ?? {};
@@ -333,21 +333,22 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
333333
if (!options.skipSyncEnvVars) {
334334
const $spinner = spinner();
335335
$spinner.start(`Syncing ${numberOfEnvVars} env ${vars} with the server`);
336-
const success = await syncEnvVarsWithServer(
336+
337+
const uploadResult = await syncEnvVarsWithServer(
337338
projectClient.client,
338339
resolvedConfig.project,
339340
options.env,
340341
childVars,
341342
parentVars
342343
);
343344

344-
if (!success) {
345+
if (!uploadResult.success) {
345346
await failDeploy(
346347
projectClient.client,
347348
deployment,
348349
{
349350
name: "SyncEnvVarsError",
350-
message: `Failed to sync ${numberOfEnvVars} env ${vars} with the server`,
351+
message: `Failed to sync ${numberOfEnvVars} env ${vars} with the server: ${uploadResult.error}`,
351352
},
352353
"",
353354
$spinner
@@ -587,13 +588,11 @@ export async function syncEnvVarsWithServer(
587588
envVars: Record<string, string>,
588589
parentEnvVars?: Record<string, string>
589590
) {
590-
const uploadResult = await apiClient.importEnvVars(projectRef, environmentSlug, {
591+
return await apiClient.importEnvVars(projectRef, environmentSlug, {
591592
variables: envVars,
592593
parentVariables: parentEnvVars,
593594
override: true,
594595
});
595-
596-
return uploadResult.success;
597596
}
598597

599598
async function failDeploy(
@@ -637,7 +636,7 @@ async function failDeploy(
637636
console.log(lastFewLines);
638637
}
639638
} else {
640-
outro(`${chalkError(`${prefix}:`)} ${error.message}.`);
639+
outro(`${chalkError(`${prefix}:`)} ${error.message}`);
641640
}
642641
};
643642

0 commit comments

Comments
 (0)