Skip to content

Commit 0ebbe8b

Browse files
committed
feat(deps): update script to fetch latest versions without major bumps
Improved the dependency update script to automatically use the latest available versions, while keeping the current major version to avoid breaking changes.
1 parent ab6c736 commit 0ebbe8b

File tree

1 file changed

+56
-28
lines changed

1 file changed

+56
-28
lines changed

scripts/update_shared_libraries.py

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,64 @@
11
import requests
2+
import os
3+
import re
24

3-
shared_library_version = "1.7.2"
4-
github_download_url = "https://github.com//bogdanfinn/tls-client/releases/download/v{}/{}"
5-
github_repo_filenames = [
6-
# Windows
7-
f"tls-client-windows-32-v{shared_library_version}.dll",
8-
f"tls-client-windows-64-v{shared_library_version}.dll",
9-
# MacOS
10-
f"tls-client-darwin-arm64-v{shared_library_version}.dylib",
11-
f"tls-client-darwin-amd64-v{shared_library_version}.dylib",
12-
# Linux
13-
f"tls-client-linux-alpine-amd64-v{shared_library_version}.so",
14-
f"tls-client-linux-ubuntu-amd64-v{shared_library_version}.so",
15-
f"tls-client-linux-arm64-v{shared_library_version}.so"
16-
]
17-
dependency_filenames = [
5+
REPO = "bogdanfinn/tls-client"
6+
DEST_DIR = "../tls_client/dependencies/"
7+
MAJOR_VERSION = "1"
8+
9+
# Regex to strip version from filenames like -v1.8.0
10+
version_pattern = re.compile(r"-v?\d+\.\d+\.\d+")
11+
12+
# Mapping from original GitHub filenames (without version) to local dependency filenames
13+
rename_map = {
1814
# Windows
19-
"tls-client-32.dll",
20-
"tls-client-64.dll",
15+
"tls-client-windows-32.dll": "tls-client-32.dll",
16+
"tls-client-windows-64.dll": "tls-client-64.dll",
2117
# MacOS
22-
"tls-client-arm64.dylib",
23-
"tls-client-x86.dylib",
18+
"tls-client-darwin-arm64.dylib": "tls-client-arm64.dylib",
19+
"tls-client-darwin-amd64.dylib": "tls-client-x86.dylib",
2420
# Linux
25-
"tls-client-amd64.so",
26-
"tls-client-x86.so",
27-
"tls-client-arm64.so"
28-
]
21+
"tls-client-linux-alpine-amd64.so": "tls-client-amd64.so",
22+
"tls-client-linux-ubuntu-amd64.so": "tls-client-x86.so",
23+
"tls-client-linux-arm64.so": "tls-client-arm64.so",
24+
}
25+
26+
# Fetch all releases
27+
releases_url = f"https://api.github.com/repos/{REPO}/releases"
28+
releases = requests.get(releases_url).json()
29+
30+
# Find the latest release with the desired major version
31+
latest_release = None
32+
for release in releases:
33+
tag = release.get("tag_name", "")
34+
version = tag.lstrip("v")
35+
if version.startswith(MAJOR_VERSION + "."):
36+
latest_release = release
37+
break
38+
39+
if not latest_release:
40+
print(f"No release found with major version {MAJOR_VERSION}.")
41+
exit(1)
42+
43+
tag_name = latest_release["tag_name"]
44+
assets = latest_release.get("assets", [])
45+
os.makedirs(DEST_DIR, exist_ok=True)
46+
47+
for asset in assets:
48+
name = asset["name"]
49+
50+
# Strip version from filename
51+
name_stripped = version_pattern.sub("", name)
52+
53+
# Apply renaming if matched
54+
target_name = rename_map.get(name_stripped)
55+
if not target_name:
56+
print(f"Skipping unmatched file: {name}")
57+
continue
2958

30-
for github_filename, dependency_filename in zip(github_repo_filenames, dependency_filenames):
31-
response = requests.get(
32-
url=github_download_url.format(shared_library_version, github_filename)
33-
)
59+
download_url = asset["browser_download_url"]
60+
print(f"Downloading {name}{target_name}")
3461

35-
with open(f"../tls_client/dependencies/{dependency_filename}", "wb") as f:
62+
response = requests.get(download_url)
63+
with open(os.path.join(DEST_DIR, target_name), "wb") as f:
3664
f.write(response.content)

0 commit comments

Comments
 (0)