Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to resolve semver for WP_VERSION env #207

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

thelovekesh
Copy link
Member

@thelovekesh thelovekesh commented May 24, 2024

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: #51

@thelovekesh thelovekesh requested a review from a team as a code owner May 24, 2024 16:00
@thelovekesh
Copy link
Member Author

thelovekesh commented May 24, 2024

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.

Co-authored-by: Pascal Birchler <pascalb@google.com>
if ( 1 === $version_count ) {
$constraint = "^$wp_version_env"; // Get the latest minor version.
} elseif ( 2 === $version_count ) {
$constraint = "~$wp_version_env.0"; // Get the latest patch version.
Copy link
Member Author

@thelovekesh thelovekesh May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added .0 as patch version due to semver package API behavior:

The ~ operator is best explained by example: ~1.2 is equivalent to >=1.2 <2.0.0, while ~1.2.3 is equivalent to >=1.2.3 <1.3.0. Ref: https://getcomposer.org/doc/articles/versions.md#tilde-version-range-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants