|
1 | 1 | import requests
|
| 2 | +import os |
| 3 | +import re |
2 | 4 |
|
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 = { |
18 | 14 | # 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", |
21 | 17 | # 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", |
24 | 20 | # 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 |
29 | 58 |
|
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}") |
34 | 61 |
|
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: |
36 | 64 | f.write(response.content)
|
0 commit comments