1 |
commit: 715c1a649eed5da8b292bf105351024c90ba6f9e |
2 |
Author: Stephan Hartmann <sultan <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Jan 31 20:19:56 2022 +0000 |
4 |
Commit: Stephan Hartmann <sultan <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Jan 31 20:19:56 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/chromium-tools.git/commit/?id=715c1a64 |
7 |
|
8 |
Add edge-bump script |
9 |
|
10 |
Signed-off-by: Stephan Hartmann <sultan <AT> gentoo.org> |
11 |
|
12 |
edge-bump | 347 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 |
1 file changed, 347 insertions(+) |
14 |
|
15 |
diff --git a/edge-bump b/edge-bump |
16 |
new file mode 100755 |
17 |
index 0000000..5a44177 |
18 |
--- /dev/null |
19 |
+++ b/edge-bump |
20 |
@@ -0,0 +1,347 @@ |
21 |
+#!/bin/env python3 |
22 |
+ |
23 |
+import argparse |
24 |
+import json |
25 |
+import os |
26 |
+import shutil |
27 |
+import sys |
28 |
+import urllib.request |
29 |
+import subprocess |
30 |
+import functools |
31 |
+import operator |
32 |
+ |
33 |
+from debian import deb822 |
34 |
+from contextlib import closing |
35 |
+ |
36 |
+from portage.dbapi.porttree import portdbapi |
37 |
+from portage.versions import * |
38 |
+from portage.package.ebuild import digestgen, config |
39 |
+from portage.output import EOutput |
40 |
+ |
41 |
+from git import Repo |
42 |
+ |
43 |
+pkg_data = \ |
44 |
+{ |
45 |
+ "stable" : |
46 |
+ { |
47 |
+ "pkg" : "microsoft-edge", |
48 |
+ "suffix" : "stable", |
49 |
+ "version" : [], |
50 |
+ "dversion" : [], |
51 |
+ "bversion" : [], |
52 |
+ "stable" : True, |
53 |
+ "count" : 1 |
54 |
+ }, |
55 |
+ "beta" : |
56 |
+ { |
57 |
+ "pkg" : "microsoft-edge-beta", |
58 |
+ "suffix" : None, |
59 |
+ "version" : [], |
60 |
+ "dversion" : [], |
61 |
+ "bversion" : [], |
62 |
+ "stable" : False, |
63 |
+ "count" : 3 |
64 |
+ }, |
65 |
+ "dev" : |
66 |
+ { |
67 |
+ "pkg" : "microsoft-edge-dev", |
68 |
+ "suffix" : None, |
69 |
+ "version" : [], |
70 |
+ "dversion" : [], |
71 |
+ "bversion" : [], |
72 |
+ "stable" : False, |
73 |
+ "count" : 3 |
74 |
+ } |
75 |
+} |
76 |
+ |
77 |
+def getEdgeVersionData(base_url, archive, dist, comp, arch): |
78 |
+ if not base_url.endswith("/"): |
79 |
+ url = base_url + "/" |
80 |
+ url += f"{archive}/dists/{dist}/{comp}/binary-{arch}/Packages" |
81 |
+ |
82 |
+ with closing(urllib.request.urlopen(url)) as fp: |
83 |
+ return list(deb822.Packages.iter_paragraphs(fp, use_apt_pkg=False)) |
84 |
+ |
85 |
+def compareEdgeVersion(item1, item2): |
86 |
+ return -vercmp(item1[0], item2[0]) |
87 |
+ |
88 |
+def getEdgeChannelVersions(versions, channel): |
89 |
+ pkg = pkg_data[channel]["pkg"] |
90 |
+ if pkg_data[channel]["suffix"] is not None: |
91 |
+ pkg += "-" + pkg_data[channel]["suffix"] |
92 |
+ v = [] |
93 |
+ for item in versions: |
94 |
+ if item["Package"] == pkg: |
95 |
+ (version, revision) = item["Version"].split("-") |
96 |
+ v.append((version, revision)) |
97 |
+ v.sort(key=functools.cmp_to_key(compareEdgeVersion)) |
98 |
+ return v |
99 |
+ |
100 |
+def isMajorBump(uversion, tversion): |
101 |
+ uv_list = uversion.split(".") |
102 |
+ tv_list = tversion.split(".") |
103 |
+ if int(uv_list[0]) > int(tv_list[0]): |
104 |
+ return True |
105 |
+ return False |
106 |
+ |
107 |
+def getPrevChannel(channel): |
108 |
+ channels = list(pkg_data.keys()) |
109 |
+ channel_list = channels + [channels[len(channels) - 1]] |
110 |
+ for i in range(0, len(channel_list) - 1): |
111 |
+ if channel_list[i] == channel: |
112 |
+ return channel_list[i + 1] |
113 |
+ raise ValueError(f"Unknown channel \"{channel}\".") |
114 |
+ |
115 |
+def getEbuildVersion(version): |
116 |
+ if version[1] == "r0": |
117 |
+ return version[0] |
118 |
+ return f"{version[0]}-{version[1]}" |
119 |
+ |
120 |
+def main(): |
121 |
+ parser = argparse.ArgumentParser() |
122 |
+ parser.add_argument("--dry-run", "-n", action="store_true") |
123 |
+ args = parser.parse_args() |
124 |
+ |
125 |
+ output = EOutput() |
126 |
+ |
127 |
+ output.einfo("Fetching upstream version information ...") |
128 |
+ |
129 |
+ versions = getEdgeVersionData(base_url="https://packages.microsoft.com/repos", |
130 |
+ archive="edge", dist="stable", comp="main", |
131 |
+ arch="amd64") |
132 |
+ |
133 |
+ edge_info = {} |
134 |
+ for channel in pkg_data.keys(): |
135 |
+ edge_info[channel] = [] |
136 |
+ |
137 |
+ for channel in pkg_data.keys(): |
138 |
+ edge_info[channel] = getEdgeChannelVersions(versions=versions, |
139 |
+ channel=channel) |
140 |
+ |
141 |
+ output.einfo("Looking up Edge versions information in tree ...") |
142 |
+ |
143 |
+ db = portdbapi() |
144 |
+ repo_path = db.getRepositoryPath(repository_id="gentoo") |
145 |
+ for channel in pkg_data.keys(): |
146 |
+ pkg = pkg_data[channel]["pkg"] |
147 |
+ cpvs = db.cp_list(mycp=f"www-client/{pkg}", mytree=repo_path) |
148 |
+ for cpv in cpvs: |
149 |
+ (cp, version, rev) = pkgsplit(mypkg=cpv) |
150 |
+ pkg_data[channel]["version"].append((version,rev)) |
151 |
+ if len(pkg_data[channel]["version"]) == 0: |
152 |
+ output.ewarn("Couldn't determine tree versions for "+ |
153 |
+ "www-client/{pkg}") |
154 |
+ pkg_data[channel]["version"].sort(key=functools.cmp_to_key(compareEdgeVersion)) |
155 |
+ |
156 |
+ output.einfo("Comparing Edge version informations ...") |
157 |
+ |
158 |
+ for channel in pkg_data.keys(): |
159 |
+ versions = map(operator.itemgetter(0), edge_info[channel]) |
160 |
+ for ver in pkg_data[channel]["version"]: |
161 |
+ if ver[0] not in versions: |
162 |
+ output.ewarn("Upstream dropped version " + |
163 |
+ f"{ver} from channel " + |
164 |
+ f"\"{channel}\" of www-client/" + |
165 |
+ f"{pkg_data[channel]['pkg']}.") |
166 |
+ pkg_data[channel]["dversion"].append(ver) |
167 |
+ |
168 |
+ for channel in pkg_data.keys(): |
169 |
+ if len(edge_info[channel]) == 0: |
170 |
+ output.ewarn(f"Upstream version unknown for channel \"{channel}\".") |
171 |
+ else: |
172 |
+ for uver in edge_info[channel]: |
173 |
+ bump = None |
174 |
+ for tver in pkg_data[channel]["version"]: |
175 |
+ ver_info = vercmp(uver[0], getEbuildVersion(tver)) |
176 |
+ if ver_info is None: |
177 |
+ output.ewarn("Cannot determine new version for " + |
178 |
+ f"channel \"{channel}\" of " + |
179 |
+ f"www-client/" + |
180 |
+ f"{pkg_data[channel]['pkg']}.") |
181 |
+ bump = False |
182 |
+ break |
183 |
+ elif ver_info > 0: |
184 |
+ if bump is None: |
185 |
+ bump = True |
186 |
+ elif ver_info == 0: |
187 |
+ bump = False |
188 |
+ elif ver_info < 0: |
189 |
+ bump = False |
190 |
+ if bump: |
191 |
+ pkg_data[channel]["bversion"].append((uver[0], "r0")) |
192 |
+ |
193 |
+ if ( len(pkg_data[channel]["bversion"]) == 0 and |
194 |
+ len(pkg_data[channel]["dversion"]) == |
195 |
+ len(pkg_data[channel]["version"]) ): |
196 |
+ output.ewarn("Update would remove all versions " + |
197 |
+ f"from tree for channel \"{channel}\" of " + |
198 |
+ f"www-client/" + |
199 |
+ f"{pkg_data[channel]['pkg']}.") |
200 |
+ pkg_data[channel]["dversion"] = [] |
201 |
+ elif ( len(pkg_data[channel]["bversion"]) >= |
202 |
+ pkg_data[channel]["count"] ): |
203 |
+ count = pkg_data[channel]["count"] |
204 |
+ pkg_data[channel]["bversion"] = \ |
205 |
+ pkg_data[channel]["bversion"][:count] |
206 |
+ pkg_data[channel]["dversion"] = pkg_data[channel]["version"] |
207 |
+ elif ( len(pkg_data[channel]["bversion"]) + |
208 |
+ len(pkg_data[channel]["version"]) > |
209 |
+ pkg_data[channel]["count"] ): |
210 |
+ count = len(pkg_data[channel]["bversion"]) + \ |
211 |
+ len(pkg_data[channel]["version"]) - \ |
212 |
+ pkg_data[channel]["count"] |
213 |
+ pkg_data[channel]["dversion"] = \ |
214 |
+ pkg_data[channel]["version"][-count:] |
215 |
+ |
216 |
+ for channel in pkg_data.keys(): |
217 |
+ pkg = pkg_data[channel]["pkg"] |
218 |
+ output.einfo(f"www-client/{pkg} version information:") |
219 |
+ vstr = "" |
220 |
+ for ver in reversed(pkg_data[channel]["version"]): |
221 |
+ if ver in pkg_data[channel]["dversion"]: |
222 |
+ vstr += f"({getEbuildVersion(ver)})\t" |
223 |
+ else: |
224 |
+ vstr += f"{getEbuildVersion(ver)}\t" |
225 |
+ for ver in pkg_data[channel]["bversion"]: |
226 |
+ vstr += f"{getEbuildVersion(ver)}*\t" |
227 |
+ output.einfo(f"\t{channel}\t{vstr}") |
228 |
+ |
229 |
+ if len(pkg_data[channel]["bversion"]) > 0: |
230 |
+ output.einfo(f"\t\t==> bump") |
231 |
+ elif len(pkg_data[channel]["dversion"]) > 0: |
232 |
+ output.einfo(f"\t\t==> cleanup") |
233 |
+ else: |
234 |
+ output.einfo(f"\t\t==> unchanged") |
235 |
+ |
236 |
+ if not args.dry_run: |
237 |
+ repo = Repo(repo_path) |
238 |
+ if repo.is_dirty(): |
239 |
+ output.eerror("Git Repository is dirty, can't continue.") |
240 |
+ sys.exit(1) |
241 |
+ |
242 |
+ index = repo.index |
243 |
+ |
244 |
+ for channel in pkg_data.keys(): |
245 |
+ pkg = pkg_data[channel]["pkg"] |
246 |
+ tver = pkg_data[channel]["version"][0] |
247 |
+ tversion = getEbuildVersion(tver) |
248 |
+ for uver in pkg_data[channel]["bversion"]: |
249 |
+ uversion = getEbuildVersion(uver) |
250 |
+ major_bump = isMajorBump(uversion=uver[0], tversion=tver[0]) |
251 |
+ output.einfo(f"Bumping www-client/{pkg}-{uversion} ...") |
252 |
+ if major_bump: |
253 |
+ prev_channel = getPrevChannel(channel=channel) |
254 |
+ prev_pkg = pkg_data[prev_channel]["pkg"] |
255 |
+ prev_version = getEbuildVersion( |
256 |
+ pkg_data[prev_channel]["version"][0]) |
257 |
+ from_ebuild = os.path.join("www-client", |
258 |
+ prev_pkg, |
259 |
+ prev_pkg + "-" + |
260 |
+ prev_version + |
261 |
+ ".ebuild") |
262 |
+ else: |
263 |
+ from_ebuild = os.path.join("www-client", |
264 |
+ pkg, |
265 |
+ pkg + "-" + |
266 |
+ tversion + |
267 |
+ ".ebuild") |
268 |
+ to_ebuild = os.path.join("www-client", |
269 |
+ pkg, |
270 |
+ pkg + "-" + |
271 |
+ uversion + |
272 |
+ ".ebuild") |
273 |
+ |
274 |
+ if args.dry_run: |
275 |
+ print(f"cp {from_ebuild} {to_ebuild}") |
276 |
+ if pkg_data[channel]["stable"]: |
277 |
+ print(f"ekeyword ~amd64 {to_ebuild}") |
278 |
+ print(f"git add {to_ebuild}") |
279 |
+ else: |
280 |
+ to_ebuild = os.path.join(repo_path, to_ebuild) |
281 |
+ from_ebuild = os.path.join(repo_path, from_ebuild) |
282 |
+ shutil.copyfile(from_ebuild, to_ebuild) |
283 |
+ if pkg_data[channel]["stable"]: |
284 |
+ subprocess.check_call(["ekeyword", "~amd64", to_ebuild]) |
285 |
+ index.add(to_ebuild) |
286 |
+ |
287 |
+ if args.dry_run: |
288 |
+ print(f"git add {os.path.join('www-client', pkg, 'Manifest')}") |
289 |
+ print("git commit -m", |
290 |
+ f"\"www-client/{pkg}: automated bump", |
291 |
+ f"({uversion})", |
292 |
+ "-s -S\"") |
293 |
+ else: |
294 |
+ to_path = os.path.dirname(to_ebuild) |
295 |
+ cfg = config.config() |
296 |
+ cfg["O"] = to_path |
297 |
+ |
298 |
+ digestgen.digestgen(None, cfg, db) |
299 |
+ index.add(os.path.join(to_path, "Manifest")) |
300 |
+ |
301 |
+ repo.git.commit("-m", |
302 |
+ f"www-client/{pkg}: automated bump ({uversion})", |
303 |
+ "-s", "-S") |
304 |
+ |
305 |
+ if pkg_data[channel]["stable"]: |
306 |
+ for bver in pkg_data[channel]["bversion"]: |
307 |
+ bversion = getEbuildVersion(bver) |
308 |
+ output.einfo(f"Stabilizing www-client/{pkg}-{bversion} ...") |
309 |
+ ebuild = os.path.join("www-client", |
310 |
+ pkg, |
311 |
+ pkg + "-" + |
312 |
+ bversion + |
313 |
+ ".ebuild") |
314 |
+ if args.dry_run: |
315 |
+ print(f"ekeyword amd64 {ebuild}") |
316 |
+ print(f"git add {os.path.join('www-client', pkg, 'Manifest')}") |
317 |
+ print("git commit -m", |
318 |
+ f"\"www-client/{pkg}: amd64 stable ({bversion})\" -s -S") |
319 |
+ else: |
320 |
+ ebuild = os.path.join(repo_path, ebuild) |
321 |
+ subprocess.check_call(["ekeyword", "amd64", ebuild]) |
322 |
+ index.add(ebuild) |
323 |
+ |
324 |
+ to_path = os.path.dirname(ebuild) |
325 |
+ cfg = config.config() |
326 |
+ cfg["O"] = to_path |
327 |
+ |
328 |
+ digestgen.digestgen(None, cfg, db) |
329 |
+ index.add(os.path.join(to_path, "Manifest")) |
330 |
+ |
331 |
+ repo.git.commit("-m", |
332 |
+ f"www-client/{pkg}: amd64 stable ({bversion})", |
333 |
+ "-s", "-S") |
334 |
+ |
335 |
+ for dver in pkg_data[channel]["dversion"]: |
336 |
+ dversion = getEbuildVersion(dver) |
337 |
+ output.einfo(f"Removing www-client/{pkg}-{dversion} ...") |
338 |
+ rm_ebuild = os.path.join("www-client", |
339 |
+ pkg, |
340 |
+ pkg + "-" + |
341 |
+ dversion + |
342 |
+ ".ebuild") |
343 |
+ if args.dry_run: |
344 |
+ print(f"git rm {os.path.relpath(rm_ebuild, repo_path)}") |
345 |
+ else: |
346 |
+ rm_ebuild = os.path.join(repo_path, rm_ebuild) |
347 |
+ index.remove(rm_ebuild, working_tree=True) |
348 |
+ |
349 |
+ if len(pkg_data[channel]["dversion"]) > 0: |
350 |
+ if args.dry_run: |
351 |
+ print(f"git add {os.path.join('www-client', pkg, 'Manifest')}") |
352 |
+ print("git commit -m", |
353 |
+ f"\"www-client/{pkg}: remove old\" -s -S") |
354 |
+ else: |
355 |
+ to_path = os.path.dirname(rm_ebuild) |
356 |
+ cfg = config.config() |
357 |
+ cfg["O"] = to_path |
358 |
+ |
359 |
+ digestgen.digestgen(None, cfg, db) |
360 |
+ index.add(os.path.join(to_path, "Manifest")) |
361 |
+ |
362 |
+ repo.git.commit("-m", |
363 |
+ f"www-client/{pkg}: remove old", |
364 |
+ "-s", "-S") |
365 |
+ |
366 |
+if __name__ == "__main__": |
367 |
+ main() |