Allow configuration via environment variables - #2860
Conversation
davidjgoss
left a comment
There was a problem hiding this comment.
Thanks for raising this @youdie006. It looks good at a glance, but please can you follow the standard pull request template including the CoC acknowledgement:
https://raw.githubusercontent.com/cucumber/.github/refs/heads/main/.github/PULL_REQUEST_TEMPLATE.md
Each configuration option can now be set via a CUCUMBER_OPTION_<SCREAMING_SNAKE> environment variable (e.g. retryTagFilter -> CUCUMBER_OPTION_RETRY_TAG_FILTER), following the design in cucumber#2347. Env values sit between the config file and the CLI in precedence (CLI > env > config file > default) and keep the existing merge semantics (tag expressions combine). Values are parsed as JSON where possible and validated against the config schema; unknown CUCUMBER_OPTION_* vars are ignored. Adds docs, a changelog entry, and tests.
96f1d5d to
c5e2259
Compare
|
Thanks @davidjgoss! I've updated the description to the standard template with the Code of Conduct acknowledgement, and pointed the CHANGELOG entry at this PR. Ready for another look when you have a moment. |
davidjgoss
left a comment
There was a problem hiding this comment.
Thanks again. A couple of suggestions to improve.
| CUCUMBER_OPTION_PARALLEL=2 CUCUMBER_OPTION_RETRY_TAG_FILTER='@flaky' cucumber-js | ||
| ``` | ||
|
|
||
| Values are parsed as JSON where possible, so booleans, numbers, arrays and objects can be expressed, while anything that isn't valid JSON (like a tag expression) is kept as a plain string: |
There was a problem hiding this comment.
This is an implementation detail and we could do without having it in the user-facing documentation.
There was a problem hiding this comment.
Looking at this now, I think my steer to have CUCUMBER_OPTION be the prefix we look for was a mistake and it's led us to a more complex implementation than is needed.
First, there are no collisions with other env vars, and given we also support CUCUMBER_PUBLISH_URL and CUCUMBER_PUBLISH_TOKEN, having the extra prefix causes fragmentation from a user perspective. So I think just e.g. CUCUMBER_RETRY_TAG_FILTER is fine.
Second, we already have the list of option names to check (from the default flag config object), so we can have fewer loops and less code by simply iterating over those keys, and for each one forming the env var key and checking env for it - no need to iterate over the whole env object.
🤔 What's changed?
Each configuration option can now be set via an environment variable (#2347). An option's key is converted to
CUCUMBER_OPTION_<SCREAMING_SNAKE>— e.g.retryTagFilter→CUCUMBER_OPTION_RETRY_TAG_FILTER— following @davidjgoss's design in the issue.mergeConfigurationsbetween the config file and CLI), preserving the existing merge-vs-overwrite semantics (e.g.CUCUMBER_OPTION_TAGSand--tagscombine into(@a) and (@b)).CUCUMBER_OPTION_*vars are ignored. Profile-level options are out of scope, per the issue.fromEnvmodule; the public API surface is unchanged (verified by api-extractor).⚡️ What's your motivation?
Fixes #2347 — lets every configuration option be provided via the environment (useful in CI), which previously wasn't possible for most options.
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
The precedence placement (env between config file and CLI) and the
CUCUMBER_OPTION_TAGSmerge semantics — happy to adjust if you'd prefer different behaviour. Quick manual check:CUCUMBER_OPTION_DRY_RUN=trueskips scenarios;CUCUMBER_OPTION_TAGS='@wip'with--tags 'not @wip'resolves to(@wip) and (not @wip).📋 Checklist: