This repository has been archived by the owner on Nov 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcondo.ps1
239 lines (178 loc) · 6.49 KB
/
condo.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#Requires -version 4
<#
.SYNOPSIS
Builds the project using the condo build system.
.DESCRIPTION
Uses condo to build the project(s) contained within the current repository. If condo is not already present, it will
be downloaded and restored using the provided URI or branch. If not URL or branch is provided, the latest release
version will be downloaded.
.PARAMETER Reset
Deletes the pre-existing locally restored copy of condo and its dependencies before redownloading and restoring.
.PARAMETER Local
Uses the current repository to restore condo and its dependencies. This is useful for locally testing customizations
to condo from its own repository.
.PARAMETER Uri
The URI from which to download and restore condo.
.PARAMETER Branch
The branch from which to download and restore condo from its default repository.
.PARAMETER Source
The file system path from which to restore condo and its dependencies from source. This is useful for locally testing
customizations to condo from a different repository.
.PARAMETER Verbosity
The verbosity used for messaging to the standard output from both condo and the underlying MSBuild system.
Acceptable values are: Quiet, Minimal, Normal, Detailed, and Diagnostic
.PARAMETER NoColor
Indicates that any messaging to the standard output should not be emitted using colors. This is useful for parsing
output by third party tools.
.PARAMETER Username
The username used to bootstrap access to secured package feeds.
.PARAMETER Password
The password used to bootstrap access to secured package feeds. For Visual Studio Team Services (VSTS) feeds, this
should be an access token with at least the Packaging (read) scope.
.PARAMETER MSBuildArgs
Contains any additional parameters that are not bound to one of the parameters above. These values will be passed
to the underlying MSBuild runtime. These values are automatically bound from all remaining arguments. Specifying
the parameter as a collection is not necessary. See examples for more information.
.EXAMPLE
condo -Uri https://github.com/automotivemastermind/condo/releases/2.0.0.zip
# use the specified uri to install condo (if it is not already installed)
.EXAMPLE
condo -Branch develop
# use the develop branch to install condo
.EXAMPLE
condo -Reset -Verbosity Detailed
# reset condo to latest release build and enable verbose logging
.EXAMPLE
condo /t:Publish /p:Configuration=Release
# pass a target and property to the msbuild runtime
.EXAMPLE
condo -Username [email protected] -Password B528BF58-8C1F-48AC-9D9D-737E5DFD2B77
# bootstrap secured feeds using the specified username and password
.INPUTS
None. Condo does not accept any inputs through a pipe.
.OUTPUTS
None. Condo does not emit any outputs through a pipe.
.NOTES
The underlying build system in use is Microsoft Build for .NET Core. Any parameters beyond those supported by this
cmdlet will be passed to the msbuild process for consideration.
.LINK
http://open.automotivemastermind.com/condo
#>
[CmdletBinding(DefaultParameterSetName='ByBranch')]
Param (
[Parameter()]
[Alias('r')]
[switch]
$Reset,
[Parameter()]
[Alias('l')]
[switch]
$Local,
[Parameter()]
[Alias('nc')]
[switch]
$NoColor,
[Parameter()]
[switch]
$SecureFeed,
[Parameter()]
[Alias('v')]
[ValidateSet('Quiet', 'Minimal', 'Normal', 'Detailed', 'Diagnostic')]
[string]
$Verbosity = 'Normal',
[Parameter(Mandatory, ParameterSetName='ByUri')]
[Alias('u')]
[string]
$Uri,
[Parameter(ParameterSetName='ByBranch')]
[Alias('b')]
[string]
$Branch = 'develop',
[Parameter(Mandatory, ParameterSetName='BySource')]
[Alias('s')]
[string]
$Source,
[Parameter(ValueFromRemainingArguments)]
[string[]]
$MSBuildArgs = @()
)
function Write-Message([string] $message, [System.ConsoleColor] $color) {
if ($NoColor) {
Write-Host $message
return
}
Write-Host -ForegroundColor $color $message
}
function Write-Failure([string] $message) {
Write-Message -Color Red -Message $message
}
function Write-Info([string] $message) {
Write-Message -Color Yellow -Message $message
}
function Get-File([string] $url, [string] $path, [int] $retries = 5) {
try {
Invoke-WebRequest $url -OutFile $path > $null
}
catch [System.Exception] {
Write-Failure "Unable to retrieve file: $url"
if ($retries -eq 0) {
$exception = $_.Exception
throw $exception
}
Write-Failure "Retrying in 10 seconds... attempts left: $retries"
Start-Sleep -Seconds 10
$retries--
}
}
# find the script path
$RootPath = $PSScriptRoot
$CondoRoot = "$HOME\.am\condo"
$SrcRoot = "$CondoRoot\.src"
$CondoScript = "$SrcRoot\src\AM.Condo\Scripts\condo.ps1"
if ($PSCmdlet.ParameterSetName -eq 'ByBranch') {
$Uri = "https://github.com/automotivemastermind/condo/archive/$Branch.zip"
}
if ($Reset.IsPresent -and (Test-Path $CondoRoot)) {
Write-Info 'Resetting condo build system...'
Remove-Item -Recurse -Force $CondoRoot > $null
}
if ($Local) {
$Source = $RootPath
}
if (!(Test-Path $SrcRoot)) {
Write-Info "Creating path for condo at $SrcRoot..."
New-Item $SrcRoot -ItemType Directory > $null
if ($Source -and (Test-Path $Source)) {
Write-Info "Using condo build system from $Source..."
Copy-Item -Recurse "$Source\*" $SrcRoot > $null
}
else {
Write-Info "Using condo build system from $Uri..."
$CondoTemp = Join-Path ([System.IO.Path]::GetTempPath()) $([System.IO.Path]::GetRandomFileName())
$CondoZip = Join-Path $CondoTemp 'condo.zip'
New-Item $CondoTemp -ItemType Directory > $null
Get-File -url $Uri -Path $CondoZip
$CondoExtract = Join-Path $CondoTemp 'extract'
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($CondoZip, $CondoExtract)
Push-Location "$CondoExtract\*" > $null
Copy-Item -Recurse * $SrcRoot > $null
Pop-Location > $null
if (Test-Path $CondoTemp) {
Remove-Item -Recurse -Force $CondoTemp -ErrorAction SilentlyContinue > $null
}
}
}
try {
# change to the root path
Push-Location $RootPath
$credential = $null
if ($SecureFeed.IsPresent) {
$credential = Get-Credential -Message "Secure NuGet Feed Credentials"
}
# execute the underlying script
& "$CondoScript" -Verbosity $Verbosity -Credential $credential -NoColor:$NoColor @MSBuildArgs
}
finally {
Pop-Location
}