Skip to content

Commit 8914b77

Browse files
committed
Script to update Bazel multitool.lock.json
1 parent f6572f5 commit 8914b77

File tree

3 files changed

+98
-11
lines changed

3 files changed

+98
-11
lines changed

multitool.lock.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@
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
}

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 .
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
Requires:
11+
- github module (pip install PyGithub)
12+
13+
```
14+
usage: update_multitool_binaries.py [-h] [--file LOCKFILE_PATH]
15+
16+
options:
17+
-h, --help show this help message and exit
18+
--file LOCKFILE_PATH path to multitool lockfile (defaults to 'multitool.lock.json' in current directory)
19+
```
20+
"""
21+
22+
import argparse
23+
import hashlib
24+
import json
25+
import os
26+
import re
27+
import urllib.request
28+
29+
try:
30+
from github import Github
31+
except ModuleNotFoundError:
32+
exit("requires github module (run: pip install PyGithub)")
33+
34+
35+
def run(lockfile_path):
36+
with open(lockfile_path) as f:
37+
data = json.load(f)
38+
39+
for tool in [tool for tool in data if tool != "$schema"]:
40+
version = re.search(f"download/(.*?)/{tool}", data[tool]["binaries"][0]["url"])[
41+
1
42+
]
43+
match = re.search(
44+
f"github.com/(.*?)/releases", data[tool]["binaries"][0]["url"]
45+
)
46+
if match:
47+
user_repo = match[1]
48+
else:
49+
continue
50+
try:
51+
new_version = Github().get_repo(user_repo).get_releases()[0].title
52+
except Exception:
53+
continue
54+
if new_version != version:
55+
print(f"found new version of '{tool}': {new_version}")
56+
for binary in data[tool]["binaries"]:
57+
new_url = binary["url"].replace(version, new_version)
58+
try:
59+
with urllib.request.urlopen(new_url) as response:
60+
sha256_hash = hashlib.sha256()
61+
sha256_hash.update(response.read())
62+
new_hash = sha256_hash.hexdigest()
63+
binary["url"] = new_url
64+
binary["sha256"] = new_hash
65+
except Exception:
66+
continue
67+
68+
with open(lockfile_path, "w") as f:
69+
json.dump(data, f, indent=2)
70+
71+
print(f"\ngenerated new '{lockfile_path}' with updated urls and hashes")
72+
73+
74+
def main():
75+
parser = argparse.ArgumentParser()
76+
parser.add_argument(
77+
"--file",
78+
dest="lockfile_path",
79+
default=os.path.join(os.getcwd(), "multitool.lock.json"),
80+
help="path to multitool lockfile (defaults to 'multitool.lock.json' in current directory)",
81+
)
82+
args = parser.parse_args()
83+
run(args.lockfile_path)
84+
85+
86+
if __name__ == "__main__":
87+
main()

0 commit comments

Comments
 (0)