Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Aug 16, 2023
1 parent 1f1faba commit 64e3f42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions msys2_autobuild/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def asset_is_complete(asset: GitReleaseAsset) -> bool:
return asset.state == "uploaded"


def download_text_asset(asset: GitReleaseAsset) -> str:
def download_text_asset(asset: GitReleaseAsset, cache=False) -> str:
assert asset_is_complete(asset)
session = get_requests_session(nocache=True)
session = get_requests_session(nocache=not cache)
with session.get(asset.browser_download_url, timeout=REQUESTS_TIMEOUT) as r:
r.raise_for_status()
return r.text
Expand Down
26 changes: 20 additions & 6 deletions msys2_autobuild/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from .config import (REQUESTS_TIMEOUT, ArchType, BuildType, Config,
build_type_is_src, get_all_build_types)
from .gh import (CachedAssets, download_text_asset, get_asset_filename,
get_current_repo, get_release, make_writable)
get_current_repo, get_release, make_writable,
asset_is_complete)
from .utils import get_requests_session, queue_website_update


Expand Down Expand Up @@ -384,16 +385,29 @@ def update_status(pkgs: List[Package]) -> None:

# If multiple jobs update this at the same time things can fail
try:
asset = None
asset_name = "status.json"
for asset in release.assets:
if asset.name == asset_name:
break

do_replace = True

# Avoid uploading the same file twice, to save API calls
if asset is not None and asset_is_complete(asset) and asset.size == len(content):
old_content = download_text_asset(asset, cache=True)
if old_content == content.decode():
do_replace = False

if do_replace:
if asset is not None:
with make_writable(asset):
asset.delete_asset()
break
with io.BytesIO(content) as fileobj:
with make_writable(release):
new_asset = release.upload_asset_from_memory( # type: ignore
fileobj, len(content), asset_name)

with io.BytesIO(content) as fileobj:
with make_writable(release):
new_asset = release.upload_asset_from_memory( # type: ignore
fileobj, len(content), asset_name)
except (GithubException, requests.RequestException) as e:
print(e)
return
Expand Down

0 comments on commit 64e3f42

Please sign in to comment.