diff --git a/.github/scripts/build-package.sh b/.github/scripts/build-package.sh index a4c35309290..746978c49ce 100644 --- a/.github/scripts/build-package.sh +++ b/.github/scripts/build-package.sh @@ -166,7 +166,7 @@ echo "Working directory is '$CURRENT_DIR'..." echo -e "Going to build Matomo $VERSION (Major version: $MAJOR_VERSION)" -if ! echo "$VERSION" | grep -E 'rc|b|a|alpha|beta|dev|build|p[0-9]{14}' -i +if ! echo "$VERSION" | grep -E 'rc|b|a|alpha|beta|dev|build' -i then if curl --output /dev/null --silent --head --fail "https://builds.matomo.org/matomo-$VERSION.zip" then @@ -219,9 +219,7 @@ echo "Git tag: $(git describe --exact-match --tags HEAD)" echo "Git path: $CURRENT_DIR/$LOCAL_REPO" echo "Matomo version in core/Version.php: $(php -r "include_once 'core/Version.php'; echo \Piwik\Version::VERSION;")" -IS_PREVIEW_VERSION=$(php -r "include_once 'core/Version.php'; \$v = new \Piwik\Version(); echo (int) \$v->isPreviewVersion('$VERSION');") - -if [ "$VERSION" != "build" ] && [ "$IS_PREVIEW_VERSION" == "0" ] +if [ "$VERSION" != "build" ] then [ "$(grep "'$VERSION'" core/Version.php | wc -l)" = "1" ] || die "version $VERSION does not match core/Version.php"; fi diff --git a/core/Version.php b/core/Version.php index a484e9b2a34..3dcf52a0f60 100644 --- a/core/Version.php +++ b/core/Version.php @@ -41,13 +41,13 @@ public function isVersionNumber($version): bool private function isNonStableVersion($version): bool { - return (bool) preg_match('/^\d+\.\d+\.\d+((-.{1,4}\d+(-p\d{14})?)|(-dev-p\d{14}))$/i', $version); + return (bool) preg_match('/^\d+\.\d+\.\d+((-.{1,4}\d+(\.\d{14})?)|(-alpha\.\d{14}))$/i', $version); } public function isPreviewVersion($version): bool { - if (\preg_match('/^\d+\.\d+\.\d+((-(rc|b|beta)\d+(-p\d{14})?)|(-dev-p\d{14}))?$/i', $version)) { - if (\preg_match('/-p(\d{14})$/', $version, $matches)) { + if (\preg_match('/^\d+\.\d+\.\d+((-(rc|b|beta)\d+(\.\d{14})?)|(-alpha\.\d{14}))?$/i', $version)) { + if (\preg_match('/\.(\d{14})$/', $version, $matches)) { $dt = DateTime::createFromFormat('YmdHis', $matches[1]); return false !== $dt && !\array_sum(array_map('intval', (array) $dt::getLastErrors())); diff --git a/tests/PHPUnit/Unit/VersionTest.php b/tests/PHPUnit/Unit/VersionTest.php index 4fdcd061356..1370693a1f7 100644 --- a/tests/PHPUnit/Unit/VersionTest.php +++ b/tests/PHPUnit/Unit/VersionTest.php @@ -9,6 +9,7 @@ namespace Piwik\Tests\Unit; +use Composer\Semver\VersionParser; use Piwik\Version; class VersionTest extends \PHPUnit\Framework\TestCase @@ -57,10 +58,10 @@ public function testIsVersionNumber() public function testIsPreviewVersion() { - $this->assertIsPreviewVersion('3.3.3-dev-p20240509114000'); - $this->assertIsPreviewVersion('3.3.3-dev-p33331224183000'); - $this->assertIsPreviewVersion('3.3.3-b1-p20240509114000'); - $this->assertIsPreviewVersion('100.999.9191-rc4-p20240509114000'); + $this->assertIsPreviewVersion('3.3.3-alpha.20240509114000'); + $this->assertIsPreviewVersion('3.3.3-alpha.33331224183000'); + $this->assertIsPreviewVersion('3.3.3-b1.20240509114000'); + $this->assertIsPreviewVersion('100.999.9191-rc4.20240509114000'); $this->assertNotPreviewVersion('3.3'); $this->assertNotPreviewVersion('3.3.'); @@ -68,17 +69,18 @@ public function testIsPreviewVersion() $this->assertNotPreviewVersion('a3.3.3'); $this->assertNotPreviewVersion('3.0.0b'); $this->assertNotPreviewVersion('3.3.3-b1'); - $this->assertNotPreviewVersion('3.3.3-b1-pp20240509114000'); - $this->assertNotPreviewVersion('3.3.3-b1-p20240509114000a'); + $this->assertNotPreviewVersion('3.3.3-b1.p20240509114000'); + $this->assertNotPreviewVersion('3.3.3-b1.20240509114000a'); $this->assertNotPreviewVersion('3.3.3-rc1'); - $this->assertNotPreviewVersion('3.3.3-p20240509114000'); + $this->assertNotPreviewVersion('3.3.3-dev.20240509114000'); + $this->assertNotPreviewVersion('3.3.3.20240509114000'); $this->assertNotPreviewVersion('p20240509114000'); - $this->assertNotPreviewVersion('3.3.3-b1-p202405091140'); - $this->assertNotPreviewVersion('3.3.3-b1-p20243309114000'); - $this->assertNotPreviewVersion('3.3.3-b1-p20240544114000'); - $this->assertNotPreviewVersion('3.3.3-b1-p20240509554000'); - $this->assertNotPreviewVersion('3.3.3-b1-p20240509117700'); - $this->assertNotPreviewVersion('3.3.3-b1-p20240509114088'); + $this->assertNotPreviewVersion('3.3.3-b1.202405091140'); + $this->assertNotPreviewVersion('3.3.3-b1.20243309114000'); + $this->assertNotPreviewVersion('3.3.3-b1.20240544114000'); + $this->assertNotPreviewVersion('3.3.3-b1.20240509554000'); + $this->assertNotPreviewVersion('3.3.3-b1.20240509117700'); + $this->assertNotPreviewVersion('3.3.3-b1.20240509114088'); } private function assertIsStableVersion($versionNumber) @@ -116,4 +118,39 @@ private function assertNotPreviewVersion($versionNumber) $isPreviewVersion = $this->version->isPreviewVersion($versionNumber); $this->assertFalse($isPreviewVersion); } + + /** + * @dataProvider getLowerVersionCompares + */ + public function testVersionContraints($v1, $v2) + { + $v = new VersionParser(); + $v1p = $v->parseConstraints($v1); + $v2p = $v->parseConstraints('<' . $v2); + + self::assertTrue($v2p->matches($v1p)); + } + + /** + * @dataProvider getLowerVersionCompares + */ + public function testVersionCompares($v1, $v2) + { + self::assertTrue(version_compare($v1, $v2, '<')); + } + + public function getLowerVersionCompares() + { + return [ + [ '5.1.0', '6.0.0-b1' ], + [ '5.1.0-alpha.20240517231100', '5.1.0-b1' ], + [ '5.1.0-alpha.20240517231100', '5.1.0-rc1' ], + [ '5.1.0-alpha.20240517231100', '5.1.0-alpha.20240617231100' ], + [ '5.1.0-b1.20240517231100', '5.1.0-b2' ], + [ '5.1.0-b1.20240517231100', '5.1.0-rc1' ], + [ '5.1.0-b1.20240517221100', '5.1.0-b1.20240517231100' ], + [ '5.1.0-rc1.20240517231100', '5.1.0-rc2' ], + [ '5.1.0-rc1.20240517221100', '5.1.0-rc1.20240517231100' ], + ]; + } }