Skip to content

Commit

Permalink
Merge pull request wp-cli#5894 from wp-cli/fix/274-unparseable-versio…
Browse files Browse the repository at this point in the history
…n-tags
  • Loading branch information
schlessera authored Feb 5, 2024
2 parents e8617c1 + a5d2e2c commit 93f5880
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 9 additions & 5 deletions php/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,12 +962,16 @@ function get_named_sem_ver( $new_version, $original_version ) {
$patch = $bits[2];
}

if ( isset( $minor ) && Semver::satisfies( $new_version, "{$major}.{$minor}.x" ) ) {
return 'patch';
}
try {
if ( isset( $minor ) && Semver::satisfies( $new_version, "{$major}.{$minor}.x" ) ) {
return 'patch';
}

if ( Semver::satisfies( $new_version, "{$major}.x.x" ) ) {
return 'minor';
if ( Semver::satisfies( $new_version, "{$major}.x.x" ) ) {
return 'minor';
}
} catch ( \UnexpectedValueException $e ) {
return '';
}

return 'major';
Expand Down
13 changes: 13 additions & 0 deletions tests/test-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public function testGetSemVer() {
$original_version = '0.19.1';
$this->assertEmpty( Utils\get_named_sem_ver( '0.18.0', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '0.19.1', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( 'nonsense', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '0.18.1-beta3', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '0.19.1-dev1', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '0.19.1-beta3', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '0.19.2-dev1', $original_version ) ); // -dev suffix not accepted by SemVer.
$this->assertEquals( 'patch', Utils\get_named_sem_ver( '0.19.2-beta3', $original_version ) );
$this->assertEquals( 'patch', Utils\get_named_sem_ver( '0.19.2', $original_version ) );
$this->assertEquals( 'minor', Utils\get_named_sem_ver( '0.20.0', $original_version ) );
$this->assertEquals( 'minor', Utils\get_named_sem_ver( '0.20.3', $original_version ) );
Expand All @@ -54,7 +60,14 @@ public function testGetSemVerWP() {
$original_version = '3.0';
$this->assertEmpty( Utils\get_named_sem_ver( '2.8', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '2.9.1', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( 'nonsense', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '2.0-beta3', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '3.0-dev1', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '3.0-beta3', $original_version ) );
$this->assertEmpty( Utils\get_named_sem_ver( '3.0.1-dev1', $original_version ) ); // -dev suffix not accepted by SemVer.
$this->assertEquals( 'patch', Utils\get_named_sem_ver( '3.0.1-beta3', $original_version ) );
$this->assertEquals( 'patch', Utils\get_named_sem_ver( '3.0.1', $original_version ) );
$this->assertEquals( 'minor', Utils\get_named_sem_ver( '3.1-beta3', $original_version ) );
$this->assertEquals( 'minor', Utils\get_named_sem_ver( '3.1', $original_version ) );
$this->assertEquals( 'minor', Utils\get_named_sem_ver( '3.1.1', $original_version ) );
$this->assertEquals( 'major', Utils\get_named_sem_ver( '4.0', $original_version ) );
Expand Down

0 comments on commit 93f5880

Please sign in to comment.