Skip to content

Commit a142d02

Browse files
committed
Fix the scripts for downloading GitHub Action artifacts (#485)
(cherry picked from commit 0e1ed3b)
1 parent 9124eb5 commit a142d02

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

build-support/download-release-artifacts.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# under the License.
1919
#
2020

21-
import sys, json, urllib.request, os, shutil, zipfile, tempfile
21+
import sys, requests, os, zipfile, tempfile
2222
from pathlib import Path
2323

2424
if len(sys.argv) != 3:
@@ -39,33 +39,36 @@
3939
dest_path = sys.argv[2]
4040

4141
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"))
42+
headers={'Accept': ACCEPT_HEADER, 'Authorization': 'Bearer ' + GITHUB_TOKEN}
43+
44+
with requests.get(workflow_run_url, headers=headers) as response:
45+
response.raise_for_status()
46+
data = response.json()
4647
for artifact in data['artifacts']:
4748
name = artifact['name']
4849
# Skip debug artifact
4950
if name.endswith("-Debug"):
5051
continue
52+
dest_dir = os.path.join(dest_path, name)
53+
if name.find("windows") >= 0 and os.path.exists(dest_dir + ".tar.gz"):
54+
print(f'Skip downloading {name} since {dest_dir}.tar.gz exists')
55+
continue
56+
if os.path.exists(dest_dir) and \
57+
(os.path.isfile(dest_dir) or len(os.listdir(dest_dir)) > 0):
58+
print(f'Skip downloading {name} since the directory exists')
59+
continue
5160
url = artifact['archive_download_url']
5261

5362
print('Downloading %s from %s' % (name, url))
54-
artifact_request = urllib.request.Request(url,
55-
headers={'Authorization': 'Bearer ' + GITHUB_TOKEN})
56-
with urllib.request.urlopen(artifact_request) as response:
63+
with requests.get(url, headers=headers, stream=True) as response:
5764
tmp_zip = tempfile.NamedTemporaryFile(delete=False)
5865
try:
59-
#
60-
shutil.copyfileobj(response, tmp_zip)
66+
for chunk in response.iter_content(chunk_size=8192):
67+
tmp_zip.write(chunk)
6168
tmp_zip.close()
6269

63-
dest_dir = os.path.join(dest_path, name)
6470
Path(dest_dir).mkdir(parents=True, exist_ok=True)
6571
with zipfile.ZipFile(tmp_zip.name, 'r') as z:
6672
z.extractall(dest_dir)
6773
finally:
6874
os.unlink(tmp_zip.name)
69-
70-
71-

build-support/stage-release.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,24 @@ build-support/generate-source-archive.sh $DEST_PATH
4040
build-support/download-release-artifacts.py $WORKFLOW_ID $DEST_PATH
4141

4242
pushd "$DEST_PATH"
43-
tar cvzf x64-windows-static.tar.gz x64-windows-static
44-
tar cvzf x86-windows-static.tar.gz x86-windows-static
45-
rm -r x64-windows-static x86-windows-static
46-
mv macos-arm64.zip macos-arm64
47-
mv macos-arm64/* .
48-
mv macos-x86_64.zip macos-x86_64
49-
mv macos-x86_64/* .
50-
rm -rf macos-x86_64/ macos-arm64/
43+
if [[ -d x64-windows-static.tar.gz ]]; then
44+
tar cvzf x64-windows-static.tar.gz x64-windows-static
45+
rm -rf x64-windows-static/
46+
fi
47+
if [[ -d x86-windows-static.tar.gz ]]; then
48+
tar cvzf x86-windows-static.tar.gz x86-windows-static
49+
rm -rf x86-windows-static/
50+
fi
51+
if [[ -d macos-arm64.zip ]]; then
52+
mv macos-arm64.zip macos-arm64
53+
mv macos-arm64/* .
54+
rm -rf macos-arm64
55+
fi
56+
if [[ -d macos-x86_64.zip ]]; then
57+
mv macos-x86_64.zip macos-x86_64
58+
mv macos-x86_64/* .
59+
rm -rf macos-x86_64/
60+
fi
5161
popd
5262

5363
# Sign all files

0 commit comments

Comments
 (0)