Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7110293

Browse filesBrowse files
committed
Update shared library script to fetch latest version dynamically (based on FlorianREGAZ#138)
Refactored `update_shared_library.py` to dynamically fetch the latest release matching major version 1.x from bogdanfinn/tls-client. Key improvements: - Removed hardcoded version in favor of dynamic resolution - Fetches latest release with major version "1.x" using GitHub API - Uses regex to strip version numbers from asset filenames - Added a mapping for consistent local renaming of binaries - Improved maintainability and reliability across OS platforms This implementation is inspired by and adapted from FlorianREGAZ#138, which improves dependency management by avoiding manual version updates. Original PR: FlorianREGAZ#138
1 parent 74d87b5 commit 7110293
Copy full SHA for 7110293

File tree

Expand file treeCollapse file tree

1 file changed

+58
-34
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+58
-34
lines changed
Open diff view settings
Collapse file

‎scripts/update_shared_library.py‎

Copy file name to clipboard
+58-34Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,64 @@
11
import requests
2+
import os
3+
import re
24

3-
shared_library_version = "1.9.1"
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-{shared_library_version}.dll",
8-
f"tls-client-windows-64-{shared_library_version}.dll",
9-
# MacOS
10-
f"tls-client-darwin-arm64-{shared_library_version}.dylib",
11-
f"tls-client-darwin-amd64-{shared_library_version}.dylib",
12-
# Linux
13-
# f"tls-client-linux-alpine-amd64-{shared_library_version}.so", # Removed in 1.7.8
14-
f"tls-client-linux-ubuntu-amd64-{shared_library_version}.so",
15-
f"tls-client-linux-ubuntu-amd64-{shared_library_version}.so",
16-
f"tls-client-linux-arm64-{shared_library_version}.so"
17-
]
18-
dependency_filenames = [
5+
REPO = "bogdanfinn/tls-client"
6+
DEST_DIR = "../async_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 = {
1914
# Windows
20-
"tls-client-32.dll",
21-
"tls-client-64.dll",
15+
"tls-client-windows-32.dll": "tls-client-32.dll",
16+
"tls-client-windows-64.dll": "tls-client-64.dll",
2217
# MacOS
23-
"tls-client-arm64.dylib",
24-
"tls-client-x86.dylib",
18+
"tls-client-darwin-arm64.dylib": "tls-client-arm64.dylib",
19+
"tls-client-darwin-amd64.dylib": "tls-client-x86.dylib",
2520
# Linux
26-
"tls-client-amd64.so",
27-
"tls-client-x86.so",
28-
"tls-client-arm64.so"
29-
]
30-
31-
for github_filename, dependency_filename in zip(github_repo_filenames, dependency_filenames):
32-
filepath = f"../async_tls_client/dependencies/{dependency_filename}"
33-
url = github_download_url.format(shared_library_version, github_filename)
34-
print(f'Downloading {url}...')
35-
response = requests.get(url=url)
36-
if not response.ok:
37-
print(f'Failed to fetch ({response.status_code})')
38-
print(f'Writing to "{filepath}"...')
39-
with open(filepath, "wb") as f:
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
58+
59+
download_url = asset["browser_download_url"]
60+
print(f"Downloading {name}{target_name}")
61+
62+
response = requests.get(download_url)
63+
with open(os.path.join(DEST_DIR, target_name), "wb") as f:
4064
f.write(response.content)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.