Skip to content

Add host-tools/setup.sh to create .env with prompts - #348

Open
iarif4u wants to merge 1 commit into
WordPress:masterfrom
iarif4u:add/host-tools-setup
Open

iarif4u wants to merge 1 commit into
WordPress:masterfrom
iarif4u:add/host-tools-setup

Conversation

@iarif4u

@iarif4u iarif4u commented Oct 2, 2026

Copy link
Copy Markdown

Part of #257 (the first idea: set up .env with prompts instead of vim). The one-step run script is in #346 for #260.

Purpose

Hosts say that the runner install is tedious. Today, they clone the repo, copy .env.default, edit it in vim, and find out on the first run whether the database credentials work. This script does those steps and checks them.

What host-tools/setup.sh does

  1. Checks the software: php git rsync wget unzip node npm. composer is optional. It prints the Node.js and npm versions and stops with a list if something is missing.
  2. Asks for the values: database name, user, password, host, PHP executable, checkout directory, and the report API key. Passwords and the API key are not shown when you type them. Press Enter to keep the current value.
  3. Tests the database connection with the runner's own wpt_runner_parse_db_host() and mysqli, using WPT_PHP_EXECUTABLE. If the connection fails, .env is not changed.
  4. Writes .env from .env.default. It changes only the lines it asks about. It quotes each value safely, sets the file mode to 600, and saves the old .env as .env.bak-<timestamp>.

Also:

  • Sets WPT_TEST_DIR to WPT_PREPARE_DIR. With .env.default as it is, the two are different (wp-test-runner and /tmp/wp-test-runner), so a local run stops in check_required_env() with "WPT_TEST_DIR must be the same as WPT_PREPARE_DIR".
  • --non-interactive takes the values from the environment, for provisioning tools. --skip-checks and --skip-db-check skip those steps.
  • Warns when run as root.
  • It does not install software, create the database, or set up cron. Those are different for each host.

The README "Configuring the Runner" section now mentions the script first, before the manual steps.

Testing

Tested against a real MySQL 9.6 server with PHP 8.4:

Case Result
--non-interactive, correct credentials Connects, writes .env (mode 600), exit 0
source .env, then check_required_env() Passes
Wrong password "Access denied", .env unchanged, exit 1
Invalid WPT_DB_HOST "WPT_DB_HOST is not valid", .env unchanged
Interactive, values with ', #, $ and spaces Values are the same after source .env
Run again, Enter for every value Keeps the values, saves a backup
Environment value set Environment value wins over the current .env
node, npm or wget missing Lists the missing software, exit 1

Contributed at WordCamp Contributor Day.

Checks the required software, asks for the database credentials and the
report API key, tests the database connection with mysqli, and writes
.env from .env.default. WPT_TEST_DIR is set to WPT_PREPARE_DIR, which a
local run requires. --non-interactive takes the values from the
environment.

Part of WordPress#257.
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: iarif4u <iarif4u@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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.

1 participant