Skip to content

Commit

Permalink
fix: pull latest github release
Browse files Browse the repository at this point in the history
In some cases the first release may be a pre-release or otherwise may not be the latest.

Use the /latest url to get the "latest" according to github
  • Loading branch information
ctrlaltf24 authored and thw26 committed Oct 23, 2024
1 parent 1fc367a commit 0def2e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
31 changes: 14 additions & 17 deletions ou_dedetai/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,48 +367,45 @@ def same_size(url, file_path):
return res


def get_latest_release_data(releases_url):
data = net_get(releases_url)
def get_latest_release_data(repository):
release_url = f"https://api.github.com/repos/{repository}/releases/latest"
data = net_get(release_url)
if data:
try:
json_data = json.loads(data.decode())
except json.JSONDecodeError as e:
logging.error(f"Error decoding JSON response: {e}")
return None

if not isinstance(json_data, list) or len(json_data) == 0:
logging.error("Invalid or empty JSON response.")
return None
else:
return json_data
return json_data
else:
logging.critical("Could not get latest release URL.")
return None


def get_latest_release_url(json_data):
def get_first_asset_url(json_data):
release_url = None
if json_data:
release_url = json_data[0].get('assets')[0].get('browser_download_url')
release_url = json_data.get('assets')[0].get('browser_download_url')
logging.info(f"Release URL: {release_url}")
return release_url


def get_tag_name(json_data):
tag_name = None
if json_data:
tag_name = json_data[0].get('tag_name')
tag_name = json_data.get('tag_name')
logging.info(f"Release URL Tag Name: {tag_name}")
return tag_name


def set_logoslinuxinstaller_latest_release_config():
if config.lli_release_channel is None or config.lli_release_channel == "stable": # noqa: E501
releases_url = "https://api.github.com/repos/FaithLife-Community/LogosLinuxInstaller/releases" # noqa: E501
repo = "FaithLife-Community/LogosLinuxInstaller"
else:
releases_url = "https://api.github.com/repos/FaithLife-Community/test-builds/releases" # noqa: E501
json_data = get_latest_release_data(releases_url)
logoslinuxinstaller_url = get_latest_release_url(json_data)
repo = "FaithLife-Community/test-builds"
json_data = get_latest_release_data(repo)
logoslinuxinstaller_url = get_first_asset_url(json_data)
if logoslinuxinstaller_url is None:
logging.critical(f"Unable to set {config.name_app} release without URL.") # noqa: E501
return
Expand All @@ -421,10 +418,10 @@ def set_logoslinuxinstaller_latest_release_config():


def set_recommended_appimage_config():
releases_url = "https://api.github.com/repos/FaithLife-Community/wine-appimages/releases" # noqa: E501
repo = "FaithLife-Community/wine-appimages"
if not config.RECOMMENDED_WINE64_APPIMAGE_URL:
json_data = get_latest_release_data(releases_url)
appimage_url = get_latest_release_url(json_data)
json_data = get_latest_release_data(repo)
appimage_url = get_first_asset_url(json_data)
if appimage_url is None:
logging.critical("Unable to set recommended appimage config without URL.") # noqa: E501
return
Expand Down
6 changes: 3 additions & 3 deletions ou_dedetai/wine.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ def set_win_version(exe, windows_version):


def install_icu_data_files(app=None):
releases_url = "https://api.github.com/repos/FaithLife-Community/icu/releases" # noqa: E501
json_data = network.get_latest_release_data(releases_url)
icu_url = network.get_latest_release_url(json_data)
repo = "FaithLife-Community/icu"
json_data = network.get_latest_release_data(repo)
icu_url = network.get_first_asset_url(json_data)
# icu_tag_name = utils.get_latest_release_version_tag_name(json_data)
if icu_url is None:
logging.critical(f"Unable to set {config.name_app} release without URL.") # noqa: E501
Expand Down

0 comments on commit 0def2e5

Please sign in to comment.