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

allow configuration via environment variables #2347

Open
davidjgoss opened this issue Oct 24, 2023 · 8 comments
Open

allow configuration via environment variables #2347

davidjgoss opened this issue Oct 24, 2023 · 8 comments
Labels
good first issue Good for newcomers ✅ accepted The core team has agreed that it is a good idea to fix this ⚡ enhancement Request for new functionality

Comments

@davidjgoss
Copy link
Contributor

davidjgoss commented Oct 24, 2023

🤔 What's the problem you've observed?

Cucumber can be configured via the CLI and files, but not via environment variables (except the publish functionality which does support some).

This means users that configure most of their other stuff with environment variables often have a sort of frankenstein setup, with some stuff living in the Cucumber config (maybe in profiles) and other somewhat related stuff sitting elsewhere (e.g. in .env files).

✨ Do you have a proposal for making it better?

Support configuring Cucumber via environment variables.

When resolving configuration, each option should be sought from environment variables by converting its key to uppercase-with-underscores format, prefixing with CUCUMBER_OPTION_, and then checking the environment for that key. So for example, retryTagFilter would be expressed as CUCUMBER_RETRY_TAG_FILTER and so on.

TBA on how things like booleans and arrays should be expressed and parsed. We should follow conventions set by other tools if they exist.

Environment variables should take precedence over the configuration file and default, but not over the CLI, which "wins" because it's been passed directly in the command. All options should maintain their current merge vs overwrite behaviour.

Profile-level options are out of scope.

📚 Any additional context?

See conversation on #2346.


This text was originally generated from a template, then edited by hand. You can modify the template here.

@davidjgoss davidjgoss added the 🏦 debt Tech debt label Oct 24, 2023
@davidjgoss davidjgoss added ✅ accepted The core team has agreed that it is a good idea to fix this ⚡ enhancement Request for new functionality and removed 🏦 debt Tech debt labels Oct 24, 2023
@vitalets
Copy link

Do we really need this third source of truth?
Currently if I want some parameter to be configured via env var, I can explicitly define that:

export default {
  retryTagFilter: process.env.MY_VARIABLE_FOR_TAG_FILTER
}

@davidjgoss
Copy link
Contributor Author

Do we really need this third source of truth?

Need? No. But I think it's worthwhile (if not exactly urgent).

@Ben-EJ
Copy link

Ben-EJ commented Nov 27, 2023

Mind if I give this a go? : )

@davidjgoss
Copy link
Contributor Author

@Ben-EJ definitely, feel free to give this a go!

I've just updated the description to clarify a 1) the prefix should be CUCUMBER_OPTION_ to avoid collisions with env vars that we set from Cucumber and 2) the CLI is still top in order of priority.

To give you an idea of where to look, https://github.com/cucumber/cucumber-js/blob/main/src/api/load_configuration.ts#L40-L44 is where the configurations from different places (currently defaults, config file and CLI) are merged together, so capturing from the environment should probably happen around here.

Feel free to drop into #committers-js on the Slack or raise a draft PR if you want some early feedback/guidance!

@davidjgoss davidjgoss added the good first issue Good for newcomers label Dec 21, 2023
@0v00
Copy link

0v00 commented Feb 28, 2024

hey @davidjgoss is this still open to be worked on?

@davidjgoss
Copy link
Contributor Author

@0v00 sure, let me know if you need any advice.

@0v00
Copy link

0v00 commented Mar 31, 2024

hey @davidjgoss sorry for the delay, but i should be able to open a PR shortly.

i just want to clarify some behavior - in a situation where we set e.g. CUCUMBER_TAGS="@foo" and also pass in options.provided tag values e.g. --tags "@bar or @baz", what do we want the expected output to be in this case? should we be expecting a merge of values e.g. (@foo) and (@bar or @baz) or should the options.provided values overwrite the ENV values, resulting in (@bar or @baz)? thanks

@davidjgoss
Copy link
Contributor Author

davidjgoss commented Apr 4, 2024

Sorry for the late reply @0v00!

To your question, yes this should merge and your example is just right. For all config options we should replicate the existing behaviour (either merge or override depending on type), it's just a case of slotting the env-sourced ones in between CLI and config file.

Hope this helps, let me know if you need anything else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers ✅ accepted The core team has agreed that it is a good idea to fix this ⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

4 participants