-
Notifications
You must be signed in to change notification settings - Fork 1k
Add environment variable configuration support to wp-cli.yml #6169
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
base: main
Are you sure you want to change the base?
Conversation
- Add 'env' configuration key to config-spec.php - Create get_env_or_config() helper function in utils.php - Update get_cache_dir() to use config fallback - Update cache expiry/max_size to use config fallback - Update packages_dir to use config fallback - Add Behat tests for env variable configuration - Environment variables still take precedence over config Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Add env example to wp-cli.example.yml - Update JSON schema to include env property - Document that env values are fallbacks when env vars not set Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Add null check for runner->config in get_env_or_config() - Update schema description to clarify values are converted to strings - Allow both string and numeric types in schema (YAML parses numbers) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for configuring environment variable fallback values in wp-cli.yml configuration files. When environment variables like WP_CLI_CACHE_DIR are not set in the shell, WP-CLI will now check the configuration file for fallback values. Actual environment variables always take precedence over config values.
- Introduces a new
envconfiguration key inwp-cli.ymlfor defining environment variable fallbacks - Implements a
get_env_or_config()helper function that checks environment variables first, then config - Updates environment variable reads for cache directory, cache settings, and packages directory to use the new helper
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
php/config-spec.php |
Adds the env configuration specification with type <map> and documentation |
php/utils.php |
Implements get_env_or_config() helper function and updates get_cache_dir() to use it |
php/class-wp-cli.php |
Updates cache initialization to use get_env_or_config() for WP_CLI_CACHE_EXPIRY and WP_CLI_CACHE_MAX_SIZE |
php/WP_CLI/Runner.php |
Updates packages directory resolution to use get_env_or_config() for WP_CLI_PACKAGES_DIR |
schemas/wp-cli-config.json |
Adds JSON schema definition for the env property accepting strings and numbers |
schemas/wp-cli.example.yml |
Adds example configuration showing how to use the env key |
features/config.feature |
Adds Behat test scenarios verifying config fallback behavior and environment variable precedence |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add scenario testing WP_CLI_CACHE_EXPIRY configuration - Add scenario testing WP_CLI_CACHE_MAX_SIZE configuration - Add scenario testing environment variable precedence for both - Tests verify config fallbacks and env var override behavior Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Description
Adds support for configuring environment variable fallback values in
wp-cli.yml. When an environment variable likeWP_CLI_CACHE_DIRis not set in the shell, WP-CLI now checks the config file. Actual environment variables always take precedence.Changes
Core implementation:
envconfiguration key toconfig-spec.phpfor defining environment variable fallbacksWP_CLI\Utils\get_env_or_config()helper that checks environment first, then configget_cache_dir()forWP_CLI_CACHE_DIRWP_CLI_CACHE_EXPIRYandWP_CLI_CACHE_MAX_SIZEWP_CLI_PACKAGES_DIRDocumentation:
wp-cli-config.json) withenvproperty definitionwp-cli.example.ymlTests:
WP_CLI_CACHE_DIRWP_CLI_PACKAGES_DIRWP_CLI_CACHE_EXPIRYWP_CLI_CACHE_MAX_SIZEExample Usage
Running
wp cli infowill use these values when the corresponding environment variables are not set.How has this been tested?
Checklist:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.