Skip to content

Commit

Permalink
Fix next preview version generation to correctly bump patch or b/rc i…
Browse files Browse the repository at this point in the history
…f needed
  • Loading branch information
michalkleiner committed Jul 5, 2024
1 parent 2309f8d commit 8cbb883
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
27 changes: 24 additions & 3 deletions core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,31 @@ public function nextPreviewVersion($version): string
}
return '';
} elseif ($this->isStableVersion($version)) {
// no suffix yet
return $version . '-alpha.' . $dt;
// no suffix yet, we need to bump the patch first
$newVersion = preg_replace_callback(
'/^(\d+\.\d+\.)(\d+)$/',
function ($matches) {
$matches[2] = $matches[2] + 1;
return $matches[1] . $matches[2];
},
$version
);

return sprintf('%s-alpha.%s', $newVersion, $dt);
} elseif ('alpha' === substr($version, -5)) {
// -alpha
return $version . '.' . $dt;
} else {
// -b1, -rc1, -alpha
// -b1, -rc1
$newVersion = preg_replace_callback(
'^(\d+\.\d+\.\d+-(?:rc|b|beta))(\d+)$/i',
function ($matches) {
$matches[2] = $matches[2] + 1;
return $matches[1] . $matches[2];
},
$version
);

return $version . '.' . $dt;
}
}
Expand Down
27 changes: 26 additions & 1 deletion tests/PHPUnit/Unit/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ public function testNextPreviewVersion()
$this->assertNextVersionExists('3.3.3-rc1.20201224180000');
}

public function testNextPreviewCorrectlyBumpsVersionIfNeeded()
{
// stable bumps patch and adds alpha
$this->assertCorrectPreviewVersionWithoutSuffix('3.3.3', '3.3.4-alpha');

// non-stable bumps b1, rc1
$this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-b1', '3.3.3-b2');
$this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-rc1', '3.3.3-rc2');
$this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-b1.20201224180000', '3.3.3-b1');
$this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-rc1.20201224180000', '3.3.3-rc1');

// preview does not bump x.y.z, only dt suffix
$this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-alpha-20201224180000', '3.3.3-alpha');
$this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-b1.20201224180000', '3.3.3-b1');
$this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-rc1.20201224180000', '3.3.3-rc1');
}

private function assertIsStableVersion($versionNumber)
{
$isStable = $this->version->isStableVersion($versionNumber);
Expand Down Expand Up @@ -152,10 +169,18 @@ private function assertNextVersionExists($versionNumber)
$this->assertTrue($this->version->isPreviewVersion($nextVersionNumber));
}

private function assertCorrectPreviewVersionWithoutSuffix($versionNumber, $newVersionNumber)
{
$this->assertStringMatchesFormat(

Check failure on line 174 in tests/PHPUnit/Unit/VersionTest.php

View workflow job for this annotation

GitHub Actions / PHP (UnitTests, 8.2, Mariadb, PDO_MYSQL)

Failed asserting that string matches format description.

Check failure on line 174 in tests/PHPUnit/Unit/VersionTest.php

View workflow job for this annotation

GitHub Actions / PHP (UnitTests, 8.3, Mysql, MYSQLI)

Failed asserting that string matches format description.
"/^$newVersionNumber.\d{14}$/",
$this->version->nextPreviewVersion($versionNumber)

Check failure on line 176 in tests/PHPUnit/Unit/VersionTest.php

View workflow job for this annotation

GitHub Actions / PHP (UnitTests, 7.2, Mysql, PDO_MYSQL)

Failed asserting that string matches format description.
);
}

/**
* @dataProvider getLowerVersionCompares
*/
public function testVersionContraints($v1, $v2)
public function testVersionConstraints($v1, $v2)
{
$v = new VersionParser();
$v1p = $v->parseConstraints($v1);
Expand Down

0 comments on commit 8cbb883

Please sign in to comment.