Skip to content

Commit 91fc24d

Browse files
authored
[build] Script to update Bazel multitool.lock.json (and update ruff) (#16061)
* Script to update Bazel multitool.lock.json * Update ruff dependency for Python
1 parent c896d2d commit 91fc24d

File tree

3 files changed

+89
-12
lines changed

3 files changed

+89
-12
lines changed

multitool.lock.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@
44
"binaries": [
55
{
66
"kind": "archive",
7-
"url": "https://github.com/astral-sh/ruff/releases/download/0.11.11/ruff-aarch64-unknown-linux-musl.tar.gz",
7+
"url": "https://github.com/astral-sh/ruff/releases/download/0.12.3/ruff-aarch64-unknown-linux-musl.tar.gz",
88
"file": "ruff-aarch64-unknown-linux-musl/ruff",
9-
"sha256": "3ca33d9b68b8b0bc7e3673b7638910ac2f7c5399303b37bec4d13c005481a78a",
9+
"sha256": "7890e49b12c1321688540324a7788457a22711657301598402cba1a9e9be6607",
1010
"os": "linux",
1111
"cpu": "arm64"
1212
},
1313
{
1414
"kind": "archive",
15-
"url": "https://github.com/astral-sh/ruff/releases/download/0.11.11/ruff-x86_64-unknown-linux-musl.tar.gz",
15+
"url": "https://github.com/astral-sh/ruff/releases/download/0.12.3/ruff-x86_64-unknown-linux-musl.tar.gz",
1616
"file": "ruff-x86_64-unknown-linux-musl/ruff",
17-
"sha256": "bb64b083767a5fd0a62e10e9a35614974ad53025e2878cf14a0c698680e6c30c",
17+
"sha256": "6ee9216ba4f7fd761e68bd5c23958e662c67fcff8f49e511660d557431b4bd7c",
1818
"os": "linux",
1919
"cpu": "x86_64"
2020
},
2121
{
2222
"kind": "archive",
23-
"url": "https://github.com/astral-sh/ruff/releases/download/0.11.11/ruff-aarch64-apple-darwin.tar.gz",
23+
"url": "https://github.com/astral-sh/ruff/releases/download/0.12.3/ruff-aarch64-apple-darwin.tar.gz",
2424
"file": "ruff-aarch64-apple-darwin/ruff",
25-
"sha256": "814ccb26bed9c027bfc20ac88d33494ab0be62721757c73be70e26c23efbb3f7",
25+
"sha256": "5769e4841870d1f7c17f12a7d1437222e8035eded52f93c54c035c770dbffebb",
2626
"os": "macos",
2727
"cpu": "arm64"
2828
},
2929
{
3030
"kind": "archive",
31-
"url": "https://github.com/astral-sh/ruff/releases/download/0.11.11/ruff-x86_64-apple-darwin.tar.gz",
31+
"url": "https://github.com/astral-sh/ruff/releases/download/0.12.3/ruff-x86_64-apple-darwin.tar.gz",
3232
"file": "ruff-x86_64-apple-darwin/ruff",
33-
"sha256": "8bef00e82bc07ea26b45adcffc3d55b2d0821f3a3e4d5f441f4dd4ad608fc1be",
33+
"sha256": "472a4790db11a8bcd79cf7b731fb1c036c376f9cc4e6532099f8f39a6f86b9bb",
3434
"os": "macos",
3535
"cpu": "x86_64"
3636
},
3737
{
3838
"kind": "archive",
39-
"url": "https://github.com/astral-sh/ruff/releases/download/0.11.11/ruff-x86_64-pc-windows-msvc.zip",
39+
"url": "https://github.com/astral-sh/ruff/releases/download/0.12.3/ruff-x86_64-pc-windows-msvc.zip",
4040
"file": "ruff-x86_64-pc-windows-msvc/ruff.exe",
41-
"sha256": "b7619ff27098a4d7f37c52fb8fc61ccfe677aaade7722a385b40f8d5273ebddd",
41+
"sha256": "37dc6f2f5756421fc59fe5f841ecaa92beee38a39751dfe5a42bdc13992da3d5",
4242
"os": "windows",
4343
"cpu": "x86_64"
4444
}
4545
]
4646
}
47-
}
47+
}

py/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ commands =
4343
[testenv:linting]
4444
skip_install = true
4545
deps =
46-
ruff==0.11.12
46+
ruff==0.12.3
4747
commands =
4848
ruff check --fix --show-fixes --exit-non-zero-on-fix .
4949
ruff format --exit-non-zero-on-format .

scripts/update_multitool_binaries.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
This script updates the version of tool binaries defined in a Bazel rules_multitool lockfile.
5+
If the tool has binaries hosted in a public GitHub repo's Release assets, it will update the
6+
lockfile's URL and hash to the latest versions, otherwise it will skip it.
7+
8+
See: https://github.com/theoremlp/rules_multitool
9+
10+
-----------------------------------------------------------------------------------------------------------
11+
usage: update_multitool_binaries.py [-h] [--file LOCKFILE_PATH]
12+
13+
options:
14+
-h, --help show this help message and exit
15+
--file LOCKFILE_PATH path to multitool lockfile (defaults to 'multitool.lock.json' in current directory)
16+
-----------------------------------------------------------------------------------------------------------
17+
"""
18+
19+
import argparse
20+
import json
21+
import os
22+
import re
23+
import urllib.request
24+
25+
26+
def run(lockfile_path):
27+
with open(lockfile_path) as f:
28+
data = json.load(f)
29+
30+
for tool in [tool for tool in data if tool != "$schema"]:
31+
match = re.search(f"download/(.*?)/{tool}", data[tool]["binaries"][0]["url"])
32+
if match:
33+
version = match[1]
34+
else:
35+
continue
36+
match = re.search("github.com/(.*?)/releases", data[tool]["binaries"][0]["url"])
37+
if match:
38+
releases_url = f"https://api.github.com/repos/{match[1]}/releases/latest"
39+
else:
40+
continue
41+
try:
42+
with urllib.request.urlopen(releases_url) as response:
43+
json_resp = json.loads(response.read())
44+
new_version = json_resp["tag_name"]
45+
assets = json_resp["assets"]
46+
except Exception:
47+
continue
48+
if new_version != version:
49+
print(f"found new version of '{tool}': {new_version}")
50+
urls = [asset.get("browser_download_url") for asset in assets]
51+
hashes = [asset.get("digest").split(":")[1] for asset in assets]
52+
for binary in data[tool]["binaries"]:
53+
new_url = binary["url"].replace(version, new_version)
54+
new_hash = hashes[urls.index(new_url)]
55+
binary["url"] = new_url
56+
binary["sha256"] = new_hash
57+
58+
with open(lockfile_path, "w") as f:
59+
json.dump(data, f, indent=2)
60+
61+
print(f"\ngenerated new '{lockfile_path}' with updated urls and hashes")
62+
63+
64+
def main():
65+
parser = argparse.ArgumentParser()
66+
parser.add_argument(
67+
"--file",
68+
dest="lockfile_path",
69+
default=os.path.join(os.getcwd(), "multitool.lock.json"),
70+
help="path to multitool lockfile (defaults to 'multitool.lock.json' in current directory)",
71+
)
72+
args = parser.parse_args()
73+
run(args.lockfile_path)
74+
75+
76+
if __name__ == "__main__":
77+
main()

0 commit comments

Comments
 (0)