Debian Codegraph @

testing/mozharness/scripts/desktop_partner_repacks.py

raw
1 #!/usr/bin/env python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 # You can obtain one at http://mozilla.org/MPL/2.0/.
5 """desktop_partner_repacks.py
6
7 This script manages Desktop partner repacks for beta/release builds.
8 """
9 import os
10 import sys
11
12 # load modules from parent dir
13 sys.path.insert(1, os.path.dirname(sys.path[0]))
14
15 from mozharness.base.log import FATAL
16 from mozharness.base.python import VirtualenvMixin
17 from mozharness.base.script import BaseScript
18 from mozharness.mozilla.automation import AutomationMixin
19 from mozharness.mozilla.secrets import SecretsMixin
20
21
22 # DesktopPartnerRepacks {{{1
23 class DesktopPartnerRepacks(AutomationMixin, BaseScript, VirtualenvMixin, SecretsMixin):
24 """Manages desktop partner repacks"""
25
26 actions = [
27 "get-secrets",
28 "setup",
29 "repack",
30 "summary",
31 ]
32 config_options = [
33 [
34 ["--version", "-v"],
35 {
36 "dest": "version",
37 "help": "Version of Firefox to repack",
38 },
39 ],
40 [
41 ["--build-number", "-n"],
42 {
43 "dest": "build_number",
44 "help": "Build number of Firefox to repack",
45 },
46 ],
47 [
48 ["--platform"],
49 {
50 "dest": "platform",
51 "help": "Platform to repack (e.g. linux64, macosx64, ...)",
52 },
53 ],
54 [
55 ["--partner", "-p"],
56 {
57 "dest": "partner",
58 "help": "Limit repackaging to partners matching this string",
59 },
60 ],
61 [
62 ["--taskid", "-t"],
63 {
64 "dest": "taskIds",
65 "action": "extend",
66 "help": "taskId(s) of upstream tasks for vanilla Firefox artifacts",
67 },
68 ],
69 [
70 ["--limit-locale", "-l"],
71 {
72 "dest": "limitLocales",
73 "action": "append",
74 },
75 ],
76 ]
77
78 def __init__(self):
79 # fxbuild style:
80 buildscript_kwargs = {
81 "all_actions": DesktopPartnerRepacks.actions,
82 "default_actions": DesktopPartnerRepacks.actions,
83 "config": {
84 "log_name": "partner-repacks",
85 "hashType": "sha512",
86 "workdir": "partner-repacks",
87 },
88 }
89 #
90
91 BaseScript.__init__(
92 self, config_options=self.config_options, **buildscript_kwargs
93 )
94
95 def _pre_config_lock(self, rw_config):
96 if os.getenv("REPACK_MANIFESTS_URL"):
97 self.info(
98 "Overriding repack_manifests_url to %s"
99 % os.getenv("REPACK_MANIFESTS_URL")
100 )
101 self.config["repack_manifests_url"] = os.getenv("REPACK_MANIFESTS_URL")
102 if os.getenv("UPSTREAM_TASKIDS"):
103 self.info("Overriding taskIds with %s" % os.getenv("UPSTREAM_TASKIDS"))
104 self.config["taskIds"] = os.getenv("UPSTREAM_TASKIDS").split()
105
106 if "version" not in self.config:
107 self.fatal("Version (-v) not supplied.")
108 if "build_number" not in self.config:
109 self.fatal("Build number (-n) not supplied.")
110 if "repo_file" not in self.config:
111 self.fatal("repo_file not supplied.")
112 if "repack_manifests_url" not in self.config:
113 self.fatal(
114 "repack_manifests_url not supplied in config or via REPACK_MANIFESTS_URL"
115 )
116 if "taskIds" not in self.config:
117 self.fatal("Need upstream taskIds from command line or in UPSTREAM_TASKIDS")
118
119 def query_abs_dirs(self):
120 if self.abs_dirs:
121 return self.abs_dirs
122 abs_dirs = super(DesktopPartnerRepacks, self).query_abs_dirs()
123 for directory in abs_dirs:
124 value = abs_dirs[directory]
125 abs_dirs[directory] = value
126 dirs = {}
127 dirs["abs_repo_dir"] = os.path.join(abs_dirs["abs_work_dir"], ".repo")
128 dirs["abs_partners_dir"] = os.path.join(abs_dirs["abs_work_dir"], "partners")
129 for key in dirs.keys():
130 if key not in abs_dirs:
131 abs_dirs[key] = dirs[key]
132 self.abs_dirs = abs_dirs
133 return self.abs_dirs
134
135 # Actions {{{
136 def _repo_cleanup(self):
137 self.rmtree(self.query_abs_dirs()["abs_repo_dir"])
138 self.rmtree(self.query_abs_dirs()["abs_partners_dir"])
139
140 def _repo_init(self, repo):
141 partial_env = {
142 "GIT_SSH_COMMAND": "ssh -oIdentityFile={}".format(self.config["ssh_key"])
143 }
144 status = self.run_command(
145 [
146 sys.executable,
147 repo,
148 "init",
149 "--no-repo-verify",
150 "-u",
151 self.config["repack_manifests_url"],
152 ],
153 cwd=self.query_abs_dirs()["abs_work_dir"],
154 partial_env=partial_env,
155 )
156 if status:
157 return status
158 return self.run_command(
159 [sys.executable, repo, "sync", "--current-branch", "--no-tags"],
160 cwd=self.query_abs_dirs()["abs_work_dir"],
161 partial_env=partial_env,
162 )
163
164 def setup(self):
165 """setup step"""
166 repo = self.download_file(
167 self.config["repo_file"],
168 file_name="repo",
169 parent_dir=self.query_abs_dirs()["abs_work_dir"],
170 error_level=FATAL,
171 )
172 if not os.path.exists(repo):
173 self.fatal("Unable to download repo tool.")
174 self.chmod(repo, 0o755)
175 self.retry(
176 self._repo_init,
177 args=(repo,),
178 error_level=FATAL,
179 cleanup=self._repo_cleanup(),
180 good_statuses=[0],
181 sleeptime=5,
182 )
183
184 def repack(self):
185 """creates the repacks"""
186 repack_cmd = [
187 "./mach",
188 "python",
189 "python/mozrelease/mozrelease/partner_repack.py",
190 "-v",
191 self.config["version"],
192 "-n",
193 str(self.config["build_number"]),
194 ]
195 if self.config.get("platform"):
196 repack_cmd.extend(["--platform", self.config["platform"]])
197 if self.config.get("partner"):
198 repack_cmd.extend(["--partner", self.config["partner"]])
199 if self.config.get("taskIds"):
200 for taskId in self.config["taskIds"]:
201 repack_cmd.extend(["--taskid", taskId])
202 if self.config.get("limitLocales"):
203 for locale in self.config["limitLocales"]:
204 repack_cmd.extend(["--limit-locale", locale])
205
206 self.run_command(repack_cmd, cwd=os.environ["GECKO_PATH"], halt_on_failure=True)
207
208
209 # main {{{
210 if __name__ == "__main__":
211 partner_repacks = DesktopPartnerRepacks()
212 partner_repacks.run_and_exit()