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

Adjust preview channel condition #22202

Merged
merged 5 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/scripts/build-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ 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|preview' -i
if ! echo "$VERSION" | grep -E 'rc|b|a|alpha|beta|dev|build|p[0-9]{14}' -i
then
if curl --output /dev/null --silent --head --fail "https://builds.matomo.org/$F-$VERSION.zip"
if curl --output /dev/null --silent --head --fail "https://builds.matomo.org/matomo-$VERSION.zip"
then
echo "--> Error: stable version $VERSION has already been built (not expected). <-- "
fi
Expand Down Expand Up @@ -219,7 +219,10 @@ 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;")"

if [ "$VERSION" != "build" ]; then
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" ]
then
[ "$(grep "'$VERSION'" core/Version.php | wc -l)" = "1" ] || die "version $VERSION does not match core/Version.php";
fi

Expand Down Expand Up @@ -268,4 +271,4 @@ if [ "$VERSION" != "build" ]; then
fi
done
done
fi
fi
30 changes: 24 additions & 6 deletions core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Piwik;

use DateTime;

/**
* Matomo version information.
*
Expand All @@ -24,18 +26,34 @@ final class Version

public const MAJOR_VERSION = 5;

public function isStableVersion($version)
public function isStableVersion($version): bool
{
return (bool) preg_match('/^\d+\.\d+\.\d+$/', $version);
}

public function isVersionNumber($version): bool
{
return (bool) preg_match('/^(\d+)\.(\d+)\.(\d+)$/', $version);
return
$this->isStableVersion($version) ||
$this->isNonStableVersion($version) ||
$this->isPreviewVersion($version);
}

public function isVersionNumber($version)
private function isNonStableVersion($version): bool
{
return $this->isStableVersion($version) || $this->isNonStableVersion($version);
return (bool) preg_match('/^\d+\.\d+\.\d+((-.{1,4}\d+(-p\d{14})?)|(-dev-p\d{14}))$/i', $version);
}

private function isNonStableVersion($version)
public function isPreviewVersion($version): bool
{
return (bool) preg_match('/^(\d+)\.(\d+)\.(\d+)-.{1,4}(\d+)$/', $version);
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)) {
$dt = DateTime::createFromFormat('YmdHis', $matches[1]);

return false !== $dt && !\array_sum(array_map('intval', (array) $dt::getLastErrors()));
}
}

return false;
}
}
46 changes: 42 additions & 4 deletions tests/PHPUnit/Unit/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ public function testIsVersionNumber()
$this->assertNotVersionNumber('3.3.3-bbeta1'); // max 4 allowed but bbeta is 5
}

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->assertNotPreviewVersion('3.3');
$this->assertNotPreviewVersion('3.3.');
$this->assertNotPreviewVersion('3-3-3');
$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-rc1');
$this->assertNotPreviewVersion('3.3.3-p20240509114000');
$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');
}

private function assertIsStableVersion($versionNumber)
{
$isStable = $this->version->isStableVersion($versionNumber);
Expand All @@ -69,13 +95,25 @@ private function assertNotStableVersion($versionNumber)

private function assertIsVersionNumber($versionNumber)
{
$isStable = $this->version->isVersionNumber($versionNumber);
$this->assertTrue($isStable);
$isVersionNumber = $this->version->isVersionNumber($versionNumber);
$this->assertTrue($isVersionNumber);
}

private function assertNotVersionNumber($versionNumber)
{
$isStable = $this->version->isVersionNumber($versionNumber);
$this->assertFalse($isStable);
$isVersionNumber = $this->version->isVersionNumber($versionNumber);
$this->assertFalse($isVersionNumber);
}

private function assertIsPreviewVersion($versionNumber)
{
$isPreviewVersion = $this->version->isPreviewVersion($versionNumber);
$this->assertTrue($isPreviewVersion);
}

private function assertNotPreviewVersion($versionNumber)
{
$isPreviewVersion = $this->version->isPreviewVersion($versionNumber);
$this->assertFalse($isPreviewVersion);
}
}
Loading