diff --git a/.forgejo/workflows/publish-faceai-container.yml b/.forgejo/workflows/publish-faceai-container.yml index e20f9481..f9fadc8a 100644 --- a/.forgejo/workflows/publish-faceai-container.yml +++ b/.forgejo/workflows/publish-faceai-container.yml @@ -131,34 +131,39 @@ jobs: fi fi - python3 - "${TMP_DIR}/batch-response.json" "${TMP_DIR}/download-url.txt" "${TMP_DIR}/download-headers.txt" <<'PY' - import json - import sys + printf '%s\n' \ + 'import json' \ + 'import sys' \ + '' \ + 'response_path, url_path, headers_path = sys.argv[1:4]' \ + 'with open(response_path, "r", encoding="utf-8") as handle:' \ + ' data = json.load(handle)' \ + '' \ + 'objects = data.get("objects") or []' \ + 'if not objects:' \ + ' raise SystemExit("Forgejo LFS batch response did not contain any objects")' \ + '' \ + 'obj = objects[0]' \ + 'if "error" in obj:' \ + ' raise SystemExit("Forgejo LFS object error: {}".format(obj["error"]))' \ + '' \ + 'download = ((obj.get("actions") or {}).get("download"))' \ + 'if not download or "href" not in download:' \ + ' raise SystemExit("Forgejo LFS batch response did not contain a download action")' \ + '' \ + 'with open(url_path, "w", encoding="utf-8") as handle:' \ + ' handle.write(download["href"])' \ + '' \ + 'headers = download.get("header") or {}' \ + 'with open(headers_path, "w", encoding="utf-8") as handle:' \ + ' for key, value in headers.items():' \ + ' handle.write("{}: {}\\n".format(key, value))' \ + > "${TMP_DIR}/parse_lfs_batch.py" - response_path, url_path, headers_path = sys.argv[1:4] - with open(response_path, 'r', encoding='utf-8') as handle: - data = json.load(handle) - - objects = data.get('objects') or [] - if not objects: - raise SystemExit('Forgejo LFS batch response did not contain any objects') - - obj = objects[0] - if 'error' in obj: - raise SystemExit(f"Forgejo LFS object error: {obj['error']}") - - download = ((obj.get('actions') or {}).get('download')) - if not download or 'href' not in download: - raise SystemExit('Forgejo LFS batch response did not contain a download action') - - with open(url_path, 'w', encoding='utf-8') as handle: - handle.write(download['href']) - - headers = download.get('header') or {} - with open(headers_path, 'w', encoding='utf-8') as handle: - for key, value in headers.items(): - handle.write(f'{key}: {value}\n') - PY + python3 "${TMP_DIR}/parse_lfs_batch.py" \ + "${TMP_DIR}/batch-response.json" \ + "${TMP_DIR}/download-url.txt" \ + "${TMP_DIR}/download-headers.txt" DOWNLOAD_URL="$(cat "${TMP_DIR}/download-url.txt")" download_args=()