Skip to content

Commit b8922b7

Browse files
Add env push confirmation bypass flags
Add --force and --yes to hydrogen env push so agents can push an already-computed environment diff without answering the confirmation prompt.\n\nThe command still fetches environments, filters read-only and secret variables, detects no-op pushes, and shows the existing prompt by default. When either confirmation flag is set, it skips only the final diff confirmation and proceeds to push the local variables.\n\nTests cover both flag spellings and assert that the prompt is skipped while the push mutation receives the expected variables. The Oclif manifest and changeset are updated for the new flags.\n\nCloses shop/issues-develop#22875
1 parent e64ef52 commit b8922b7

4 files changed

Lines changed: 84 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/cli-hydrogen': patch
3+
---
4+
5+
Add `--force` and `--yes` confirmation bypasses to `hydrogen env push`.

packages/cli/oclif.manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,21 @@
805805
"hasDynamicHelp": false,
806806
"multiple": false,
807807
"type": "option"
808+
},
809+
"force": {
810+
"char": "f",
811+
"description": "Push environment variable changes without confirmation.",
812+
"env": "SHOPIFY_HYDROGEN_FLAG_FORCE",
813+
"name": "force",
814+
"allowNo": false,
815+
"type": "boolean"
816+
},
817+
"yes": {
818+
"description": "Automatically confirm environment variable changes.",
819+
"env": "SHOPIFY_HYDROGEN_FLAG_YES",
820+
"name": "yes",
821+
"allowNo": false,
822+
"type": "boolean"
808823
}
809824
},
810825
"hasDynamicHelp": false,

packages/cli/src/commands/hydrogen/env/push.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,53 @@ describe('pushVariables', () => {
478478
);
479479
});
480480
});
481+
482+
it.each(['force', 'yes'] as const)(
483+
'does not prompt for diff confirmation when --%s is provided',
484+
async (confirmationFlag) => {
485+
vi.mocked(getStorefrontEnvVariables).mockResolvedValue({
486+
id: SHOPIFY_CONFIG.storefront.id,
487+
environmentVariables: [
488+
{
489+
id: '1',
490+
key: 'EXISTING_TOKEN',
491+
value: '1',
492+
isSecret: false,
493+
readOnly: false,
494+
},
495+
{
496+
id: '2',
497+
key: 'SECOND_TOKEN',
498+
value: '2',
499+
isSecret: false,
500+
readOnly: false,
501+
},
502+
],
503+
});
504+
505+
await inTemporaryDirectory(async (tmpDir) => {
506+
const filePath = joinPath(tmpDir, envFile);
507+
await writeFile(filePath, 'EXISTING_TOKEN=1\nSECOND_TOKEN=NEW_VALUE');
508+
await expect(
509+
runEnvPush({
510+
path: tmpDir,
511+
env: 'preview',
512+
envFile,
513+
[confirmationFlag]: true,
514+
}),
515+
).resolves.not.toThrow();
516+
517+
expect(renderConfirmationPrompt).not.toHaveBeenCalled();
518+
expect(pushStorefrontEnvVariables).toHaveBeenCalledWith(
519+
{storeFqdn: 'my-shop', token: 'abc123'},
520+
'gid://shopify/HydrogenStorefront/2',
521+
'gid://shopify/HydrogenStorefrontEnvironment/2',
522+
[
523+
{key: 'EXISTING_TOKEN', value: '1'},
524+
{key: 'SECOND_TOKEN', value: 'NEW_VALUE'},
525+
],
526+
);
527+
});
528+
},
529+
);
481530
});

packages/cli/src/commands/hydrogen/env/push.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Command from '@shopify/cli-kit/node/base-command';
2+
import {Flags} from '@oclif/core';
23
import {diffLines} from 'diff';
34
import {commonFlags, flagsToCamelObject} from '../../../lib/flags.js';
45
import {login} from '../../../lib/auth.js';
@@ -41,6 +42,15 @@ export default class EnvPush extends Command {
4142
...commonFlags.env,
4243
...commonFlags.envFile,
4344
...commonFlags.path,
45+
force: Flags.boolean({
46+
char: 'f',
47+
description: 'Push environment variable changes without confirmation.',
48+
env: 'SHOPIFY_HYDROGEN_FLAG_FORCE',
49+
}),
50+
yes: Flags.boolean({
51+
description: 'Automatically confirm environment variable changes.',
52+
env: 'SHOPIFY_HYDROGEN_FLAG_YES',
53+
}),
4454
};
4555

4656
async run(): Promise<void> {
@@ -52,13 +62,17 @@ export default class EnvPush extends Command {
5262
interface EnvPushOptions {
5363
env?: string;
5464
envFile: string;
65+
force?: boolean;
5566
path?: string;
67+
yes?: boolean;
5668
}
5769

5870
export async function runEnvPush({
5971
env: envHandle,
6072
envFile,
73+
force = false,
6174
path = process.cwd(),
75+
yes = false,
6276
}: EnvPushOptions) {
6377
let validatedEnvironment: Environment;
6478

@@ -181,7 +195,7 @@ export async function runEnvPush({
181195
body: 'No changes to your environment variables.',
182196
});
183197
return;
184-
} else {
198+
} else if (!force && !yes) {
185199
const diff = diffLines(comparableRemoteVars, compareableLocalVars);
186200
const confirmPush = await renderConfirmationPrompt({
187201
confirmationMessage: 'Yes, confirm changes',

0 commit comments

Comments
 (0)