biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / applications / virtualization / crosvm / update.py
blob62e195d3426f2536f7bacaddcbde569df3309769
1 #! /usr/bin/env nix-shell
2 #! nix-shell -p common-updater-scripts python3
3 #! nix-shell -i python
5 import csv
6 import json
7 import re
8 import shlex
9 import subprocess
10 from os.path import abspath, dirname, splitext
11 from urllib.request import urlopen
13 # CrOS version numbers look like this:
14 # [<chrome-major-version>.]<tip-build>.<branch-build>.<branch-branch-build>
16 # As far as I can tell, branches are where internal Google
17 # modifications are added to turn Chromium OS into Chrome OS, and
18 # branch branches are used for fixes for specific devices. So for
19 # Chromium OS they will always be 0. This is a best guess, and is not
20 # documented.
21 with urlopen('https://chromiumdash.appspot.com/cros/download_serving_builds_csv?deviceCategory=ChromeOS') as resp:
22 reader = csv.reader(map(bytes.decode, resp))
23 header = reader.__next__()
24 cr_stable_index = header.index('cr_stable')
25 cros_stable_index = header.index('cros_stable')
26 chrome_version = []
27 platform_version = []
29 for line in reader:
30 if line[cr_stable_index] == "no update":
31 continue
32 this_chrome_version = list(map(int, line[cr_stable_index].split('.')))
33 this_platform_version = list(map(int, line[cros_stable_index].split('.')))
34 chrome_version = max(chrome_version, this_chrome_version)
35 platform_version = max(platform_version, this_platform_version)
37 chrome_major_version = chrome_version[0]
38 chromeos_tip_build = platform_version[0]
39 release_branch = f'release-R{chrome_major_version}-{chromeos_tip_build}.B'
41 # Determine the git revision.
42 with urlopen(f'https://chromium.googlesource.com/chromiumos/platform/crosvm/+/refs/heads/{release_branch}?format=JSON') as resp:
43 resp.readline() # Remove )]}' header
44 rev = json.load(resp)['commit']
46 # Determine the patch version by counting the commits that have been
47 # added to the release branch since it forked off the chromeos branch.
48 with urlopen(f'https://chromium.googlesource.com/chromiumos/platform/crosvm/+log/refs/heads/chromeos..{rev}?format=JSON') as resp:
49 resp.readline() # Remove )]}' header
50 branch_commits = json.load(resp)['log']
51 version = f'{chrome_major_version}.{len(branch_commits)}'
53 # Update the version, git revision, and hash in crosvm's default.nix.
54 subprocess.run(['update-source-version', 'crosvm', f'--rev={rev}', version])