wp-cli-tests icon indicating copy to clipboard operation
wp-cli-tests copied to clipboard

Add script to resolve semver for `WP_VERSION` env

Open thelovekesh opened this issue 1 year ago • 2 comments

Summary

This PR aims to add a script which helps to determine the semver for passed WP_VERSION env variable. To do so correctly, this script uses composer/semver package.

Example cases:

Versions data
'5.4'   => 'insecure',
'5.9'   => 'insecure',
'5.9.1' => 'insecure',
'5.9.2' => 'insecure',
'6.0'   => 'insecure',
'6.0.1' => 'insecure',
'6.0.2' => 'insecure',
'6.1'   => 'insecure',
'6.1.1' => 'insecure',
'6.1.2' => 'insecure',
'6.2'   => 'insecure',
'6.2.1' => 'insecure',
'6.2.2' => 'insecure',
'6.5'   => 'insecure',
'6.5.2' => 'latest',
// Input => Output
array( '5.0', '5.0' ), // Does not match any version. So return as it is.
array( '5', '5.9.2' ), // Return the latest major version.
array( '5.9', '5.9.2' ), // Return the latest patch version.
array( '5.9.1', '5.9.1' ), // Return the exact version.
array( '6', '6.5.2' ), // Return the latest minor version.
array( '6.0', '6.0.2' ), // Return the latest patch version.
array( '6.0.0', '6.0' ), // Return the requested version.
array( '', '6.5.2' ), // Return the latest version.
array( 'latest', '6.5.2' ), // Return the latest version.
array( 'some-mismatched-version', 'some-mismatched-version' ), // Does not match any version. So return as it is.
array( '6.5-alpha', '6.5.2' ), // Return the latest version.
array( '6.5-beta', '6.5.2' ), // Return the latest version.
array( '6.5-rc', '6.5.2' ), // Return the latest version.
array( '6.5-nightly', '6.5-nightly' ), // Does not match any version. So return as it is.
array( '6.5.0.0', '6.5' ), // Return the latest version.
array( '6.5.2.0', '6.5.2' ), // Return the latest version.

Fixes: https://github.com/wp-cli/wp-cli-tests/issues/51

thelovekesh avatar May 24 '24 16:05 thelovekesh

~~One aspect I'm uncertain about is:~~

~~Should passing a single version string resolve to the latest version of the major release? For instance, if someone passes 5, should it resolve to the latest minor version within that major version, like "5.x.x", or should it resolve to the absolute latest version available?~~

Seems like some bug with my logic. It should resolve the latest minor version.

thelovekesh avatar May 24 '24 16:05 thelovekesh

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar May 17 '25 11:05 codecov[bot]