Skip to content

feat(deps): update script to fetch latest versions without major bumps #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 56 additions & 28 deletions scripts/update_shared_libraries.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,64 @@
import requests
import os
import re

shared_library_version = "1.7.2"
github_download_url = "https://github.com//bogdanfinn/tls-client/releases/download/v{}/{}"
github_repo_filenames = [
# Windows
f"tls-client-windows-32-v{shared_library_version}.dll",
f"tls-client-windows-64-v{shared_library_version}.dll",
# MacOS
f"tls-client-darwin-arm64-v{shared_library_version}.dylib",
f"tls-client-darwin-amd64-v{shared_library_version}.dylib",
# Linux
f"tls-client-linux-alpine-amd64-v{shared_library_version}.so",
f"tls-client-linux-ubuntu-amd64-v{shared_library_version}.so",
f"tls-client-linux-arm64-v{shared_library_version}.so"
]
dependency_filenames = [
REPO = "bogdanfinn/tls-client"
DEST_DIR = "../tls_client/dependencies/"
MAJOR_VERSION = "1"

# Regex to strip version from filenames like -v1.8.0
version_pattern = re.compile(r"-v?\d+\.\d+\.\d+")

# Mapping from original GitHub filenames (without version) to local dependency filenames
rename_map = {
# Windows
"tls-client-32.dll",
"tls-client-64.dll",
"tls-client-windows-32.dll": "tls-client-32.dll",
"tls-client-windows-64.dll": "tls-client-64.dll",
# MacOS
"tls-client-arm64.dylib",
"tls-client-x86.dylib",
"tls-client-darwin-arm64.dylib": "tls-client-arm64.dylib",
"tls-client-darwin-amd64.dylib": "tls-client-x86.dylib",
# Linux
"tls-client-amd64.so",
"tls-client-x86.so",
"tls-client-arm64.so"
]
"tls-client-linux-alpine-amd64.so": "tls-client-amd64.so",
"tls-client-linux-ubuntu-amd64.so": "tls-client-x86.so",
"tls-client-linux-arm64.so": "tls-client-arm64.so",
}

# Fetch all releases
releases_url = f"https://api.github.com/repos/{REPO}/releases"
releases = requests.get(releases_url).json()

# Find the latest release with the desired major version
latest_release = None
for release in releases:
tag = release.get("tag_name", "")
version = tag.lstrip("v")
if version.startswith(MAJOR_VERSION + "."):
latest_release = release
break

if not latest_release:
print(f"No release found with major version {MAJOR_VERSION}.")
exit(1)

tag_name = latest_release["tag_name"]
assets = latest_release.get("assets", [])
os.makedirs(DEST_DIR, exist_ok=True)

for asset in assets:
name = asset["name"]

# Strip version from filename
name_stripped = version_pattern.sub("", name)

# Apply renaming if matched
target_name = rename_map.get(name_stripped)
if not target_name:
print(f"Skipping unmatched file: {name}")
continue

for github_filename, dependency_filename in zip(github_repo_filenames, dependency_filenames):
response = requests.get(
url=github_download_url.format(shared_library_version, github_filename)
)
download_url = asset["browser_download_url"]
print(f"Downloading {name} → {target_name}")

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