From ecedb39ea942df7e718d6ecfac7d84d89c6ae2b1 Mon Sep 17 00:00:00 2001 From: Alexandre Roux D'Anzi Date: Tue, 8 Nov 2022 14:51:55 +0100 Subject: [PATCH 1/3] specify minimal eOS version in rollout config file --- src/Helpers/Build.php | 36 ++++++++++++++++++++++++++++++++---- src/Helpers/Builds.php | 3 ++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 7e2df2d..0d076c7 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -403,6 +403,15 @@ private function parseSemVer($versionString) { $versionArray = explode(".", $versionString); + if(empty($versionArray[0])) { + $versionArray[0] = 0; + } + if(empty($versionArray[1])) { + $versionArray[1] = 0; + } + if(empty($versionArray[2])) { + $versionArray[2] = 0; + } return array_map("intval", $versionArray); } @@ -532,9 +541,9 @@ * @param type $params The params dictionary inside the current POST request * @return boolean True if valid, False if not. */ - public function includeInResults($params) + public function includeInResults($params, $currenteOSVersion) { - return $this->isValid($params) && $this->checkRollout() && $this->getSize() > 0; + return $this->isValid($params) && $this->checkRollout($currenteOSVersion) && $this->getSize() > 0; } /** @@ -559,8 +568,27 @@ * Return if rollout successful or not for a build * @return boolean */ - public function checkRollout() - { + + public function checkRollout($currenteOSVersion="") + { + $minimalVersion = isset($this->confProp['requirements']) ? $this->confProp['requirements']['minOSVersion'] : null; + $isCompatible = true; + if(isset($minimalVersion)){ + $currenteOSVersionSemantic = $this->parseSemVer($currenteOSVersion); + $minimalSemanticVersion = $this->parseSemVer($minimalVersion); + $isCompatible = false; + if($currenteOSVersionSemantic[0] == $minimalSemanticVersion[0]){ + if($currenteOSVersionSemantic[1] == $minimalSemanticVersion[1]){ + $isCompatible=$currenteOSVersionSemantic[2] >= $minimalSemanticVersion[2]; + } + else + $isCompatible = $currenteOSVersionSemantic[1] > $minimalSemanticVersion[1]; + } + else + $isCompatible = $currenteOSVersionSemantic[0] > $minimalSemanticVersion[0]; + } + if( !$isCompatible ) + return false; $rolloutpercentage = isset($this->confProp['rollout']['percentage']) ? (int) $this->confProp['rollout']['percentage'] : 100; if ($rolloutpercentage < 0 || $rolloutpercentage > 100) { return TRUE; diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index 0c8d8e5..b7e84b4 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -162,6 +162,7 @@ $params = $this->postData['params']; preg_match_all('/.*(eOS) v([0-9\.]+)-?((alpha|beta|rc)(\.\d)?)?.*/', $_SERVER['HTTP_USER_AGENT'], $currentTokens); $shouldDisplayPatch=false; + $this->currenteOSVersion = -1; if(isset($currentTokens[2]) && count($currentTokens[2])>0){ $this->currenteOSVersion = $currentTokens[2][0]; $versionArray = explode(".", $this->currenteOSVersion); @@ -204,7 +205,7 @@ $build = new Build($file, $dir, $this->logger, $shouldDisplayPatch); } - if ($build->includeInResults($this->postData['params'])) { + if ($build->includeInResults($this->postData['params'], $this->currenteOSVersion)) { array_push($this->builds, $build); } -- GitLab From e6f70eac8f78487a9fd86ed64f5e8e047a7743c0 Mon Sep 17 00:00:00 2001 From: Alexandre Roux D'Anzi Date: Tue, 8 Nov 2022 14:54:01 +0100 Subject: [PATCH 2/3] adapt comment --- src/Helpers/Build.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 0d076c7..c4a3e7a 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -565,7 +565,7 @@ } /** - * Return if rollout successful or not for a build + * Return if rollout and requirements successful or not for a build * @return boolean */ -- GitLab From fdd4cb0d14bf3f7fdce715bc0ab898d63d41e8ad Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Tue, 8 Nov 2022 14:43:22 +0000 Subject: [PATCH 3/3] use checkRequirements instead of checkRollout --- src/Helpers/Build.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index c4a3e7a..87bcf4d 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -543,7 +543,7 @@ */ public function includeInResults($params, $currenteOSVersion) { - return $this->isValid($params) && $this->checkRollout($currenteOSVersion) && $this->getSize() > 0; + return $this->isValid($params) && $this->checkRollout() && $this->checkRequirements($currenteOSVersion) && $this->getSize() > 0; } /** @@ -565,11 +565,10 @@ } /** - * Return if rollout and requirements successful or not for a build + * Return if requirements are met or not for a build * @return boolean - */ - - public function checkRollout($currenteOSVersion="") + */ + public function checkRequirements($currenteOSVersion="") { $minimalVersion = isset($this->confProp['requirements']) ? $this->confProp['requirements']['minOSVersion'] : null; $isCompatible = true; @@ -579,7 +578,7 @@ $isCompatible = false; if($currenteOSVersionSemantic[0] == $minimalSemanticVersion[0]){ if($currenteOSVersionSemantic[1] == $minimalSemanticVersion[1]){ - $isCompatible=$currenteOSVersionSemantic[2] >= $minimalSemanticVersion[2]; + $isCompatible = $currenteOSVersionSemantic[2] >= $minimalSemanticVersion[2]; } else $isCompatible = $currenteOSVersionSemantic[1] > $minimalSemanticVersion[1]; @@ -587,8 +586,16 @@ else $isCompatible = $currenteOSVersionSemantic[0] > $minimalSemanticVersion[0]; } - if( !$isCompatible ) - return false; + return $isCompatible; + } + + /** + * Return if rollout successful or not for a build + * @return boolean + */ + + public function checkRollout() + { $rolloutpercentage = isset($this->confProp['rollout']['percentage']) ? (int) $this->confProp['rollout']['percentage'] : 100; if ($rolloutpercentage < 0 || $rolloutpercentage > 100) { return TRUE; -- GitLab