Skip to content

Commit 4e9b5aa

Browse files
authored
Add pipeline to cache cargo binstall (#318)
Adds a pipeline to cache cargo binstall. Adds `.tgz` (short for `.tar.gz`) support to the DownloadCargoBinaryFromGitHub.py script. Also fixes a logic error in the conditional that decides which assets to download. See successful pipeline run: https://dev.azure.com/projectmu/mu/_build/results?buildId=64211&view=logs&j=402df595-8a03-57d0-41e1-0654a1932349
1 parent ca9b6b4 commit 4e9b5aa

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## @file
2+
# Azure Pipeline to download Cargo Binstall and save it as a pipeline artifact that
3+
# can be accessed by other pipelines.
4+
#
5+
# Copyright (c) Microsoft Corporation. All rights reserved.
6+
# SPDX-License-Identifier: BSD-2-Clause-Patent
7+
##
8+
9+
schedules:
10+
# At 1:00 on Monday
11+
# https://crontab.guru/#0_1_*_*_1
12+
- cron: 0 1 * * 1
13+
branches:
14+
include:
15+
- main
16+
always: true
17+
18+
jobs:
19+
- job: Update_Cargo_Binstall
20+
displayName: Update Cargo Binstall
21+
22+
pool:
23+
vmImage: windows-latest
24+
25+
steps:
26+
- checkout: self
27+
clean: true
28+
fetchDepth: 1
29+
fetchTags: false
30+
31+
- script: pip install requests --upgrade
32+
displayName: Install and Upgrade pip Modules
33+
condition: succeeded()
34+
35+
- task: PythonScript@0
36+
displayName: Download and Stage Cargo Binstall
37+
env:
38+
BINARIES_DIR: "$(Build.BinariesDirectory)"
39+
BINARY_NAME: "cargo-binstall"
40+
DOWNLOAD_DIR: "$(Build.ArtifactStagingDirectory)"
41+
REPO_URL: "https://api.github.com/repos/cargo-bins/cargo-binstall/releases"
42+
inputs:
43+
scriptSource: filePath
44+
scriptPath: Scripts/DownloadCargoBinaryFromGitHub/DownloadCargoBinaryFromGitHub.py
45+
workingDirectory: $(Agent.BuildDirectory)
46+
condition: succeeded()
47+
48+
- task: PublishBuildArtifacts@1
49+
displayName: Publish Cargo Binstall
50+
retryCountOnTaskFailure: 3
51+
inputs:
52+
PathtoPublish: $(Build.BinariesDirectory)
53+
ArtifactName: Binaries
54+
condition: succeeded()

Scripts/DownloadCargoBinaryFromGitHub/DownloadCargoBinaryFromGitHub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
# Download assets
4545
for asset in releases[0]['assets']:
4646
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'))):
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'))):
4949
filepath = DOWNLOAD_DIR / asset['name']
5050
print(f"Downloading {asset['name']}...")
5151
with requests.get(asset['browser_download_url'], stream=True) as r:
@@ -61,7 +61,7 @@
6161
if filename.name.endswith('.zip'):
6262
with zipfile.ZipFile(filename, 'r') as zip_ref:
6363
zip_ref.extractall(extracted_dir)
64-
elif filename.name.endswith('.tar.gz'):
64+
elif filename.name.endswith(('.tar.gz', '.tgz')):
6565
with tarfile.open(filename, 'r:gz') as tar:
6666
tar.extractall(path=extracted_dir)
6767

0 commit comments

Comments
 (0)