This is an automated email from the ASF dual-hosted git repository. baodi pushed a commit to branch branch-1.13 in repository https://gitbox.apache.org/repos/asf/pulsar-client-node.git
commit 7f1cbf4dfb4737c091bb2c9c103b229ddcfae0ec Author: Baodi Shi <[email protected]> AuthorDate: Wed Feb 26 11:07:00 2025 +0800 Fix release workflow and script (#404) (cherry picked from commit 36b154eadea1d08eb657b541bbeb18f140889526) --- build-support/download-release-artifacts.py | 61 +++++++++++++++-------------- build-support/stage-release.sh | 2 +- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/build-support/download-release-artifacts.py b/build-support/download-release-artifacts.py index 9b846aa..0fcbcbb 100755 --- a/build-support/download-release-artifacts.py +++ b/build-support/download-release-artifacts.py @@ -17,8 +17,12 @@ # specific language governing permissions and limitations # under the License. # - -import sys, json, urllib.request, os, shutil, zipfile, tempfile +import sys +import requests +import os +import shutil +import zipfile +import tempfile from pathlib import Path if len(sys.argv) != 3: @@ -39,36 +43,35 @@ 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")) - for artifact in data['artifacts']: - name = artifact['name'] - url = artifact['archive_download_url'] +headers = {'Accept': ACCEPT_HEADER, 'Authorization': f'Bearer {GITHUB_TOKEN}'} - 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: - tmp_zip = tempfile.NamedTemporaryFile(delete=False) - try: - # - shutil.copyfileobj(response, tmp_zip) - tmp_zip.close() +response = requests.get(workflow_run_url, headers=headers) +response.raise_for_status() - 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) +data = response.json() +for artifact in data['artifacts']: + name = artifact['name'] + url = artifact['archive_download_url'] - for root, dirs, files in os.walk(dest_path, topdown=False): - for name in files: - shutil.move(os.path.join(root, name), dest_path) - if not os.listdir(root): - os.rmdir(root) + print(f'Downloading {name} from {url}') + artifact_response = requests.get(url, headers=headers, stream=True) + artifact_response.raise_for_status() + with tempfile.NamedTemporaryFile(delete=False) as tmp_zip: + for chunk in artifact_response.iter_content(chunk_size=8192): + tmp_zip.write(chunk) + tmp_zip_path = tmp_zip.name + try: + dest_dir = os.path.join(dest_path, name) + Path(dest_dir).mkdir(parents=True, exist_ok=True) + with zipfile.ZipFile(tmp_zip_path, 'r') as z: + z.extractall(dest_dir) + finally: + os.unlink(tmp_zip_path) +for root, dirs, files in os.walk(dest_path, topdown=False): + for name in files: + shutil.move(os.path.join(root, name), dest_path) + if not os.listdir(root): + os.rmdir(root) \ No newline at end of file diff --git a/build-support/stage-release.sh b/build-support/stage-release.sh index c99028c..33fd03b 100755 --- a/build-support/stage-release.sh +++ b/build-support/stage-release.sh @@ -20,7 +20,7 @@ set -e -x -if [ $# -neq 2 ]; then +if [ "$#" -ne 2 ]; then echo "Usage: $0 \$DEST_PATH \$WORKFLOW_ID" exit 1 fi
