From 4a1bcc8cb98b486aca70252d6606781d59280c62 Mon Sep 17 00:00:00 2001 From: "Md. Arifur Rahman" Date: Fri, 2 Oct 2026 10:57:46 +0600 Subject: [PATCH 1/2] Add host-tools/testrunner.sh to run the full test cycle in one step Updates the runner, loads .env, and runs prepare, test, report and cleanup. The report still runs when tests fail, cleanup always runs, and a lock stops overlapping runs from cron. Fixes #260. Creates the host-tools directory from #259. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 ++++ host-tools/testrunner.sh | 71 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 host-tools/testrunner.sh diff --git a/README.md b/README.md index 4302671..7df8c30 100644 --- a/README.md +++ b/README.md @@ -573,6 +573,12 @@ Some suggestions: ### Script en Bash +The runner includes a ready-made script for this: [`host-tools/testrunner.sh`](host-tools/testrunner.sh). It updates the runner and runs the 4 steps. It also runs the report when a test fails, always cleans up, and stops when another run is still active. Use it in place of the example below: + +```bash +bash /home/wptestrunner/phpunit-test-runner/host-tools/testrunner.sh +``` + This is a simple example of a Bash script that could be placed in the directory above the software. For example, at `/home/wptestrunner/`. ```bash diff --git a/host-tools/testrunner.sh b/host-tools/testrunner.sh new file mode 100755 index 0000000..1b5bce9 --- /dev/null +++ b/host-tools/testrunner.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# +# Run the full test cycle in one step: update the runner, prepare, test, +# report and clean up. +# +# Use this after the runner is set up and its .env file is configured +# (database credentials, and WPT_REPORT_API_KEY if you report results). +# +# Usage: +# ./host-tools/testrunner.sh +# +# Example cron entry (every 4 hours): +# 0 */4 * * * /home/wptestrunner/phpunit-test-runner/host-tools/testrunner.sh >> /home/wptestrunner/testrunner.log 2>&1 +# +# Optional environment variables: +# WPT_RUNNER_DIR Path to the runner directory. Default: the parent of this script's directory. +# WPT_SKIP_UPDATE Set to 1 to skip "git pull" (for example, when you test local changes). +# +# The PHP binary comes from WPT_PHP_EXECUTABLE in .env (default: php), the +# same setting that the runner uses to run the tests. +# +# Exit status: 0 when every step succeeds, 1 when any step fails. + +set -uo pipefail + +RUNNER_DIR="${WPT_RUNNER_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" + +cd "$RUNNER_DIR" || { echo "Error: cannot open runner directory: $RUNNER_DIR" >&2; exit 1; } + +if [[ ! -f .env ]]; then + echo "Error: $RUNNER_DIR/.env not found. Copy .env.default to .env and configure it first." >&2 + exit 1 +fi + +# Stop when another run is still active, for example a slow run that cron starts again. +if command -v flock >/dev/null 2>&1; then + exec 9>"${TMPDIR:-/tmp}/wpt-testrunner-$(id -u).lock" + if ! flock -n 9; then + echo "Another test run is still active. Stopping." >&2 + exit 1 + fi +fi + +if [[ "${WPT_SKIP_UPDATE:-0}" != "1" ]]; then + git pull --ff-only origin master || echo "Warning: could not update the runner. Continuing with the current version." >&2 +fi + +# shellcheck source=/dev/null +source .env + +read -r -a PHP <<< "${WPT_PHP_EXECUTABLE:-php}" + +status=0 + +# Always clean up, also when a step fails or the run is stopped. +trap '"${PHP[@]}" cleanup.php || status=1' EXIT + +if ! "${PHP[@]}" prepare.php; then + echo "Error: prepare.php failed. Skipping the tests and the report." >&2 + exit 1 +fi + +# test.php exits with a non-zero status when a test fails. +# Run the report anyway, so that the failures are reported. +"${PHP[@]}" test.php || status=1 +"${PHP[@]}" report.php || status=1 + +trap - EXIT +"${PHP[@]}" cleanup.php || status=1 + +exit "$status" From 41575c3ead8e73db25299814fdd612632d17b961 Mon Sep 17 00:00:00 2001 From: "Md. Arifur Rahman" Date: Fri, 2 Oct 2026 22:52:43 +0600 Subject: [PATCH 2/2] Use a placeholder path in the testrunner.sh examples The examples hardcoded /home/wptestrunner. Use /path/to/phpunit-test-runner instead, and note that the script finds the runner from its own location. --- README.md | 4 ++-- host-tools/testrunner.sh | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7df8c30..405ea9d 100644 --- a/README.md +++ b/README.md @@ -573,10 +573,10 @@ Some suggestions: ### Script en Bash -The runner includes a ready-made script for this: [`host-tools/testrunner.sh`](host-tools/testrunner.sh). It updates the runner and runs the 4 steps. It also runs the report when a test fails, always cleans up, and stops when another run is still active. Use it in place of the example below: +The runner includes a ready-made script for this: [`host-tools/testrunner.sh`](host-tools/testrunner.sh). It updates the runner and runs the 4 steps. It also runs the report when a test fails, always cleans up, and stops when another run is still active. Replace `/path/to/phpunit-test-runner` with the directory of your clone, and use it in place of the example below: ```bash -bash /home/wptestrunner/phpunit-test-runner/host-tools/testrunner.sh +bash /path/to/phpunit-test-runner/host-tools/testrunner.sh ``` This is a simple example of a Bash script that could be placed in the directory above the software. For example, at `/home/wptestrunner/`. diff --git a/host-tools/testrunner.sh b/host-tools/testrunner.sh index 1b5bce9..d9927e8 100755 --- a/host-tools/testrunner.sh +++ b/host-tools/testrunner.sh @@ -9,8 +9,10 @@ # Usage: # ./host-tools/testrunner.sh # -# Example cron entry (every 4 hours): -# 0 */4 * * * /home/wptestrunner/phpunit-test-runner/host-tools/testrunner.sh >> /home/wptestrunner/testrunner.log 2>&1 +# Example cron entry (every 4 hours). Replace /path/to/phpunit-test-runner with +# the directory of your clone. The script finds the runner from its own location, +# so it does not need to be started from that directory: +# 0 */4 * * * /path/to/phpunit-test-runner/host-tools/testrunner.sh >> /path/to/testrunner.log 2>&1 # # Optional environment variables: # WPT_RUNNER_DIR Path to the runner directory. Default: the parent of this script's directory.