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

Commit 0b56ab40 authored by Akhil's avatar Akhil 🙂
Browse files

Merge branch '4789-incremental-rollout-squashed' into 'master'

Added incremental rollout feature for builds

See merge request !32
parents db2bddd9 322f59a6
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -71,6 +71,30 @@ The fields `device` and `channel` are mandatory and `incremental` is an optional
- The contents should be read as: Upgrades from major version 9 to major version 9 and to major version 10 are allowed. Upgrades from major version 10 to major version 10 and to major version 11 are allowed.
- Current version is always available as an upgrade (if a more recent build is found), even if file is not available (for backwards compatibility too).

## How to set incremental rollout percentage in build config file

- You can specify incremental rollout rules by adding values in `config.json` file. You can add the file only if you want percentage incremental rollout for a build.
- The format of file name will be : `<BUILD_NAME>.zip.config.json`

```shell
$ cd builds/full/test/guacamoleb/
$ tree
.
├── e.x.xx-xxyyzz-guacamoleb.zip # the full ROM zip file
└── e.x.xx-xxyyzz-guacamoleb.zip.config.json # the ROM build.config.json file
```

- E.g. : Suppose builds for "guacamoleb" devices are stored at "/mnt/rom/builds/full/test/guacamoleb". The file "/mnt/rom/builds/full/test/guacamoleb/e.x.xx-xxyyzz-guacamoleb.zip.config.json" should then have contents like:
```json
    { 
        "rollout": {
            "percentage": 20
        }   
    }
```
- The `percentage` value must be between 0 to 100. Do not add `%` sign after the value. 
- The `config.json` file is not mandatory. In case it does not exist, a build will consider a 100% rollout percentage.

### ONLY for LineageOS 15.x and newer

If you are willing to use this project on top of your LineageOS 15.x ( or newer ) ROM builds, you may have noticed that the file named `build.prop` have been removed inside your ZIP file, and has been instead integrated within your `system.new.dat` file, which is basically an ext4 image ( you can find out more here: https://source.android.com/devices/tech/ota/block ).
+20 −19
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@
                  );
    
                  Flight::json($ret);
    
            });
        }

+47 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
        private $incremental = '';
        private $filePath = '';
        private $buildProp = '';
        private $confProp = '';
        private $uid = null;
        private $size = '';
        private $logger = null;
@@ -82,6 +83,7 @@
            // - builds/CURRENT_ZIP_FILE.zip/system/build.prop
            // - builds/CURRENT_ZIP_FILE.zip.prop ( which must exist )
            $this->buildProp = explode("\n", @file_get_contents($this->getPropFilePath()));
            $this->confProp = $this->getConfProp();
            // Try to fetch build.prop values. In some cases, we can provide a fallback, in other a null value will be given
            $this->timestamp = intval($this->getBuildPropValue('ro.build.date.utc') ?? filemtime($this->filePath));
            $this->incremental = $this->getBuildPropValue('ro.build.version.incremental') ?? '';
@@ -510,4 +512,48 @@
        {
            return is_callable($func) && false === stripos(ini_get('disable_functions'), $func);
        }

        /**
         * Check if the current build is valid with multiple conditions
         * @param type $params The params dictionary inside the current POST request
         * @return boolean True if valid, False if not.
         */
        public function includeInResults($params)
        {
            return $this->isValid($params) && $this->checkRollout();
        }

        /**
         * Return the correct config file path (depending of version)
         * @return string
         */
        private function getConfigFilePath()
        {
            return file_exists($this->filePath . '.config.json') ? $this->filePath . '.config.json' : '';
        }

        /**
         * Return the all values from config file path
         * @return JSON if valid otherwise null
         */
        private function getConfProp(){
            $configFilePath = $this->getConfigFilePath();
            return ($configFilePath) ?  json_decode( file_get_contents($configFilePath) , true) : array();
        }

        /**
         * Return if rollout successful or not for a build
         * @return boolean
         */
        public function checkRollout()
        {
            $rolloutpercentage = isset($this->confProp['rollout']['percentage']) ? $this->confProp['rollout']['percentage'] : 100;
            if ($rolloutpercentage >= 0 && $rolloutpercentage < 100) {
                $rand_number = rand(0, 100);
                if ($rand_number > $rolloutpercentage) {
                    return false;
                }
            }
            return true;
        }
    }
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -204,7 +204,7 @@
                            $build = new Build($file, $dir, $this->logger);
                        }
                        
                        if ($build->isValid($this->postData['params'])) {
                        if ($build->includeInResults($this->postData['params'])) {
                            array_push($this->builds, $build);
                            if (!empty($this->postData['params']) && strcmp($this->postData['params']['source_incremental'], $build->getIncremental()) == 0) {
                                $this->currentBuild = $build;