Skip to content

Commit 7f1cbf4

Browse files
committed
Fix release workflow and script (#404)
(cherry picked from commit 36b154e)
1 parent 64e6085 commit 7f1cbf4

2 files changed

Lines changed: 33 additions & 30 deletions

File tree

build-support/download-release-artifacts.py

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919
#
20-
21-
import sys, json, urllib.request, os, shutil, zipfile, tempfile
20+
import sys
21+
import requests
22+
import os
23+
import shutil
24+
import zipfile
25+
import tempfile
2226
from pathlib import Path
2327

2428
if len(sys.argv) != 3:
@@ -39,36 +43,35 @@
3943
dest_path = sys.argv[2]
4044

4145
workflow_run_url = LIST_URL % workflow_run_id
42-
request = urllib.request.Request(workflow_run_url,
43-
headers={'Accept': ACCEPT_HEADER, 'Authorization': 'Bearer ' + GITHUB_TOKEN})
44-
with urllib.request.urlopen(request) as response:
45-
data = json.loads(response.read().decode("utf-8"))
46-
for artifact in data['artifacts']:
47-
name = artifact['name']
48-
url = artifact['archive_download_url']
46+
headers = {'Accept': ACCEPT_HEADER, 'Authorization': f'Bearer {GITHUB_TOKEN}'}
4947

50-
print('Downloading %s from %s' % (name, url))
51-
artifact_request = urllib.request.Request(url,
52-
headers={'Authorization': 'Bearer ' + GITHUB_TOKEN})
53-
with urllib.request.urlopen(artifact_request) as response:
54-
tmp_zip = tempfile.NamedTemporaryFile(delete=False)
55-
try:
56-
#
57-
shutil.copyfileobj(response, tmp_zip)
58-
tmp_zip.close()
48+
response = requests.get(workflow_run_url, headers=headers)
49+
response.raise_for_status()
5950

60-
dest_dir = os.path.join(dest_path, name)
61-
Path(dest_dir).mkdir(parents=True, exist_ok=True)
62-
with zipfile.ZipFile(tmp_zip.name, 'r') as z:
63-
z.extractall(dest_dir)
64-
finally:
65-
os.unlink(tmp_zip.name)
51+
data = response.json()
52+
for artifact in data['artifacts']:
53+
name = artifact['name']
54+
url = artifact['archive_download_url']
6655

67-
for root, dirs, files in os.walk(dest_path, topdown=False):
68-
for name in files:
69-
shutil.move(os.path.join(root, name), dest_path)
70-
if not os.listdir(root):
71-
os.rmdir(root)
56+
print(f'Downloading {name} from {url}')
57+
artifact_response = requests.get(url, headers=headers, stream=True)
58+
artifact_response.raise_for_status()
7259

60+
with tempfile.NamedTemporaryFile(delete=False) as tmp_zip:
61+
for chunk in artifact_response.iter_content(chunk_size=8192):
62+
tmp_zip.write(chunk)
63+
tmp_zip_path = tmp_zip.name
7364

65+
try:
66+
dest_dir = os.path.join(dest_path, name)
67+
Path(dest_dir).mkdir(parents=True, exist_ok=True)
68+
with zipfile.ZipFile(tmp_zip_path, 'r') as z:
69+
z.extractall(dest_dir)
70+
finally:
71+
os.unlink(tmp_zip_path)
7472

73+
for root, dirs, files in os.walk(dest_path, topdown=False):
74+
for name in files:
75+
shutil.move(os.path.join(root, name), dest_path)
76+
if not os.listdir(root):
77+
os.rmdir(root)

build-support/stage-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
set -e -x
2222

23-
if [ $# -neq 2 ]; then
23+
if [ "$#" -ne 2 ]; then
2424
echo "Usage: $0 \$DEST_PATH \$WORKFLOW_ID"
2525
exit 1
2626
fi

0 commit comments

Comments
 (0)