Commit 5d6ecd70aaa for woocommerce
commit 5d6ecd70aaacefcdbd476cc183ab229a446f2f64
Author: Ján Mikláš <neosinner@gmail.com>
Date: Tue Nov 17 17:24:36 2026 +0100
Share the extension config reader and schema (#71060)
* Share the extension config reader
* Add config reader changelog
diff --git a/packages/js/extension-tooling/README.md b/packages/js/extension-tooling/README.md
index 458bb8db9d5..18e679e6bbe 100644
--- a/packages/js/extension-tooling/README.md
+++ b/packages/js/extension-tooling/README.md
@@ -2,6 +2,19 @@
Install `@woocommerce/extension-tooling` as a development dependency in the extension.
+## Extension configuration
+
+The reader uses Bash and `jq` to validate `config.woo` in the extension's `package.json` and apply defaults. Run it from the extension root.
+
+```sh
+pnpm exec woo-extension-config
+pnpm exec woo-extension-config '.zip.root'
+```
+
+Use `--github-output` to write the normalized JSON to `GITHUB_OUTPUT` under `json`. Use `--phpunit-matrix` to get the selected PHPUnit legs for the current extension. Set `SUITE=integration` for integration legs (the default is `unit`), or `SCHEDULED=true` to include scheduled legs. `REQUESTED_WP`, `REQUESTED_WC` and `REQUESTED_PHP` set version overrides, and `PREVIOUS_WP` supplies the version for `previous` WordPress legs.
+
+To run the reader before installing dependencies, get `bin/woo-config.sh` and `bin/woo-config.schema.json` from the same reviewed commit of this package. Keep the files in the same directory and run `bash /path/to/woo-config.sh` from the extension root.
+
## Webpack
Import the helpers from the extension's webpack configuration. Keep the entry paths, output paths and match patterns in that configuration.
diff --git a/packages/js/extension-tooling/bin/woo-config.schema.json b/packages/js/extension-tooling/bin/woo-config.schema.json
new file mode 100644
index 00000000000..464624859a4
--- /dev/null
+++ b/packages/js/extension-tooling/bin/woo-config.schema.json
@@ -0,0 +1,470 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "title": "package.json config.woo",
+ "description": "Per-plugin settings of the shared WooCommerce plugin tooling. bin/woo-config.sh validates the object against this schema and applies the defaults shown here.",
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "slug": {
+ "type": "string",
+ "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
+ "description": "Plugin slug: the name of the ZIP, the release asset and the WooCommerce.com or WordPress.org product. Default: the package.json name."
+ },
+ "mainFile": {
+ "type": "string",
+ "pattern": "\\.php$",
+ "description": "Main plugin file. Default: <slug>.php."
+ },
+ "productName": {
+ "type": "string",
+ "description": "Product name for docs and messages. Default: the slug."
+ },
+ "capabilities": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "js": {
+ "type": "boolean",
+ "default": true,
+ "description": "pnpm dependencies and the JavaScript gate (check:js, lint:md:docs)."
+ },
+ "jsTests": {
+ "type": "boolean",
+ "default": false,
+ "description": "pnpm run test:js in the shared plugin-js-lint.yml workflow."
+ },
+ "buildTests": {
+ "type": "boolean",
+ "default": false,
+ "description": "pnpm run test:build after the package build."
+ },
+ "e2e": {
+ "type": "boolean",
+ "default": false,
+ "description": "Playwright through bin/e2e.sh and the shared plugin-e2e.yml workflow."
+ },
+ "phpunit": {
+ "type": "boolean",
+ "default": true,
+ "description": "The shared plugin-phpunit.yml workflow with phpunit.legs."
+ },
+ "isolated": {
+ "type": "boolean",
+ "default": false,
+ "description": "composer run test:php:isolated in the shared plugin-php-lint.yml workflow."
+ },
+ "integration": {
+ "type": "boolean",
+ "default": false,
+ "description": "The shared plugin-phpunit.yml workflow with integration.legs (scheduled and manual runs)."
+ },
+ "qit": {
+ "type": "boolean",
+ "default": true,
+ "description": "QIT jobs in manual-ci.yml, ci-cron.yml and ci-cron-qit.yml."
+ },
+ "pluginCheck": {
+ "type": "boolean",
+ "default": true,
+ "description": "Plugin Check on the candidate ZIP."
+ }
+ }
+ },
+ "zip": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "phpCompatibility": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "testVersion": {
+ "type": "string",
+ "pattern": "^[0-9]+[.][0-9]+(-[0-9]+[.][0-9]+)?$",
+ "description": "PHP range to check against the packaged files, for example 7.4-8.5."
+ },
+ "ruleset": {
+ "type": "string",
+ "description": "Optional PHPCS ruleset using the plugin's locked tools/php-quality dependencies."
+ },
+ "ignore": {
+ "type": "string",
+ "description": "Optional comma-separated PHPCS path exclusions."
+ }
+ }
+ },
+ "root": {
+ "type": "string",
+ "description": "Folder inside the ZIP. Default: the slug."
+ },
+ "exclude": {
+ "type": "string",
+ "default": "exclude.lst",
+ "description": "Exclude list: one zip -x wildcard per line, matched against <root>/<path>; a leading / anchors at the plugin folder; # comments."
+ },
+ "build": {
+ "type": "string",
+ "default": "build",
+ "description": "Package script bin/build-zip.sh runs first; empty for none."
+ },
+ "composerProduction": {
+ "type": "boolean",
+ "default": false,
+ "description": "composer install --no-dev in the staging folder, so vendor/ ships."
+ },
+ "php": {
+ "type": "string",
+ "default": "8.4",
+ "description": "PHP of the CI package job; \"system\" keeps the runner's PHP."
+ }
+ }
+ },
+ "versionPatterns": {
+ "type": "array",
+ "description": "Version strings besides the main file header. update_version.sh rewrites and check_versions.sh checks each.",
+ "items": {
+ "type": "object",
+ "additionalProperties": false,
+ "required": [ "pattern" ],
+ "properties": {
+ "file": {
+ "type": "string",
+ "description": "Default: mainFile."
+ },
+ "pattern": {
+ "type": "string",
+ "pattern": "%s",
+ "description": "Literal text with %s for the version; a leading ^ anchors at the start of a line."
+ }
+ }
+ }
+ },
+ "pluginCheck": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "excludeChecks": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "excludeDirectories": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "excludeFiles": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "ignoreCodes": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "ignoreWarnings": {
+ "type": "boolean",
+ "default": false
+ },
+ "strict": {
+ "type": "boolean",
+ "default": false
+ },
+ "timeoutMinutes": {
+ "type": "integer",
+ "default": 10
+ }
+ }
+ },
+ "qit": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "extension": {
+ "type": "string",
+ "description": "QIT extension slug. Default: the slug."
+ },
+ "plugins": {
+ "type": "string",
+ "default": "",
+ "description": "Plugin the QIT activation test installs with the extension (--plugin=<value>), e.g. a required plugin."
+ },
+ "derivativeExclude": {
+ "type": "string",
+ "default": "",
+ "description": "Path removed from the security and PHP compatibility scan copy (e.g. lib/)."
+ },
+ "apiFuzz": {
+ "type": "boolean",
+ "default": true
+ },
+ "timeoutMinutes": {
+ "type": "integer",
+ "default": 100
+ }
+ }
+ },
+ "e2e": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "projects": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "default": [ "" ],
+ "description": "Playwright projects, one CI job each; \"\" runs every project in one job."
+ },
+ "timeoutMinutes": {
+ "type": "integer",
+ "default": 20
+ },
+ "privatePlugins": {
+ "type": "boolean",
+ "default": false,
+ "description": "Trusted runs pass ORG_DOWNLOADS to bin/e2e.sh prepare (bin/hooks/e2e-prepare.sh)."
+ }
+ }
+ },
+ "phpunit": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "timeoutMinutes": {
+ "type": "integer",
+ "default": 10
+ },
+ "phpInput": {
+ "enum": [ "ignore", "replace" ],
+ "default": "ignore",
+ "description": "Whether a requested PHP version replaces the legs' PHP."
+ },
+ "ini": {
+ "type": "string",
+ "default": "",
+ "description": "Extra setup-php ini-values."
+ },
+ "scheduledWc": {
+ "type": "string",
+ "default": "",
+ "description": "WooCommerce version for Cron CI (e.g. trunk); empty keeps latest."
+ },
+ "passEnv": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "pattern": "^[A-Z_][A-Z0-9_]*$"
+ },
+ "default": [],
+ "description": "Environment variables that the shared bin/phpunit.sh passes into the wp-env container when they are set on the host. A plugin with its own PHPUnit runner does not read it."
+ },
+ "legs": {
+ "$ref": "#/$defs/legs"
+ }
+ }
+ },
+ "phpLint": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "php": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "default": [ "8.4" ],
+ "description": "PHP versions of the plugin-php-lint.yml coding standards job (composer check:php, bin/hooks/php-lint.sh)."
+ },
+ "isolatedPhp": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "default": [ "8.4" ],
+ "description": "PHP versions of the plugin-php-lint.yml isolated tests job (capabilities.isolated)."
+ }
+ }
+ },
+ "makepot": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "exclude": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "default": [],
+ "description": "Paths bin/makepot.sh skips (wp i18n make-pot --exclude), on top of the WP-CLI defaults such as node_modules and vendor."
+ },
+ "headers": {
+ "type": "object",
+ "additionalProperties": {
+ "type": "string"
+ },
+ "default": {},
+ "description": "POT headers bin/makepot.sh sets (wp i18n make-pot --headers). Keys are written as given."
+ }
+ }
+ },
+ "integration": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "timeoutMinutes": {
+ "type": "integer",
+ "default": 20
+ },
+ "legs": {
+ "$ref": "#/$defs/legs"
+ }
+ }
+ },
+ "privatePlugins": {
+ "type": "array",
+ "description": "Private plugin ZIPs that trusted PHPUnit runs download before checkout.",
+ "items": {
+ "type": "object",
+ "additionalProperties": false,
+ "required": [ "slug" ],
+ "properties": {
+ "slug": {
+ "type": "string"
+ },
+ "source": {
+ "enum": [ "release", "all-plugins", "wordpress.org" ],
+ "default": "release",
+ "description": "release: <slug>.zip of woocommerce/<slug>'s latest release; all-plugins: product-packages/<slug>/<slug>.zip in woocommerce/all-plugins; wordpress.org: the latest stable WordPress.org ZIP (no token needed)."
+ },
+ "suites": {
+ "type": "array",
+ "items": {
+ "enum": [ "unit", "integration" ]
+ },
+ "default": [ "unit" ]
+ },
+ "dirEnv": {
+ "type": "string",
+ "description": "Environment variable that receives the plugin folder."
+ },
+ "requireEnv": {
+ "type": "string",
+ "description": "Environment variable set to 1 so tests fail instead of skipping."
+ },
+ "hookOnly": {
+ "type": "boolean",
+ "default": false,
+ "description": "Download only, for bin/hooks/php-tests.sh ($WOO_PRIVATE_PLUGINS_DIR/<slug>)."
+ },
+ "minimumPattern": {
+ "type": "string",
+ "pattern": "%s",
+ "description": "Literal text in mainFile with %s for this plugin's minimum supported version, for legs[].plugins minimum and below-minimum."
+ }
+ }
+ }
+ },
+ "pullRequests": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "privatePlugins": {
+ "type": "boolean",
+ "default": false,
+ "description": "The E2E and integration suites need privatePlugins in every run: same-repository pull requests download them (E2E gets ORG_DOWNLOADS, the integration suite runs), fork pull requests skip both with a warning."
+ }
+ }
+ },
+ "release": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "target": {
+ "enum": [ "woocommerce.com", "wordpress.org" ],
+ "default": "woocommerce.com"
+ },
+ "productId": {
+ "type": "integer",
+ "description": "WooCommerce.com product ID (bin/deploy.sh)."
+ },
+ "readmeChangelog": {
+ "type": "boolean",
+ "default": false,
+ "description": "readme.txt carries the changelog (sync at release start, checked by check_versions.sh)."
+ },
+ "wpOrgSlug": {
+ "type": "string",
+ "description": "WordPress.org slug; empty skips the WordPress.org deploy."
+ }
+ }
+ }
+ },
+ "$defs": {
+ "legs": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "additionalProperties": false,
+ "required": [ "php" ],
+ "properties": {
+ "php": {
+ "type": "string"
+ },
+ "wp": {
+ "type": "string",
+ "default": "latest",
+ "description": "latest, previous, minimum or a version."
+ },
+ "wc": {
+ "type": "string",
+ "default": "latest",
+ "description": "latest, minimum or a version/tag."
+ },
+ "script": {
+ "type": "string",
+ "default": "test:php:unit",
+ "description": "Composer script the leg runs."
+ },
+ "coverage": {
+ "type": "boolean",
+ "default": false
+ },
+ "env": {
+ "type": "object",
+ "additionalProperties": {
+ "type": "string"
+ }
+ },
+ "defaultOnly": {
+ "type": "boolean",
+ "default": false,
+ "description": "Run only when no WordPress or PHP version is requested."
+ },
+ "scheduledOnly": {
+ "type": "boolean",
+ "default": false,
+ "description": "Run only in Cron CI."
+ },
+ "plugins": {
+ "type": "object",
+ "additionalProperties": {
+ "type": "string"
+ },
+ "description": "Private plugin release per slug: latest, minimum, below-minimum (newest release older than the minimum) or a tag. release-source plugins only."
+ },
+ "provision": {
+ "enum": [ "install", "hook" ],
+ "default": "install",
+ "description": "install: bin/install.sh; hook: bin/hooks/php-tests-provision.sh."
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/packages/js/extension-tooling/bin/woo-config.sh b/packages/js/extension-tooling/bin/woo-config.sh
new file mode 100755
index 00000000000..c65b4e942a4
--- /dev/null
+++ b/packages/js/extension-tooling/bin/woo-config.sh
@@ -0,0 +1,275 @@
+#!/usr/bin/env bash
+#
+# Prints the plugin's tooling metadata: package.json `config.woo` with every default applied.
+# Shared scripts and workflows read per-plugin values only through this script, so the defaults
+# live in one place. woo-config.schema.json, next to this script, documents each key; the object
+# is validated against it first, so a misspelled key or a wrong type fails here.
+#
+# Run it from the plugin root, the folder with package.json.
+#
+# Usage:
+# woo-extension-config Normalized config as JSON.
+# woo-extension-config '<jq filter>' One value, e.g. '.zip.root' (raw output).
+# woo-extension-config --github-output Writes `json=<config>` to $GITHUB_OUTPUT.
+# woo-extension-config --phpunit-matrix PHPUnit legs as a JSON array. See README.md for inputs.
+set -euo pipefail
+
+# npm links executables from node_modules/.bin. The schema lives beside the script target.
+reader=$0
+while [[ -L "$reader" ]]; do
+ directory=$(dirname "$reader")
+ reader=$(readlink "$reader")
+ [[ "$reader" == /* ]] || reader="$directory/$reader"
+done
+schema="$(dirname "$reader")/woo-config.schema.json"
+
+if [[ ! -f package.json ]]; then
+ echo 'No package.json here. Run this from the plugin root.' >&2
+ exit 1
+fi
+
+if ! command -v jq >/dev/null; then
+ echo 'jq is required to read extension config.' >&2
+ exit 1
+fi
+
+# The subset of JSON Schema that woo-config.schema.json uses: type, enum, pattern, required,
+# properties, additionalProperties, items and $ref into $defs.
+errors=$(jq -r --slurpfile schema "$schema" '
+ def check($node; $path):
+ (if $node | has("$ref") then $schema[0]["$defs"][$node["$ref"] | split("/") | last] else $node end) as $s
+ | . as $value
+ | type as $type
+ | if $s.type != null and ((if $s.type == "integer" then $type == "number" and $value == ($value | floor) else $type == $s.type end) | not) then
+ "\($path): expected \($s.type), got \($type)"
+ else
+ (if $s.enum != null and ($s.enum | any(. == $value) | not) then "\($path): \($value | tojson) is not one of \($s.enum | tojson)" else empty end),
+ (if $type == "string" and $s.pattern != null and ($value | test($s.pattern) | not) then "\($path): \($value | tojson) does not match \($s.pattern)" else empty end),
+ (if $type == "object" then
+ (($s.required // [])[] | select(. as $key | $value | has($key) | not) | "\($path): missing \(.)"),
+ ($value | to_entries[] | .key as $key | .value
+ | if ($s.properties // {}) | has($key) then check($s.properties[$key]; "\($path).\($key)")
+ elif $s.additionalProperties == false then "\($path): unknown key \($key)"
+ elif ($s.additionalProperties | type) == "object" then check($s.additionalProperties; "\($path).\($key)")
+ else empty end)
+ else empty end),
+ (if $type == "array" and $s.items != null then
+ ($value | to_entries[] | .key as $index | .value | check($s.items; "\($path)[\($index)]"))
+ else empty end)
+ end;
+ (if (.config | type) == "object" and (.config | has("sww")) then "config.sww: renamed to config.woo" else empty end),
+ (if (.config | type) == "object" and (.config | has("woo")) then .config.woo | check($schema[0]; "config.woo") else empty end)
+' package.json) || {
+ echo 'package.json is not valid JSON, or woo-config.schema.json is missing.' >&2
+ exit 1
+}
+if [[ -n "$errors" ]]; then
+ echo 'Invalid package.json tooling config:' >&2
+ sed 's/^/ /' <<< "$errors" >&2
+ exit 1
+fi
+
+config=$(jq -ce '
+ # A key the object has, else the default. Unlike `//`, keeps false, 0 and "".
+ def opt($key; $default): if type == "object" and has($key) then .[$key] else $default end;
+ (.config.woo // {}) as $c
+ | .name as $package
+ | ($c | opt("slug"; $package)) as $name
+ | if ($name | type) != "string" then error("no slug") else . end
+ | ($c | opt("mainFile"; $name + ".php")) as $main
+ | ($c | opt("capabilities"; {})) as $cap
+ | ($c | opt("zip"; {})) as $zip
+ | ($c | opt("pluginCheck"; {})) as $pc
+ | ($c | opt("qit"; {})) as $qit
+ | ($c | opt("e2e"; {})) as $e2e
+ | ($c | opt("phpunit"; {})) as $unit
+ | ($c | opt("release"; {})) as $rel
+ | ($c | opt("phpLint"; {})) as $lint
+ | ($c | opt("makepot"; {})) as $pot
+ | {
+ slug: $name,
+ version: .version,
+ mainFile: $main,
+ productName: ($c | opt("productName"; $name)),
+ capabilities: {
+ js: ($cap | opt("js"; true)),
+ jsTests: ($cap | opt("jsTests"; false)),
+ buildTests: ($cap | opt("buildTests"; false)),
+ e2e: ($cap | opt("e2e"; false)),
+ phpunit: ($cap | opt("phpunit"; true)),
+ isolated: ($cap | opt("isolated"; false)),
+ integration: ($cap | opt("integration"; false)),
+ qit: ($cap | opt("qit"; true)),
+ pluginCheck: ($cap | opt("pluginCheck"; true))
+ },
+ zip: {
+ root: ($zip | opt("root"; $name)),
+ exclude: ($zip | opt("exclude"; "exclude.lst")),
+ build: ($zip | opt("build"; "build")),
+ composerProduction: ($zip | opt("composerProduction"; false)),
+ php: ($zip | opt("php"; "8.4")),
+ phpCompatibility: ($zip | opt("phpCompatibility"; null))
+ },
+ versionPatterns: [ ($c | opt("versionPatterns"; []))[] | { file: opt("file"; $main), pattern: .pattern } ],
+ pluginCheck: {
+ excludeChecks: ($pc | opt("excludeChecks"; [])),
+ excludeDirectories: ($pc | opt("excludeDirectories"; [])),
+ excludeFiles: ($pc | opt("excludeFiles"; [])),
+ ignoreCodes: ($pc | opt("ignoreCodes"; [])),
+ ignoreWarnings: ($pc | opt("ignoreWarnings"; false)),
+ strict: ($pc | opt("strict"; false)),
+ timeoutMinutes: ($pc | opt("timeoutMinutes"; 10))
+ },
+ phpLint: {
+ php: ($lint | opt("php"; [ "8.4" ])),
+ isolatedPhp: ($lint | opt("isolatedPhp"; [ "8.4" ]))
+ },
+ makepot: {
+ exclude: ($pot | opt("exclude"; [])),
+ headers: ($pot | opt("headers"; {}))
+ },
+ qit: {
+ extension: ($qit | opt("extension"; $name)),
+ plugins: ($qit | opt("plugins"; "")),
+ derivativeExclude: ($qit | opt("derivativeExclude"; "")),
+ apiFuzz: ($qit | opt("apiFuzz"; true)),
+ timeoutMinutes: ($qit | opt("timeoutMinutes"; 100))
+ },
+ e2e: {
+ projects: ($e2e | opt("projects"; [ "" ])),
+ timeoutMinutes: ($e2e | opt("timeoutMinutes"; 20)),
+ privatePlugins: ($e2e | opt("privatePlugins"; false))
+ },
+ phpunit: {
+ timeoutMinutes: ($unit | opt("timeoutMinutes"; 10)),
+ phpInput: ($unit | opt("phpInput"; "ignore")),
+ ini: ($unit | opt("ini"; "")),
+ scheduledWc: ($unit | opt("scheduledWc"; "")),
+ passEnv: ($unit | opt("passEnv"; [])),
+ legs: ($unit | opt("legs"; [
+ { php: "7.4", wp: "latest", wc: "latest" },
+ { php: "8.4", wp: "latest", wc: "latest", coverage: true },
+ { php: "8.5", wp: "latest", wc: "latest" }
+ ]))
+ },
+ integration: {
+ timeoutMinutes: ($c | opt("integration"; {}) | opt("timeoutMinutes"; 20)),
+ legs: ($c | opt("integration"; {}) | opt("legs"; []))
+ },
+ privatePlugins: [ ($c | opt("privatePlugins"; []))[] | {
+ slug: .slug,
+ source: opt("source"; "release"),
+ suites: opt("suites"; [ "unit" ]),
+ dirEnv: opt("dirEnv"; ""),
+ requireEnv: opt("requireEnv"; ""),
+ hookOnly: opt("hookOnly"; false),
+ minimumPattern: opt("minimumPattern"; "")
+ } ],
+ pullRequests: {
+ privatePlugins: ($c | opt("pullRequests"; {}) | opt("privatePlugins"; false))
+ },
+ release: {
+ target: ($rel | opt("target"; "woocommerce.com")),
+ productId: ($rel | opt("productId"; "")),
+ readmeChangelog: ($rel | opt("readmeChangelog"; false)),
+ wpOrgSlug: ($rel | opt("wpOrgSlug"; ""))
+ }
+ }
+' package.json) || {
+ echo 'package.json must have a "name" or a config.woo.slug.' >&2
+ exit 1
+}
+
+if [[ ! "$(jq -r .slug <<< "$config")" =~ ^[a-z0-9]+(-[a-z0-9]+)*$ ]]; then
+ echo 'The plugin slug must be lowercase words joined by hyphens. Set config.woo.slug when the package.json name is not the slug.' >&2
+ exit 1
+fi
+
+# Turns config.woo.phpunit.legs into concrete jobs. A leg's `wp` and `wc` are `latest`,
+# `previous` (WordPress only: the newest release of the previous major series, from
+# $PREVIOUS_WP), `minimum` (the main file's "Requires at least" / "WC requires at least") or a
+# version. A requested WordPress or WooCommerce version replaces `latest` and `previous`. A
+# requested PHP version replaces every leg's PHP when phpunit.phpInput is "replace", except on
+# legs with a `minimum` or fixed WordPress version. Legs with `"defaultOnly": true` run only
+# when no WordPress or PHP version is requested, and legs with `"scheduledOnly": true` only when
+# SCHEDULED=true (Cron CI). A leg's `plugins` picks a private plugin release: `latest`, `minimum`
+# (that plugin's minimumPattern in the main file), `below-minimum` (the newest release older than
+# the minimum) or a tag; the leg's `pluginVersions` carries it to the download step (`<x.y.z` for
+# below-minimum). Identical legs are merged. SUITE=integration reads config.woo.integration.legs.
+phpunit_matrix() {
+ local main_file wp_minimum wc_minimum minimums='{}' slug pattern prefix suffix line version
+ main_file=$(jq -r .mainFile <<< "$config")
+ wp_minimum=$(awk -F ': ' '/^[[:space:]]*\* Requires at least:/{print $2; exit}' "$main_file" | tr -d '\r')
+ wc_minimum=$(awk -F ': ' '/^[[:space:]]*\* WC requires at least:/{print $2; exit}' "$main_file" | tr -d '\r')
+ [[ ! "$wc_minimum" =~ ^[0-9]+\.[0-9]+$ ]] || wc_minimum="$wc_minimum.0"
+ # NUL separators preserve the pattern's literal text.
+ while IFS= read -r -d '' slug && IFS= read -r -d '' pattern; do
+ prefix=${pattern%%%s*}
+ suffix=${pattern#*%s}
+ line=$(grep -F -m1 -- "$prefix" "$main_file") || { echo "No minimumPattern match for $slug in $main_file." >&2; return 1; }
+ line=${line%$'\r'}
+ version=${line#*"$prefix"}
+ if [[ -n "$suffix" ]]; then
+ version=${version%%"$suffix"*}
+ fi
+ [[ "$version" =~ ^[0-9]+(\.[0-9]+)*$ ]] || { echo "Invalid minimum $slug version '$version' in $main_file." >&2; return 1; }
+ minimums=$(jq -c --arg slug "$slug" --arg version "$version" '. + { ($slug): $version }' <<< "$minimums")
+ done < <(jq -j '.privatePlugins[] | select(.minimumPattern != "") | .slug, "\u0000", .minimumPattern, "\u0000"' <<< "$config")
+ jq -c \
+ --arg wp "${REQUESTED_WP:-}" --arg wc "${REQUESTED_WC:-}" --arg php "${REQUESTED_PHP:-}" \
+ --arg previous "${PREVIOUS_WP:-}" --arg wpmin "$wp_minimum" --arg wcmin "$wc_minimum" \
+ --arg suite "${SUITE:-unit}" --arg scheduled "${SCHEDULED:-false}" --argjson minimums "$minimums" '
+ .phpunit.phpInput as $phpInput
+ | (if $suite == "integration" then .integration else .phpunit end) as $u
+ | ($wp != "" or $php != "") as $requested
+ | [ .privatePlugins[].slug ] as $private
+ | [ $u.legs[]
+ | select(($requested and (.defaultOnly // false)) | not)
+ | select((.scheduledOnly // false) | not or $scheduled == "true")
+ | (.plugins // {}) as $plugins
+ | ($plugins | to_entries | map(select(.value != "latest"))) as $pinned
+ | ($pinned | map(.key as $slug | .value as $spec | { key: $slug, value: (
+ if ($private | any(. == $slug) | not) then error("Leg plugin \($slug) is not in config.woo.privatePlugins")
+ elif $spec == "minimum" or $spec == "below-minimum" then
+ ($minimums[$slug] // error("config.woo.privatePlugins \($slug) needs a minimumPattern"))
+ | if $spec == "below-minimum" then "<" + . else . end
+ else $spec end) }) | from_entries) as $pluginVersions
+ | (.wp // "latest") as $legwp
+ | (.wc // "latest") as $legwc
+ | ($legwp == "latest" or $legwp == "previous") as $floating
+ | {
+ php: (if $php != "" and $phpInput == "replace" and $floating then $php else .php end),
+ wp: (if $legwp == "minimum" then $wpmin
+ elif $floating and $wp != "" then $wp
+ elif $legwp == "previous" then $previous
+ else $legwp end),
+ wc: (if $legwc == "minimum" then $wcmin
+ elif $legwc == "latest" and $wc != "" then $wc
+ else $legwc end),
+ script: (.script // "test:php:unit"),
+ provision: (.provision // "install"),
+ coverage: (.coverage // false),
+ env: (.env // {}),
+ pluginVersions: $pluginVersions,
+ floor: ($legwp == "minimum")
+ }
+ | . + { label: "PHP \(.php) / WP \(.wp) / WC \(.wc)\(if (.env | length) > 0 then " / " + (.env | to_entries | map("\(.key)=\(.value)") | join(", ")) else "" end)\($pinned | map(" / \(.key) \(.value)") | join(""))\(if .script != "test:php:unit" then " / " + .script else "" end)" }
+ ]
+ | reduce .[] as $leg ([]; if any(.[]; .label == $leg.label) then . else . + [ $leg ] end)
+ ' <<< "$config"
+}
+
+case "${1:-}" in
+ '')
+ printf '%s\n' "$config"
+ ;;
+ --github-output)
+ printf 'json=%s\n' "$config" >> "$GITHUB_OUTPUT"
+ ;;
+ --phpunit-matrix)
+ phpunit_matrix
+ ;;
+ *)
+ jq -r "$1" <<< "$config"
+ ;;
+esac
diff --git a/packages/js/extension-tooling/changelog/wooprd-4106-share-extension-config b/packages/js/extension-tooling/changelog/wooprd-4106-share-extension-config
new file mode 100644
index 00000000000..5e2fafd4b76
--- /dev/null
+++ b/packages/js/extension-tooling/changelog/wooprd-4106-share-extension-config
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Add the woo-extension-config command to validate extension configuration and apply defaults.
diff --git a/packages/js/extension-tooling/package.json b/packages/js/extension-tooling/package.json
index 8ed3cfea2ac..8c5a7261448 100644
--- a/packages/js/extension-tooling/package.json
+++ b/packages/js/extension-tooling/package.json
@@ -19,6 +19,7 @@
"./check-i18n": "./src/check-i18n.js"
},
"bin": {
+ "woo-extension-config": "./bin/woo-config.sh",
"woo-extension-env-start": "./bin/env-start.sh",
"woo-extension-env-dev-reset": "./bin/env-dev-reset.sh"
},
@@ -55,6 +56,7 @@
"changes": [
"package.json",
"bin/env-start.sh",
+ "bin/woo-config.*",
"{src,test}/**/*.js"
],
"events": [
diff --git a/packages/js/extension-tooling/test/config.test.js b/packages/js/extension-tooling/test/config.test.js
new file mode 100644
index 00000000000..d7439b3bfb2
--- /dev/null
+++ b/packages/js/extension-tooling/test/config.test.js
@@ -0,0 +1,150 @@
+const assert = require( 'node:assert/strict' );
+const { spawnSync } = require( 'node:child_process' );
+const fs = require( 'node:fs' );
+const os = require( 'node:os' );
+const path = require( 'node:path' );
+const { test } = require( 'node:test' );
+
+const reader = path.join( __dirname, '..', 'bin', 'woo-config.sh' );
+
+function fixture( context, config ) {
+ const directory = fs.realpathSync(
+ fs.mkdtempSync( path.join( os.tmpdir(), 'woo-config-' ) )
+ );
+ context.after( () =>
+ fs.rmSync( directory, { recursive: true, force: true } )
+ );
+ fs.writeFileSync(
+ path.join( directory, 'package.json' ),
+ JSON.stringify( { name: 'example-extension', config: { woo: config } } )
+ );
+ return directory;
+}
+
+test( 'reads config from the extension through an npm-style bin symlink', ( context ) => {
+ const directory = fixture( context, {
+ capabilities: { js: false },
+ zip: {
+ build: '',
+ phpCompatibility: { testVersion: '7.4-8.5' },
+ },
+ } );
+ const bin = path.join( directory, 'node_modules', '.bin' );
+ fs.mkdirSync( bin, { recursive: true } );
+ const link = path.join( bin, 'woo-extension-config' );
+ fs.symlinkSync( path.relative( bin, reader ), link );
+ const output = path.join( directory, 'github-output' );
+ const result = spawnSync( 'bash', [ link, '--github-output' ], {
+ cwd: directory,
+ encoding: 'utf8',
+ env: { ...process.env, GITHUB_OUTPUT: output },
+ } );
+ assert.equal( result.status, 0, result.stderr );
+ const config = JSON.parse( fs.readFileSync( output, 'utf8' ).slice( 5 ) );
+ assert.equal( config.slug, 'example-extension' );
+ assert.equal( config.capabilities.js, false );
+ assert.equal( config.zip.build, '' );
+ assert.equal( config.zip.root, 'example-extension' );
+ assert.deepEqual( config.zip.phpCompatibility, {
+ testVersion: '7.4-8.5',
+ } );
+} );
+
+test( 'rejects invalid extension config before producing outputs', ( context ) => {
+ const directory = fixture( context, { capabilities: { js: 'false' } } );
+ const result = spawnSync( 'bash', [ reader ], {
+ cwd: directory,
+ encoding: 'utf8',
+ } );
+ assert.equal( result.status, 1 );
+ assert.equal( result.stdout, '' );
+ assert.match(
+ result.stderr,
+ /config\.woo\.capabilities\.js: expected boolean/
+ );
+} );
+
+test( 'preserves an older config without the ZIP PHP compatibility opt-in', ( context ) => {
+ const result = spawnSync( 'bash', [ reader ], {
+ cwd: fixture( context, {} ),
+ encoding: 'utf8',
+ } );
+ assert.equal( result.status, 0, result.stderr );
+ assert.equal( JSON.parse( result.stdout ).zip.phpCompatibility, null );
+} );
+
+test( 'plans PHPUnit legs using the plugin headers and requested versions', ( context ) => {
+ const directory = fixture( context, {
+ phpunit: {
+ phpInput: 'replace',
+ legs: [
+ { php: '7.4', wp: 'minimum', wc: 'minimum' },
+ { php: '8.2', wp: 'previous', wc: 'latest' },
+ { php: '8.4', defaultOnly: true },
+ { php: '8.5', wp: '7.0', scheduledOnly: true },
+ ],
+ },
+ privatePlugins: [
+ {
+ slug: 'example-addon',
+ minimumPattern: 'Addon\\Example minimum: %s',
+ },
+ ],
+ integration: {
+ legs: [
+ {
+ php: '8.4',
+ script: 'test:php:integration',
+ plugins: { 'example-addon': 'below-minimum' },
+ },
+ ],
+ },
+ } );
+ fs.writeFileSync(
+ path.join( directory, 'example-extension.php' ),
+ '<?php\r\n/**\r\n * Requires at least: 6.8\r\n * WC requires at least: 10.4\r\n * Addon\\Example minimum: 2.3.4\r\n */\r\n'
+ );
+ function readMatrix( inputs = {} ) {
+ const result = spawnSync( 'bash', [ reader, '--phpunit-matrix' ], {
+ cwd: directory,
+ encoding: 'utf8',
+ env: {
+ ...process.env,
+ PREVIOUS_WP: '6.9',
+ REQUESTED_PHP: '',
+ REQUESTED_WC: '',
+ REQUESTED_WP: '',
+ SCHEDULED: 'false',
+ SUITE: 'unit',
+ ...inputs,
+ },
+ } );
+ assert.equal( result.status, 0, result.stderr );
+ return JSON.parse( result.stdout );
+ }
+ const versions = ( legs ) =>
+ legs.map( ( { php, wp, wc } ) => [ php, wp, wc ] );
+ assert.deepEqual( versions( readMatrix() ), [
+ [ '7.4', '6.8', '10.4.0' ],
+ [ '8.2', '6.9', 'latest' ],
+ [ '8.4', 'latest', 'latest' ],
+ ] );
+ assert.deepEqual(
+ versions(
+ readMatrix( {
+ REQUESTED_PHP: '8.4',
+ REQUESTED_WC: '11.2.0',
+ REQUESTED_WP: '7.1',
+ SCHEDULED: 'true',
+ } )
+ ),
+ [
+ [ '7.4', '6.8', '10.4.0' ],
+ [ '8.4', '7.1', '11.2.0' ],
+ [ '8.5', '7.0', '11.2.0' ],
+ ]
+ );
+ const [ leg ] = readMatrix( { SUITE: 'integration' } );
+ assert.equal( leg.script, 'test:php:integration' );
+ assert.deepEqual( leg.pluginVersions, { 'example-addon': '<2.3.4' } );
+} );