Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3f6e8b6 authored by Arnau Vàzquez's avatar Arnau Vàzquez
Browse files

Merge branch '775-ability-to-declare-minimal-eos-version-in-config-file' into 'master'

specify minimal eOS version in rollout config file

See merge request !46
parents e96fc267 63439df4
Loading
Loading
Loading
Loading
+37 −2
Original line number Diff line number Diff line
@@ -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() && $this->checkRequirements($currenteOSVersion) && $this->getSize() > 0;
        }

        /**
@@ -555,10 +564,36 @@
            return ($configFilePath) ?  json_decode( file_get_contents($configFilePath) , true) : array();
        }

        /**
         * Return if requirements are met or not for a build
         * @return boolean
         */ 
        public function checkRequirements($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];
            }
            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;
+2 −1
Original line number Diff line number Diff line
@@ -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);
                    }