Resolve WP_VERSION to latest patch when only major.minor is provided#307
Resolve WP_VERSION to latest patch when only major.minor is provided#307swissspidy merged 2 commits intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…vided Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Code Review
This pull request introduces logic to resolve WordPress versions specified as major.minor to the latest available patch release. The changes in bin/run-behat-tests are well-implemented, using curl and jq to handle version resolution from a remote JSON file. The logic appears correct and robustly handles various version formats and potential failure scenarios as described. I have one minor suggestion to improve the performance of the script.
| elif [[ "${WP_VERSION}" =~ ^[0-9]+\.[0-9]+$ ]]; then | ||
| WP_VERSIONS_JSON=$(curl -s https://raw.githubusercontent.com/wp-cli/wp-cli-tests/artifacts/wp-versions.json) | ||
| if [ -n "${WP_VERSIONS_JSON}" ]; then | ||
| RESOLVED_VERSION=$(echo "${WP_VERSIONS_JSON}" | jq -r --arg prefix "${WP_VERSION}." 'keys | map(select(startswith($prefix))) | sort_by(split(".") | map(tonumber)) | last // empty') |
There was a problem hiding this comment.
For a slight performance improvement and to avoid creating an extra process for echo, you can use a here-string (<<<) to pass the JSON content to jq. This is generally a more efficient way to feed a string to a command's standard input in Bash.
| RESOLVED_VERSION=$(echo "${WP_VERSIONS_JSON}" | jq -r --arg prefix "${WP_VERSION}." 'keys | map(select(startswith($prefix))) | sort_by(split(".") | map(tonumber)) | last // empty') | |
| RESOLVED_VERSION=$(jq -r --arg prefix "${WP_VERSION}." 'keys | map(select(startswith($prefix))) | sort_by(split(".") | map(tonumber)) | last // empty' <<< "${WP_VERSIONS_JSON}") |
WP_VERSION=5.1would install exactly5.1even when5.1.21is available, causing failures in tests that assert against the latest patched behavior. Specifying an exact patch like5.1.1worked correctly, but omitting the patch component silently pinned to the unpatched initial release.Changes
bin/run-behat-tests: Added version resolution logic after the existinglatesthandling:WP_VERSION=X.Y— fetcheswp-versions.jsonfrom theartifactsbranch and resolves to the highest availableX.Y.Zpatch releaseWP_VERSION=X.Y.0— normalized toX.Y(WordPress stores the initial release without a patch suffix)WP_VERSION=X.Y.Z(Z > 0) — kept as-islatest,trunk,nightly— unchangedWP_VERSIONis left unchanged (graceful fallback)Version data is sourced from
https://raw.githubusercontent.com/wp-cli/wp-cli-tests/artifacts/wp-versions.json(updated nightly via CI) to avoid hitting the WordPress API on every test run.Original prompt
WP_VERSIONshould default to latest patch if not provided #51🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.