diff --git a/build/scripts/publish_resourcepack_release.py b/build/scripts/publish_resourcepack_release.py index 4be26c2..3855c57 100644 --- a/build/scripts/publish_resourcepack_release.py +++ b/build/scripts/publish_resourcepack_release.py @@ -4,6 +4,7 @@ from __future__ import annotations import argparse import json import os +import sys import urllib.error import urllib.parse import urllib.request @@ -11,6 +12,13 @@ import zipfile from pathlib import Path +REQUEST_TIMEOUT_SECONDS = 30 + + +def log(message: str) -> None: + print(message, file=sys.stderr, flush=True) + + def zip_resourcepack(resourcepack_root: Path, archive_path: Path) -> None: archive_path.parent.mkdir(parents=True, exist_ok=True) @@ -24,7 +32,7 @@ def zip_resourcepack(resourcepack_root: Path, archive_path: Path) -> None: def request_json(request: urllib.request.Request) -> dict[str, object]: - with urllib.request.urlopen(request) as response: + with urllib.request.urlopen(request, timeout=REQUEST_TIMEOUT_SECONDS) as response: return json.load(response) @@ -97,13 +105,16 @@ def main() -> int: release_body = args.body or f"Automated resource pack release for {args.tag}." asset_name = f"resourcepack-{args.tag}.zip" + log(f"Packaging resource pack from {resourcepack_root}") zip_resourcepack(resourcepack_root, archive_path) + log(f"Creating release {args.tag} at {api_base}") release = create_release(api_base, repository, token, args.tag, release_name, release_body) release_id = release.get("id") if not isinstance(release_id, int): raise SystemExit("Release creation did not return a numeric release id") + log(f"Uploading {asset_name} to release {release_id}") upload_asset(api_base, repository, token, release_id, archive_path, asset_name) return 0