-
Notifications
You must be signed in to change notification settings - Fork 730
/
install_cli_nightly.ps1
56 lines (48 loc) · 1.76 KB
/
install_cli_nightly.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
[cmdletbinding()]
param(
[string]$RunId,
[string]$Branch,
[string]$Repo,
[string]$BinaryPath
)
$ErrorActionPreference="Stop"
if ((Get-Command "gh" -ErrorAction SilentlyContinue) -eq $null) {
throw "Please install the GitHub CLI: https://cli.github.com/"
}
$arch = $env:PROCESSOR_ARCHITECTURE.ToLowerInvariant()
switch ($arch) {
{ ($_ -eq "x64") } { $arch = "x64" }
{ ($_ -eq "amd64") } { $arch = "x64" }
{ $_ -eq "arm64" } { $arch = "arm64" }
default { throw "Unsupported architecture '$arch'" }
}
$platform = [System.Environment]::OSVersion.Platform.ToString().ToLowerInvariant()
switch ($platform) {
{ ($_ -eq "win32nt") } { $platform = "win" }
default { throw "Unsupported platform '$platform'" }
}
# Fetch
if (!$BinaryPath) {
# Default to ~/.azure/bin
$BinaryPath = [System.IO.Path]::combine($HOME, ".azure", "bin")
}
if (!$Repo) {
$Repo = "Azure/bicep"
}
if (!$Branch) {
$Branch = "main"
}
if (!$RunId) {
$RunId = & gh run list -R $Repo --branch $Branch --workflow build --status success -L 1 --json databaseId -q ".[0].databaseId"; if(!$?) { throw }
}
$tmpDir = [System.IO.Path]::combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())
& gh run download -R $Repo $RunId -n "bicep-release-$platform-$arch" --dir $tmpDir; if(!$?) { throw }
# Install
$bicepPath = [System.IO.Path]::combine($BinaryPath, "bicep.exe")
New-Item -ItemType Directory -Force -Path $BinaryPath | Out-Null
Move-Item -Path "$tmpDir/bicep.exe" -Destination $bicepPath -Force
$versionStdout = & $bicepPath --version; if(!$?) { throw }
$version = $versionStdout -replace '^.* ([0-9]*\.[0-9]*\.[0-9]*) .*$', '$1'
echo "Installed Bicep $version from https://github.com/$Repo/actions/runs/$RunId to $bicepPath"
# Cleanup
Remove-Item $tmpDir -Recurse