-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.ps1
76 lines (61 loc) · 1.9 KB
/
bootstrap.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# From https://github.com/aspnet/Security/blob/dev/run.ps1
function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
if ($RemotePath -notlike 'http*') {
Copy-Item $RemotePath $LocalPath
return
}
$retries = 10
while ($retries -gt 0) {
$retries -= 1
try {
Invoke-WebRequest -UseBasicParsing -Uri $RemotePath -OutFile $LocalPath
return $LocalPath
}
catch {
Write-Verbose "Request failed. $retries retries remaining"
}
}
Write-Error "Download failed: '$RemotePath'."
}
# Inspired by from https://github.com/aspnet/Security/blob/dev/run.ps1
function Expand-ZipFile(
[Parameter(ValueFromPipeline)]
[string]$SourceFile,
[string]$DestinationPath
) {
if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) {
Expand-Archive -Path $SourceFile -DestinationPath $DestinationPath -Force
}
else {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($SourceFile, $DestinationPath)
}
}
function Get-BuildTools(
[string]$Version,
[switch]$NoSetEnvironment
){
Write-Host "Initializing build tools..." -NoNewline
if ($env:CI_BUILDTOOLS_PATH) {
$remotePath = "$($env:CI_BUILDTOOLS_PATH)/BuildTools-$Version.zip"
} else {
$remotePath = "https://csgstorpub.blob.core.windows.net/buildtools/BuildTools-$Version.zip"
}
$localPath = ".\obj\BuildTools-$Version"
if ( !(Test-Path .\obj)){
mkdir .\obj
}
if ( !(Test-Path $localPath) ){
Get-RemoteFile $remotePath ".\obj\BuildTools-$Version.zip" | Expand-ZipFile -DestinationPath $localPath
}
if ( !(Test-Path $localPath) ){
throw "Build tools failed to download"
}
$absolutePath = (Resolve-Path $localPath).Path
if (!($NoSetEnvironment.IsPresent)) {
$env:CI_BUILDTOOLS = $absolutePath
}
Import-Module "$absolutePath\BuildTools.psd1"
Write-Host "Done`r`n"
return $absolutePath
}