Skip to content

Commit 774c2b6

Browse files
authored
DownloadCargoBinaryFromGitHub: Find most recent release with assets (#410)
Currently, the `cargo-binstall` most recent release in the binstall repo does not actually have the binstall binary. This change allows the search to find the most recent release that has the expected binaries to handle the case when other releases might also be in release list that do not have the expected binaries. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
1 parent 976aba5 commit 774c2b6

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

Scripts/DownloadCargoBinaryFromGitHub/DownloadCargoBinaryFromGitHub.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,24 @@
4141
print("Failed to find a release.")
4242
exit(1)
4343

44+
linux_found, windows_found = False, False
45+
4446
# Download assets
45-
for asset in releases[0]['assets']:
46-
name = asset['name'].lower()
47-
if (("x86_64-pc-windows-msvc" in name or "x86_64-unknown-linux-gnu" in name)
48-
and asset['name'].endswith(('.zip', '.tar.gz', '.tgz'))):
49-
filepath = DOWNLOAD_DIR / asset['name']
50-
print(f"Downloading {asset['name']}...")
51-
with requests.get(asset['browser_download_url'], stream=True) as r:
52-
with filepath.open('wb') as f:
53-
for chunk in r.iter_content(chunk_size=8192):
54-
f.write(chunk)
47+
for release in releases:
48+
for asset in release['assets']:
49+
name = asset['name'].lower()
50+
if (("x86_64-pc-windows-msvc" in name or "x86_64-unknown-linux-gnu" in name)
51+
and asset['name'].endswith(('.zip', '.tar.gz', '.tgz'))):
52+
linux_found = linux_found or "x86_64-unknown-linux-gnu" in name
53+
windows_found = windows_found or "x86_64-pc-windows-msvc" in name
54+
filepath = DOWNLOAD_DIR / asset['name']
55+
print(f"Downloading {asset['name']}...")
56+
with requests.get(asset['browser_download_url'], stream=True) as r:
57+
with filepath.open('wb') as f:
58+
for chunk in r.iter_content(chunk_size=8192):
59+
f.write(chunk)
60+
if linux_found and windows_found:
61+
break
5562

5663
# Extract files
5764
for filename in DOWNLOAD_DIR.iterdir():

0 commit comments

Comments
 (0)