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

feat: support branch values for environment variable contexts #4977

Merged
merged 17 commits into from Aug 22, 2022

Conversation

jasonbarry
Copy link
Member

@jasonbarry jasonbarry commented Aug 18, 2022

Summary

Fixes https://github.com/netlify/pillar-workflow/issues/814

This PR lets users specify branches as contexts for the various env commands. netlify build allows using a --context flag to build a site using env vars specified in the toml file as under [context.<thing>.environment], where <thing> is either a reserved context keyword (like dev, production, or deploy-preview), or any string, which corresponds to a git branch.

We've ported over that functionality to the UI to allow these types of branch overrides to be more specific than contexts when the git branch matches. For example, if you set FOO=bar for the branch-deploy context, and also have a branch-specific value of FOO=bang on the staging branch, the value of bang will take precedence when you visit the staging branch's branch deploy.

This PR brings parity to the CLI so that you can use env, build, and dev commands to get/set environment variable values to have a branch-specific value.

You can use branch-specific values simply by using a non-reserved context keyword like ntl env:get --context staging, or by prepending the branch: prefix, like ntl env:get --context branch:staging, for clarity.

Branch names are normalized using commander's custom option processing.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

Screenshot 2022-08-18 at 17 17 29

@jasonbarry jasonbarry changed the title Feat/branch values in env commands feat: support branch values for env var contexts Aug 18, 2022
@github-actions github-actions bot added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Aug 18, 2022
@jasonbarry jasonbarry self-assigned this Aug 18, 2022
@github-actions
Copy link

github-actions bot commented Aug 18, 2022

📊 Benchmark results

Comparing with 2c337b0

Package size: 222 MB

(no change)

^  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB  222 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@jasonbarry jasonbarry changed the title feat: support branch values for env var contexts feat: support branch values for environment variable contexts Aug 19, 2022
@jasonbarry jasonbarry marked this pull request as ready for review August 19, 2022 00:34
@jasonbarry jasonbarry requested a review from a team as a code owner August 19, 2022 00:34
Copy link
Contributor

@codebyuma codebyuma left a comment

Choose a reason for hiding this comment

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

Looks good to me! Left one suggestion (in two places)

**Examples**

```bash
netlify env:list # list dev context and any scope
Copy link
Contributor

Choose a reason for hiding this comment

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

[sand] suggestion to elaborate a bit, similar to the example you used for get:

Suggested change
netlify env:list # list dev context and any scope
netlify env:list # list variables with values in the dev context and with any scope

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, I assume this is auto-generated, I'll leave this comment in the JS file :)

)
.addOption(
new Option('-s, --scope <scope>', 'Specify a scope')
.choices(['builds', 'functions', 'post_processing', 'runtime', 'any'])
.default('any'),
)
.addExamples([
'netlify env:list # list dev context and any scope',
Copy link
Contributor

Choose a reason for hiding this comment

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

[sand] suggestion to elaborate a bit, similar to the example you used for get:

Suggested change
'netlify env:list # list dev context and any scope',
'netlify env:list # list variables with values in the dev context and with any scope',

Copy link

@melanierichards melanierichards left a comment

Choose a reason for hiding this comment

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

All my feedback from issues has been addressed, thanks! LGTM! :shipit:

Copy link

@melanierichards melanierichards left a comment

Choose a reason for hiding this comment

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

Refreshing my approval status after the copy updates, LGTM! 🚀

codebyuma
codebyuma previously approved these changes Aug 22, 2022
@@ -144,7 +144,7 @@ const createEnvListCommand = (program) =>
.default('any'),
)
.addExamples([
'netlify env:list # list dev context and any scope',
'netlify env:list # list variables with values in the dev context and with any scope',
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@jasonbarry jasonbarry added the automerge Add to Kodiak auto merge queue label Aug 22, 2022
@jasonbarry jasonbarry merged commit f434f57 into main Aug 22, 2022
@jasonbarry jasonbarry deleted the feat/branch-values-in-env-commands branch August 22, 2022 20:20
khendrikse pushed a commit that referenced this pull request Sep 9, 2022
* feat: support branch values in env:list

* feat: support branch values in env:get

* feat: support branch values for contexts in build and dev

* feat: support branch values for contexts in env:set

* feat: support branch values for contexts in env:unset

* test: fix some tests

* fix: remove cruft

* docs: npm run docs

* chore: update logs to print either `context` or `branch` correctly

* test: update tests

* fix: fix example help text in `env:get --help`

* fix: fix netlify/pillar-workflow#818

* fix: fix netlify/pillar-workflow#815

* fix: fix netlify/pillar-workflow#816 and fix netlify/pillar-workflow#817

* docs: addressing uma's feedback

* chore: update contributors field

Co-authored-by: jasonbarry <jasonbarry@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Add to Kodiak auto merge queue type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants