diff --git a/.github/workflows/ci-test-build-artifact.yml b/.github/workflows/ci-test-build-artifact.yml index 0bfea25..6785fb3 100644 --- a/.github/workflows/ci-test-build-artifact.yml +++ b/.github/workflows/ci-test-build-artifact.yml @@ -24,7 +24,10 @@ on: type: string default: "" wp-version: - description: "WordPress version wp-env boots with. 'latest' uses the newest stable release." + description: >- + WordPress core wp-env boots: 'latest' (newest stable release), 'trunk' (development branch), + or a specific WordPress version (e.g. '6.8' for the latest 6.8.x or '6.8.2' for a specific + patch version). type: string default: "latest" install-path: @@ -107,13 +110,34 @@ jobs: run: | set -euo pipefail + case "$WP_VERSION" in + latest) core="" ;; + trunk) core="WordPress/WordPress#master" ;; + *) + # x.y means its newest x.y.z; the WordPress/WordPress mirror tags x.y.0 releases as x.y. + if [[ "$WP_VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then + ref=$(git ls-remote --tags --refs --sort=version:refname https://github.com/WordPress/WordPress.git "$WP_VERSION" "$WP_VERSION.*" \ + | tail -n1 | sed 's|.*refs/tags/||') + elif [[ "$WP_VERSION" =~ ^[0-9]+\.[0-9]+\.0$ ]]; then + ref=${WP_VERSION%.0} + else + ref=$WP_VERSION + fi + if [[ ! "$ref" =~ ^[A-Za-z0-9._/-]+$ ]]; then + echo "::error::wp-version '$WP_VERSION' matches no WordPress release." + exit 1 + fi + core="WordPress/WordPress#$ref" + ;; + esac + # Mount only the artifact; a consumer's .wp-env.json usually mounts the dev source (".") at the same path. jq -n \ - --arg wp "$WP_VERSION" \ + --arg core "$core" \ --arg php "$PHP_VERSION" \ --arg dest "${INSTALL_PATH%/}/${SLUG}" \ '{ - core: (if $wp == "latest" then null else "WordPress/WordPress#\($wp)" end), + core: (if $core == "" then null else $core end), phpVersion: $php, plugins: [], themes: [], @@ -148,7 +172,10 @@ jobs: - name: Run wp doctor shell: bash env: - DOCTOR_IGNORE_CHECKS: ${{ inputs.doctor-ignore-checks }} + # WordPress.org publishes no checksums for trunk builds. + DOCTOR_IGNORE_CHECKS: >- + ${{ inputs.wp-version == 'trunk' && format('{0},core-verify-checksums', inputs.doctor-ignore-checks) + || inputs.doctor-ignore-checks }} run: | set -euo pipefail diff --git a/.github/workflows/ci-test-php.yml b/.github/workflows/ci-test-php.yml index 2de0e73..abc45fa 100644 --- a/.github/workflows/ci-test-php.yml +++ b/.github/workflows/ci-test-php.yml @@ -17,8 +17,9 @@ on: default: "" wp-version: description: >- - WordPress core version for wp-env, e.g. '6.8' (resolved as WordPress/WordPress#). - Empty uses the version from the consumer's .wp-env.json. Ignored when use-wp-env is false. + WordPress core for wp-env: 'latest' (newest stable release), 'trunk' (development branch), + or a specific WordPress version (e.g. '6.8' for the latest 6.8.x or '6.8.2' for a specific + patch version). Empty uses the consumer's .wp-env.json. Ignored when use-wp-env is false. type: string default: "" use-wp-env: @@ -45,12 +46,11 @@ jobs: test-php: name: PHPUnit runs-on: ${{ fromJSON(inputs.runs-on) }} - # Pin the wp-env container's PHP/WordPress core via env: (not $GITHUB_ENV, which is - # newline-injectable) at job scope, so start/run/stop resolve the same environment. - # An empty WP_ENV_CORE is ignored by wp-env (falls back to the consumer's .wp-env.json). + # Pin the wp-env container's PHP via env: (not $GITHUB_ENV, which is newline-injectable) + # at job scope, so start/run/stop resolve the same environment. WP_ENV_CORE needs a + # lookup, so the "Resolve WordPress core" step validates it before writing $GITHUB_ENV. env: WP_ENV_PHP_VERSION: ${{ inputs.use-wp-env && inputs.php-version || '' }} - WP_ENV_CORE: ${{ (inputs.use-wp-env && inputs.wp-version != '') && format('WordPress/WordPress#{0}', inputs.wp-version) || '' }} defaults: run: working-directory: ${{ inputs.working-dir }} @@ -110,6 +110,35 @@ jobs: if: ${{ inputs.use-wp-env }} run: npm ci + - name: Resolve WordPress core + if: ${{ inputs.use-wp-env && inputs.wp-version != '' }} + shell: bash + env: + WP_VERSION: ${{ inputs.wp-version }} + run: | + set -euo pipefail + case "$WP_VERSION" in + latest) core="https://wordpress.org/latest.zip" ;; + trunk) core="WordPress/WordPress#master" ;; + *) + # x.y means its newest x.y.z; the WordPress/WordPress mirror tags x.y.0 releases as x.y. + if [[ "$WP_VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then + ref=$(git ls-remote --tags --refs --sort=version:refname https://github.com/WordPress/WordPress.git "$WP_VERSION" "$WP_VERSION.*" \ + | tail -n1 | sed 's|.*refs/tags/||') + elif [[ "$WP_VERSION" =~ ^[0-9]+\.[0-9]+\.0$ ]]; then + ref=${WP_VERSION%.0} + else + ref=$WP_VERSION + fi + if [[ ! "$ref" =~ ^[A-Za-z0-9._/-]+$ ]]; then + echo "::error::wp-version '$WP_VERSION' matches no WordPress release." + exit 1 + fi + core="WordPress/WordPress#$ref" + ;; + esac + echo "WP_ENV_CORE=$core" | tee -a "$GITHUB_ENV" + - name: Start wp-env if: ${{ inputs.use-wp-env }} run: npm run wp-env start diff --git a/.github/workflows/wp-ci.yml b/.github/workflows/wp-ci.yml index 7031d91..8a65f03 100644 --- a/.github/workflows/wp-ci.yml +++ b/.github/workflows/wp-ci.yml @@ -39,7 +39,11 @@ on: type: string default: '["8.3"]' wp-versions: - description: "JSON array of WordPress core versions for wp-env, crossed with php-versions, e.g. '[\"6.8\",\"6.9\"]'. An empty-string entry uses .wp-env.json. Ignored when use-wp-env is false." + description: >- + JSON array of WordPress core versions for wp-env, crossed with php-versions, e.g. + '["6.8","latest","trunk"]'. 'latest' is the newest stable release, 'trunk' the + development branch and '6.8' the latest 6.8.x. An empty-string entry uses .wp-env.json. + Ignored when use-wp-env is false. type: string default: '[""]' test-php-exclude: