mirror of
https://github.com/pyTooling/Actions.git
synced 2026-02-12 02:56:56 +08:00
improve handling of upload failures
This commit is contained in:
59
tip.py
59
tip.py
@@ -8,6 +8,7 @@ from subprocess import check_call
|
|||||||
from glob import glob
|
from glob import glob
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from github import Github
|
from github import Github
|
||||||
|
from github import GithubException
|
||||||
|
|
||||||
print("· Get list of artifacts to be uploaded")
|
print("· Get list of artifacts to be uploaded")
|
||||||
|
|
||||||
@@ -126,29 +127,57 @@ artifacts = files
|
|||||||
|
|
||||||
assets = gh_release.get_assets()
|
assets = gh_release.get_assets()
|
||||||
|
|
||||||
|
|
||||||
|
def delete_asset_by_name(name):
|
||||||
|
for asset in assets:
|
||||||
|
if asset.name == name:
|
||||||
|
asset.delete_asset()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def upload_asset(artifact, name):
|
||||||
|
try:
|
||||||
|
return gh_release.upload_asset(artifact, name=name)
|
||||||
|
except GithubException as ex:
|
||||||
|
if "already_exists" in [err["code"] for err in ex.data["errors"]]:
|
||||||
|
print(f" - {name} exists already! deleting...")
|
||||||
|
delete_asset_by_name(name)
|
||||||
|
else:
|
||||||
|
print(f" - uploading failed: {ex}")
|
||||||
|
except Exception as ex:
|
||||||
|
print(f" - uploading failed: {ex}")
|
||||||
|
|
||||||
|
print(f" - retry uploading {name}...")
|
||||||
|
return gh_release.upload_asset(artifact, name=name)
|
||||||
|
|
||||||
|
|
||||||
|
def replace_asset(artifacts, asset):
|
||||||
|
print(f" > {asset!s}\n {asset.name!s}:")
|
||||||
|
for artifact in artifacts:
|
||||||
|
aname = str(Path(artifact).name)
|
||||||
|
if asset.name == aname:
|
||||||
|
print(f" - uploading tmp.{aname!s}...")
|
||||||
|
new_asset = upload_asset(artifact, name=f"tmp.{aname!s}")
|
||||||
|
print(f" - removing...{aname!s}")
|
||||||
|
asset.delete_asset()
|
||||||
|
print(f" - renaming tmp.{aname!s} to {aname!s}...")
|
||||||
|
new_asset.update_asset(aname, label=aname)
|
||||||
|
artifacts.remove(artifact)
|
||||||
|
return
|
||||||
|
print(" - keep")
|
||||||
|
|
||||||
|
|
||||||
if getenv("INPUT_RM", "false") == "true":
|
if getenv("INPUT_RM", "false") == "true":
|
||||||
print("· RM set. All previous assets are being cleared...")
|
print("· RM set. All previous assets are being cleared...")
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
print(" ", asset.name)
|
print(f" - {asset.name}")
|
||||||
asset.delete_asset()
|
asset.delete_asset()
|
||||||
else:
|
else:
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
print(f" > {asset!s}\n {asset.name!s}:")
|
replace_asset(artifacts, asset)
|
||||||
for artifact in artifacts:
|
|
||||||
aname = str(Path(artifact).name)
|
|
||||||
if asset.name == aname:
|
|
||||||
print(" - uploading tmp...")
|
|
||||||
new_asset = gh_release.upload_asset(artifact, name=f"tmp.{aname!s}")
|
|
||||||
print(" - removing...")
|
|
||||||
asset.delete_asset()
|
|
||||||
print(" - renaming tmp...")
|
|
||||||
new_asset.update_asset(aname, label=aname)
|
|
||||||
artifacts.remove(artifact)
|
|
||||||
break
|
|
||||||
|
|
||||||
for artifact in artifacts:
|
for artifact in artifacts:
|
||||||
print(" >", artifact)
|
print(f" > {artifact!s}:\n - uploading...")
|
||||||
print(" - uploading...")
|
|
||||||
gh_release.upload_asset(artifact)
|
gh_release.upload_asset(artifact)
|
||||||
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|||||||
Reference in New Issue
Block a user