Bug 1252003 - Add publish to balrog builder r=rail a=release DONTBUILD
authorKim Moir <kmoir@mozilla.com>
Thu, 12 May 2016 15:20:55 -0400
changeset 398076 19c1f7431744843e618f98b418cee3618a32677a
parent 398075 3dcde73ca237dd579e1599f635f3cc994afc1346
child 398077 f5e801113dc7950616aa05089f477656b1ba6e16
push id25443
push userfelipc@gmail.com
push dateMon, 08 Aug 2016 17:54:21 +0000
reviewersrail, release
bugs1252003
milestone47.0.2
Bug 1252003 - Add publish to balrog builder r=rail a=release DONTBUILD MozReview-Commit-ID: CeNwtAd2o6e
testing/mozharness/configs/releases/dev_updates_firefox_beta.py
testing/mozharness/configs/releases/dev_updates_firefox_release.py
testing/mozharness/configs/releases/updates_firefox_beta.py
testing/mozharness/configs/releases/updates_firefox_release.py
testing/mozharness/scripts/release/publish_balrog.py
--- a/testing/mozharness/configs/releases/dev_updates_firefox_beta.py
+++ b/testing/mozharness/configs/releases/dev_updates_firefox_beta.py
@@ -26,12 +26,13 @@ config = {
             "version_regex": r"^(\d+\.\d+(b\d+)?)$",
             "requires_mirrors": True,
             # TODO - when we use a real repo, rename this file # s/MozDate/MozBeta-dev/
             "patcher_config": "mozDate-branch-patcher2.cfg",
             "update_verify_channel": "beta-dev-localtest",
             "mar_channel_ids": [],
             "channel_names": ["beta-dev", "beta-dev-localtest", "beta-dev-cdntest"],
             "rules_to_update": ["firefox-beta-dev-cdntest", "firefox-beta-dev-localtest"],
+            "publish_rules": ["firefox-beta"],
         }
     },
     "balrog_use_dummy_suffix": False,
 }
--- a/testing/mozharness/configs/releases/dev_updates_firefox_release.py
+++ b/testing/mozharness/configs/releases/dev_updates_firefox_release.py
@@ -27,21 +27,23 @@ config = {
             "requires_mirrors": False,
             "patcher_config": "mozDate-branch-patcher2.cfg",
             "update_verify_channel": "beta-dev-localtest",
             "mar_channel_ids": [
                 "firefox-mozilla-beta-dev", "firefox-mozilla-release-dev",
             ],
             "channel_names": ["beta-dev", "beta-dev-localtest", "beta-dev-cdntest"],
             "rules_to_update": ["firefox-beta-dev-cdntest", "firefox-beta-dev-localtest"],
+             "publish_rules": ["firefox-beta"],
         },
         "release-dev": {
             "version_regex": r"^\d+\.\d+(\.\d+)?$",
             "requires_mirrors": True,
             "patcher_config": "mozJamun-branch-patcher2.cfg",
             "update_verify_channel": "release-dev-localtest",
             "mar_channel_ids": [],
             "channel_names": ["release-dev", "release-dev-localtest", "release-dev-cdntest"],
             "rules_to_update": ["firefox-release-dev-cdntest", "firefox-release-dev-localtest"],
+            "publish_rules": ["firefox-release"],
         },
     },
     "balrog_use_dummy_suffix": False,
 }
--- a/testing/mozharness/configs/releases/updates_firefox_beta.py
+++ b/testing/mozharness/configs/releases/updates_firefox_beta.py
@@ -22,12 +22,13 @@ config = {
         "beta": {
             "version_regex": r"^(\d+\.\d+(b\d+)?)$",
             "requires_mirrors": True,
             "patcher_config": "mozBeta-branch-patcher2.cfg",
             "update_verify_channel": "beta-localtest",
             "mar_channel_ids": [],
             "channel_names": ["beta", "beta-localtest", "beta-cdntest"],
             "rules_to_update": ["firefox-beta-cdntest", "firefox-beta-localtest"],
+            "publish_rules": ["firefox-beta"],
         },
     },
     "balrog_use_dummy_suffix": False,
 }
--- a/testing/mozharness/configs/releases/updates_firefox_release.py
+++ b/testing/mozharness/configs/releases/updates_firefox_release.py
@@ -24,21 +24,23 @@ config = {
             "requires_mirrors": False,
             "patcher_config": "mozBeta-branch-patcher2.cfg",
             "update_verify_channel": "beta-localtest",
             "mar_channel_ids": [
                 "firefox-mozilla-beta", "firefox-mozilla-release",
             ],
             "channel_names": ["beta", "beta-localtest", "beta-cdntest"],
             "rules_to_update": ["firefox-beta-cdntest", "firefox-beta-localtest"],
+            "publish_rules": ["firefox-beta"],
         },
         "release": {
             "version_regex": r"^\d+\.\d+(\.\d+)?$",
             "requires_mirrors": True,
             "patcher_config": "mozRelease-branch-patcher2.cfg",
             "update_verify_channel": "release-localtest",
             "mar_channel_ids": [],
             "channel_names": ["release", "release-localtest", "release-cdntest"],
             "rules_to_update": ["firefox-release-cdntest", "firefox-release-localtest"],
+            "publish_rules": ["firefox-release"],
         },
     },
     "balrog_use_dummy_suffix": False,
 }
new file mode 100644
--- /dev/null
+++ b/testing/mozharness/scripts/release/publish_balrog.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python
+# lint_ignore=E501
+# ***** BEGIN LICENSE BLOCK *****
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+# ***** END LICENSE BLOCK *****
+""" updates.py
+
+A script publish a release to Balrog.
+
+"""
+
+import os
+import sys
+
+sys.path.insert(1, os.path.dirname(os.path.dirname(sys.path[0])))
+from mozharness.base.vcs.vcsbase import MercurialScript
+from mozharness.mozilla.buildbot import BuildbotMixin
+
+# PublishBalrog {{{1
+
+
+class PublishBalrog(MercurialScript, BuildbotMixin):
+
+    def __init__(self, require_config_file=True):
+        super(PublishBalrog, self).__init__(
+            all_actions=[
+                'clobber',
+                'pull',
+                'submit-to-balrog',
+            ],
+            default_actions=[
+                'clobber',
+                'pull',
+                'submit-to-balrog',
+            ],
+            config={
+                'buildbot_json_path': 'buildprops.json',
+                'credentials_file': 'oauth.txt',
+            },
+            require_config_file=require_config_file
+        )
+
+    def _pre_config_lock(self, rw_config):
+        super(PublishBalrog, self)._pre_config_lock(rw_config)
+        # override properties from buildbot properties here as defined by
+        # taskcluster properties
+        self.read_buildbot_config()
+        if not self.buildbot_config:
+            self.warning("Skipping buildbot properties overrides")
+            return
+        # TODO: version and appVersion should come from repo
+        props = self.buildbot_config["properties"]
+        for prop in ['product', 'version', 'build_number', 'channels',
+                     'balrog_api_root']:
+            if props.get(prop):
+                self.info("Overriding %s with %s" % (prop, props[prop]))
+                self.config[prop] = props.get(prop)
+
+    def query_abs_dirs(self):
+        if self.abs_dirs:
+            return self.abs_dirs
+        self.abs_dirs = super(PublishBalrog, self).query_abs_dirs()
+        self.abs_dirs["abs_tools_dir"] = os.path.join(
+            self.abs_dirs['abs_work_dir'], self.config["repo"]["dest"])
+        return self.abs_dirs
+
+    def query_channel_configs(self):
+        """Return a list of channel configs.
+        For RC builds it returns "release" and "beta" using
+        "enabled_if_version_matches" to match RC.
+
+        :return: list
+         """
+        return [(n, c) for n, c in self.config["update_channels"].items() if
+            n in self.config["channels"]]
+
+    def query_repos(self):
+        """Build a list of repos to clone."""
+        return [self.config["repo"]]
+
+    def pull(self):
+        super(PublishBalrog, self).pull(
+            repos=self.query_repos())
+
+
+    def submit_to_balrog(self):
+        for _, channel_config in self.query_channel_configs():
+            self._submit_to_balrog(channel_config)
+
+    def _submit_to_balrog(self, channel_config):
+        dirs = self.query_abs_dirs()
+        auth = os.path.join(os.getcwd(), self.config['credentials_file'])
+        cmd = [
+            self.query_exe("python"),
+            os.path.join(dirs["abs_tools_dir"],
+                         "scripts/build-promotion/balrog-release-shipper.py")]
+        cmd.extend([
+            "--api-root", self.config["balrog_api_root"],
+            "--credentials-file", auth,
+            "--username", self.config["balrog_username"],
+            "--version", self.config["version"],
+            "--product", self.config["product"],
+            "--build-number", str(self.config["build_number"]),
+            "--verbose",
+        ])
+        for r in channel_config["publish_rules"]:
+            cmd.extend(["--rules", r])
+
+        self.retry(lambda: self.run_command(cmd, halt_on_failure=True))
+
+# __main__ {{{1
+if __name__ == '__main__':
+    PublishBalrog().run_and_exit()