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

Add --env & deprecate --env-branch flag for Hydrogen CLI commands #1841

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

aswamy
Copy link
Contributor

@aswamy aswamy commented Mar 12, 2024

WHY are these changes introduced?

  • Adding --env flag to standardize how we refer to environments in the CLI
    • pass in an environment's handle you can view from running env list
    • remove existing --env flag which was used to identify environment by name (used only by env push__unstable)
    • deprecate --env-branch from env pull, env push__unstable, deploy, preview, dev-vite, dev

WHAT is this pull request doing?

HOW to test your changes?

  • checkout branch
  • npm ci && cd packages/cli & npm run build
  • If you don't have a hydrogen storefront project, npx shopify hydrogen init and connect it a repo on Admin
  • In packages/cli test the following commands:
    • view handles: npx shopify hydrogen env list --path=/path/to/repo
    • deploy without specifying env handle: npx shopify hydrogen deploy --path=/path/to/repo
    • deploy by specifying env handle: npx shopify hydrogen deploy --path=/path/to/repo --env-handle=production
    • deploy by specifying a bad env handle: npx shopify hydrogen deploy --path=/path/to/repo --env-handle=fake
    • pull environment variables for preview: npx shopify hydrogen env pull --path=/path/to/repo
    • pull environment variables for production: npx shopify hydrogen env pull --path=/path/to/repo --env-handle=production
    • pull environment variables using bad env handle: npx shopify hydrogen env pull --path=/path/to/repo --env-handle=fake
    • Add an environment variable in the .env file in the storefront project
    • push environment variables for preview: npx shopify hydrogen env push__unstable --path=/path/to/repo
    • push environment variables for production: npx shopify hydrogen env push__unstable --path=/path/to/repo --env-handle=production
    • push environment variables using bad env handle: npx shopify hydrogen env push__unstable --path=/path/to/repo --env-handle=fake

Screenshots

env list
image

env pull
image

env push__unstable
image

deploy
image

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation
    • This will be a follow-up PR

Copy link
Contributor

shopify bot commented Mar 12, 2024

Oxygen deployed a preview of your add-env-handle-flag branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment March 22, 2024 7:25 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment March 22, 2024 7:25 PM
vite ✅ Successful (Logs) Preview deployment Inspect deployment March 22, 2024 7:25 PM
subscriptions ✅ Successful (Logs) Preview deployment Inspect deployment March 22, 2024 7:25 PM
optimistic-cart-ui ✅ Successful (Logs) Preview deployment Inspect deployment March 22, 2024 7:25 PM
skeleton ✅ Successful (Logs) Preview deployment Inspect deployment March 22, 2024 7:25 PM

Learn more about Hydrogen's GitHub integration.

@aswamy aswamy force-pushed the add-env-handle-flag branch 2 times, most recently from 2ca814c to f15297f Compare March 12, 2024 19:32
@aswamy aswamy self-assigned this Mar 12, 2024
Copy link
Contributor

@graygilmore graygilmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial thoughts

packages/cli/src/commands/hydrogen/deploy.ts Show resolved Hide resolved
packages/cli/src/lib/flags.ts Outdated Show resolved Hide resolved
packages/cli/src/lib/flags.ts Outdated Show resolved Hide resolved
@aswamy aswamy changed the title Add --env-handle & remove --env-branch flag for deploy & env pull Add --env-handle & deprecate --env-branch flag for deploy & env pull Mar 14, 2024
@aswamy aswamy changed the title Add --env-handle & deprecate --env-branch flag for deploy & env pull Add --env & deprecate --env-branch flag for Hydrogen CLI commands Mar 14, 2024
@aswamy
Copy link
Contributor Author

aswamy commented Mar 14, 2024

Force Push

  • Re-added --envBranch to Hydrogen CLI commands
  • Rename --envHandle to --env
  • Ensure user can't pass in --envBranch and --env at the same time
  • Remove -e shorthand for --envBranch flag
  • Changed description for --envBranch flag so it's more generic
  • The following commands will now allow you to pass in --envBranch or --env: env pull, env push__unstable, deploy, dev, dev-vite, preview

What happens when you pass in both flags?

An error is shown
image

What happens when you pass in the deprecated --envBranch flag?

You see a warning and get directed towards the newer flag
image

What happens when you pass in --env flag?

You see not warning
image

Where can i see the handles?

Run env list
image

Copy link
Contributor

@graygilmore graygilmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Did a whole bunch of 🎩ing and commented on a couple of things that popped up for me.

.changeset/lovely-donkeys-destroy.md Outdated Show resolved Hide resolved
packages/cli/src/commands/hydrogen/env/list.ts Outdated Show resolved Hide resolved
packages/cli/src/lib/common.ts Outdated Show resolved Hide resolved
Comment on lines 365 to 368
environmentTag = findEnvironmentByBranchOrThrow(
deploymentData?.environments || [],
envBranch,
).branch;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change in behavior that I think makes sense but could also be considered a breaking change. This change would mean that you cannot use the --env-branch flag in CI. Prefer to support the existing behavior and let envHandle be the new flow.

Could tackle this a few different ways so you've got options!

(deploymentData?.environments is always undefined in CI so this will always throw)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh dang... this means that --env-handle wouldn't work in CI as well... OxygenCLI only understands branch names (not handles).

Prefer to support the existing behavior and let envHandle be the new flow.

Does this mean that --env-handle should exclusively be for non-CI?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that --env-handle should exclusively be for non-CI?

exactly!

env: 'SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH',
deprecated: {
to: 'env',
message: 'Flag is deprecated. Use --env instead.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renders as:

›   Warning: Flag is deprecated. Use --env instead.

with no indication as to which flag is deprecated. Maybe we could do:

Suggested change
message: 'Flag is deprecated. Use --env instead.',
message: '--env-branch is deprecated. Use --env instead.',

Not sure if we want to mention that it'll be removed in a future version or of that's implied.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's implied. I also don't know if we will remember to remove it in the following major version. We need a TODO list of "these are items we need to update / remove before the next major version" before we promise what will be changed/removed in the following version of Hydrogen CLI.

packages/cli/src/lib/flags.ts Show resolved Hide resolved
packages/cli/src/lib/common.ts Show resolved Hide resolved
Copy link
Contributor

@benwolfram benwolfram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing stands out to me, but still some ongoing things from Gray's feedback. I'll re-review when the dust settles! Great stuff here and improvements though.

@aswamy
Copy link
Contributor Author

aswamy commented Mar 15, 2024

Force push

  • Update changeset message
  • Update flag deprecation message
  • deploy's envHandle flag will only work in non-CI environments (added a test for that as well)
  • correct spacing for env list
  • update "next steps" when environment not found

(await getStorefrontEnvironments(session, config.storefront.id))
?.environments || [];
if (envHandle) {
findEnvironmentOrThrow(environments, envHandle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this write to envHandle or envBranch variable? Or is just a code check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just to check and throw if the user provided bad envHandle

}),
},
env: {
env: Flags.string({
envBranch: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some sort of /** @deprecated **/ comment around here so that we remember to deprecate this in the next major bump?

Copy link
Contributor Author

@aswamy aswamy Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Do we have a standard for this? I would love to group all of our breaking changes into a major bump. Unless this comment is our standard 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to do something like this for deprecated stuff, yeah.

Comment on lines +70 to 81
'env-branch': Flags.string({
description:
"Specifies an environment's name when using remote environment variables.",
env: 'SHOPIFY_HYDROGEN_ENVIRONMENT_NAME',
'Specifies the environment to perform the operation using its Git branch name.',
env: 'SHOPIFY_HYDROGEN_ENVIRONMENT_BRANCH',
deprecated: {
to: 'env',
message: '--env-branch is deprecated. Use --env instead.',
},
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this one should be hidden: true to avoid new uses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

envBranch is the old flag we want to deprecate
env is the new flag we want users to start using right away. We will deprecate it in the following major bump.

for Hydrogen CLI commands
@aswamy aswamy merged commit 11879b1 into main Mar 25, 2024
13 checks passed
@aswamy aswamy deleted the add-env-handle-flag branch March 25, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants