This is an automated email from the ASF dual-hosted git repository. xyz pushed a commit to branch branch-3.7 in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git
commit a142d02bb976009c44fe9f4b3e4d9dc97134b787 Author: Yunze Xu <xyzinfern...@163.com> AuthorDate: Tue Apr 29 20:33:38 2025 +0800 Fix the scripts for downloading GitHub Action artifacts (#485) (cherry picked from commit 0e1ed3b2af24f5373036b839e4131257e8e75bf2) --- build-support/download-release-artifacts.py | 31 ++++++++++++++++------------- build-support/stage-release.sh | 26 ++++++++++++++++-------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/build-support/download-release-artifacts.py b/build-support/download-release-artifacts.py index 211faba..9b1866f 100755 --- a/build-support/download-release-artifacts.py +++ b/build-support/download-release-artifacts.py @@ -18,7 +18,7 @@ # under the License. # -import sys, json, urllib.request, os, shutil, zipfile, tempfile +import sys, requests, os, zipfile, tempfile from pathlib import Path if len(sys.argv) != 3: @@ -39,33 +39,36 @@ workflow_run_id = int(sys.argv[1]) dest_path = sys.argv[2] workflow_run_url = LIST_URL % workflow_run_id -request = urllib.request.Request(workflow_run_url, - headers={'Accept': ACCEPT_HEADER, 'Authorization': 'Bearer ' + GITHUB_TOKEN}) -with urllib.request.urlopen(request) as response: - data = json.loads(response.read().decode("utf-8")) +headers={'Accept': ACCEPT_HEADER, 'Authorization': 'Bearer ' + GITHUB_TOKEN} + +with requests.get(workflow_run_url, headers=headers) as response: + response.raise_for_status() + data = response.json() for artifact in data['artifacts']: name = artifact['name'] # Skip debug artifact if name.endswith("-Debug"): continue + dest_dir = os.path.join(dest_path, name) + if name.find("windows") >= 0 and os.path.exists(dest_dir + ".tar.gz"): + print(f'Skip downloading {name} since {dest_dir}.tar.gz exists') + continue + if os.path.exists(dest_dir) and \ + (os.path.isfile(dest_dir) or len(os.listdir(dest_dir)) > 0): + print(f'Skip downloading {name} since the directory exists') + continue url = artifact['archive_download_url'] print('Downloading %s from %s' % (name, url)) - artifact_request = urllib.request.Request(url, - headers={'Authorization': 'Bearer ' + GITHUB_TOKEN}) - with urllib.request.urlopen(artifact_request) as response: + with requests.get(url, headers=headers, stream=True) as response: tmp_zip = tempfile.NamedTemporaryFile(delete=False) try: - # - shutil.copyfileobj(response, tmp_zip) + for chunk in response.iter_content(chunk_size=8192): + tmp_zip.write(chunk) tmp_zip.close() - dest_dir = os.path.join(dest_path, name) Path(dest_dir).mkdir(parents=True, exist_ok=True) with zipfile.ZipFile(tmp_zip.name, 'r') as z: z.extractall(dest_dir) finally: os.unlink(tmp_zip.name) - - - diff --git a/build-support/stage-release.sh b/build-support/stage-release.sh index c666594..ab0cc8f 100755 --- a/build-support/stage-release.sh +++ b/build-support/stage-release.sh @@ -40,14 +40,24 @@ build-support/generate-source-archive.sh $DEST_PATH build-support/download-release-artifacts.py $WORKFLOW_ID $DEST_PATH pushd "$DEST_PATH" -tar cvzf x64-windows-static.tar.gz x64-windows-static -tar cvzf x86-windows-static.tar.gz x86-windows-static -rm -r x64-windows-static x86-windows-static -mv macos-arm64.zip macos-arm64 -mv macos-arm64/* . -mv macos-x86_64.zip macos-x86_64 -mv macos-x86_64/* . -rm -rf macos-x86_64/ macos-arm64/ +if [[ -d x64-windows-static.tar.gz ]]; then + tar cvzf x64-windows-static.tar.gz x64-windows-static + rm -rf x64-windows-static/ +fi +if [[ -d x86-windows-static.tar.gz ]]; then + tar cvzf x86-windows-static.tar.gz x86-windows-static + rm -rf x86-windows-static/ +fi +if [[ -d macos-arm64.zip ]]; then + mv macos-arm64.zip macos-arm64 + mv macos-arm64/* . + rm -rf macos-arm64 +fi +if [[ -d macos-x86_64.zip ]]; then + mv macos-x86_64.zip macos-x86_64 + mv macos-x86_64/* . + rm -rf macos-x86_64/ +fi popd # Sign all files