mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-12-26 00:52:46 +00:00
github-release: print less verbose logs, exit with error if any download fails [ci skip]
Signed-off-by: Shengqi Chen <harry-chen@outlook.com>
This commit is contained in:
parent
c0a0cd617e
commit
6d38d8f625
|
|
@ -143,6 +143,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
dst_file.parent.mkdir(parents=True, exist_ok=True)
|
dst_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
# tarball has no size information, use -1 to skip size check
|
# tarball has no size information, use -1 to skip size check
|
||||||
|
logger.info(f"queueing download of {url} to {dst_file.relative_to(working_dir)}")
|
||||||
futures.append(
|
futures.append(
|
||||||
executor.submit(
|
executor.submit(
|
||||||
download_file, url, dst_file, working_dir, updated, -1
|
download_file, url, dst_file, working_dir, updated, -1
|
||||||
|
|
@ -177,6 +178,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
dst_file.parent.mkdir(parents=True, exist_ok=True)
|
dst_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
logger.info(f"queueing download of {url} to {dst_file.relative_to(working_dir)}")
|
||||||
futures.append(
|
futures.append(
|
||||||
executor.submit(
|
executor.submit(
|
||||||
download_file, url, dst_file, working_dir, updated, remote_size
|
download_file, url, dst_file, working_dir, updated, remote_size
|
||||||
|
|
@ -187,14 +189,16 @@ def main():
|
||||||
|
|
||||||
def download_file(
|
def download_file(
|
||||||
url: str, dst_file: Path, working_dir: Path, updated: float, remote_size: int
|
url: str, dst_file: Path, working_dir: Path, updated: float, remote_size: int
|
||||||
) -> None:
|
) -> bool:
|
||||||
logger.info(f"downloading {url} to {dst_file.relative_to(working_dir)}")
|
logger.info(f"downloading {url} to {dst_file.relative_to(working_dir)} ({remote_size} bytes)")
|
||||||
try:
|
try:
|
||||||
do_download(url, dst_file, updated, remote_size)
|
do_download(url, dst_file, updated, remote_size)
|
||||||
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to download {url}: {e}", exc_info=True)
|
logger.error(f"Failed to download {url}: {e}")
|
||||||
if dst_file.is_file():
|
if dst_file.is_file():
|
||||||
dst_file.unlink()
|
dst_file.unlink()
|
||||||
|
return False
|
||||||
|
|
||||||
def link_latest(name: str, repo_dir: Path) -> None:
|
def link_latest(name: str, repo_dir: Path) -> None:
|
||||||
try:
|
try:
|
||||||
|
|
@ -241,8 +245,7 @@ def main():
|
||||||
releases = r.json()
|
releases = r.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Cannot download metadata for {repo}: {e}\n{traceback.format_exc()}",
|
f"Cannot download metadata for {repo}: {e}",
|
||||||
exc_info=True,
|
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -271,8 +274,9 @@ def main():
|
||||||
cleaning = True
|
cleaning = True
|
||||||
|
|
||||||
# 等待所有下载任务完成
|
# 等待所有下载任务完成
|
||||||
concurrent.futures.wait(futures)
|
results, _ = concurrent.futures.wait(futures)
|
||||||
executor.shutdown()
|
executor.shutdown()
|
||||||
|
all_success = all([r.result() for r in results])
|
||||||
|
|
||||||
# XXX: this does not work because `cleaning` is always False when `REPO`` is not empty
|
# XXX: this does not work because `cleaning` is always False when `REPO`` is not empty
|
||||||
if cleaning:
|
if cleaning:
|
||||||
|
|
@ -296,8 +300,10 @@ def main():
|
||||||
f"Failed to remove directory {local_dir}: {e}", exc_info=True
|
f"Failed to remove directory {local_dir}: {e}", exc_info=True
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(f"Total size is {sizeof_fmt(total_size, suffix='')}")
|
logger.info(f"Total size is {sizeof_fmt(total_size, suffix='')}")
|
||||||
|
if not all_success:
|
||||||
|
logger.error("Some files failed to download")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue