Skip to content

Commit

Permalink
feat: copy and paste from my source code, MIT licensed
Browse files Browse the repository at this point in the history
  • Loading branch information
haruki7049 committed Jul 17, 2024
1 parent d8c73d4 commit db71dd4
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions fetch-releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import requests
import subprocess
import re


def get_all_releases(owner: str, repo: str) -> list:
Expand Down Expand Up @@ -85,3 +86,83 @@ def gen_list_of_download_link(sources: dict) -> list:
result.append(assets["browser_download_url"])

return result


def filter_x86_64_linux_link(urls: list) -> list:
result: list = []

for url in urls:
if "deno-x86_64-unknown-linux-gnu" in url:
result.append(url)

return result


def filter_aarch64_linux_link(urls: list) -> list:
result: list = []

for url in urls:
if "deno-aarch64-unknown-linux-gnu" in url:
result.append(url)

return result


def gen_list_of_versions(sources: list) -> list:
result: list = []

for version in sources:
result.append(version["tag_name"])

return result


def gen_releases_list(versions: list, x86_64_linux_urls: list, aarch64_linux_urls: list) -> list:
result: list = []

# An message which counts the number of versions
print("Number of versions:", len(versions))

for url in x86_64_linux_urls:
for version in versions:
if is_correct_version_url(version, url):
print("Generating nix hash for", url)
sha256 = gen_nix_hash(url)
result.append({"version": version.replace("v", ""), "url": url, "arch": "x86_64-linux", "sha256": sha256})

elif is_correct_rc_version_url(version, url):
print("Generating nix hash for", url)
sha256 = gen_nix_hash(url)
result.append({"version": version.replace("v", ""), "url": url, "arch": "x86_64-linux", "sha256": sha256})

return result


def is_correct_rc_version_url(version: str, url: str) -> bool:
pattern = r"releases/download/(v\d+\.\d+\.\d+-rc\d+)/deno-"
match = re.search(pattern, url)
if match:
return match.group(1) == version


def is_correct_version_url(version: str, url: str) -> bool:
pattern = r"releases/download/(v\d+\.\d+\.\d+)/deno-"
match = re.search(pattern, url)
if match:
return match.group(1) == version


if __name__ == "__main__":
owner: str = "denoland"
repo: str = "deno"
destination = "sources.json"

deno_info: list = get_all_releases(owner, repo)
versions: list = gen_list_of_versions(deno_info)
urls: list = gen_list_of_download_link(deno_info)
x86_64_linux_urls: list = filter_x86_64_linux_link(urls)
aarch64_linux_urls: list = filter_aarch64_linux_link(urls)
releases_list: dict = { "deno": gen_releases_list(versions, x86_64_linux_urls, aarch64_linux_urls)}

save_to_json(releases_list, destination)
print("Done!")

0 comments on commit db71dd4

Please sign in to comment.