-
Notifications
You must be signed in to change notification settings - Fork 696
/
build.ps1
241 lines (187 loc) · 5.76 KB
/
build.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
240
241
<#
.SYNOPSIS
Builds NuGet client solutions and creates output artifacts.
.PARAMETER Configuration
Build configuration (debug by default)
.PARAMETER ReleaseLabel
Release label to use for package and assemblies versioning (zlocal by default)
.PARAMETER BuildNumber
Build number to use for package and assemblies versioning (auto-generated if not provided)
.PARAMETER Fast
Runs minimal incremental build. Skips end-to-end packaging step.
.PARAMETER CI
Indicates the build script is invoked from CI
.PARAMETER PackageEndToEnd
Indicates whether to create the end to end package.
.PARAMETER SkipDelaySigning
Indicates whether to skip strong name signing. By default assemblies will be delay signed and require strong name validation exclusions.
.EXAMPLE
.\build.ps1
To run full clean build, e.g after switching branches
.EXAMPLE
.\build.ps1 -f
Fast incremental build
.EXAMPLE
.\build.ps1 -v -ea Stop
To troubleshoot build issues
#>
[CmdletBinding()]
param (
[ValidateSet('debug', 'release')]
[Alias('c')]
[string]$Configuration,
[ValidatePattern('^(beta|final|preview|rc|release|rtm|xprivate|zlocal)([0-9]*)$')]
[Alias('l')]
[string]$ReleaseLabel = 'zlocal',
[Alias('n')]
[int]$BuildNumber,
[Alias('su')]
[switch]$SkipUnitTest,
[Alias('f')]
[switch]$Fast,
[switch]$CI,
[switch]$PackageEndToEnd,
[switch]$SkipDelaySigning,
[switch]$Binlog,
[switch]$IncludeApex
)
. "$PSScriptRoot\build\common.ps1"
If (-Not $SkipDelaySigning)
{
& "$PSScriptRoot\scripts\utils\DisableStrongNameVerification.ps1" -skipNoOpMessage
}
if (-not $Configuration) {
$Configuration = switch ($CI.IsPresent) {
$True { 'Release' } # CI build is Release by default
$False { 'Debug' } # Local builds are Debug by default
}
}
Write-Host ("`r`n" * 3)
Trace-Log ('=' * 60)
$startTime = [DateTime]::UtcNow
Trace-Log "Build started at $startTime"
Test-BuildEnvironment -CI:$CI
$BuildErrors = @()
Invoke-BuildStep 'Cleaning artifacts' {
Clear-Artifacts
Clear-Nupkgs
} `
-skip:$Fast `
-ev +BuildErrors
if ($SkipUnitTest) {
$VSTarget = "BuildVS;Pack";
$VSMessage = "Running Build"
}
else {
$VSTarget = "RunVS";
$VSMessage = "Running Build, Pack, Core unit tests, and Unit tests";
}
$MSBuildExe = Get-MSBuildExe
Invoke-BuildStep 'Running Restore' {
# Restore
$restoreArgs = "build\build.proj", "/t:RestoreVS", "/p:Configuration=$Configuration", "/p:ReleaseLabel=$ReleaseLabel", "/p:IncludeApex=$IncludeApex", "/v:m", "/m"
if ($BuildNumber)
{
$restoreArgs += "/p:BuildNumber=$BuildNumber"
}
if ($Binlog)
{
$restoreArgs += "-bl:msbuild.restore.binlog"
}
Trace-Log ". `"$MSBuildExe`" $restoreArgs"
& $MSBuildExe @restoreArgs
if (-not $?)
{
Write-Error "Failed - Running Restore"
exit 1
}
} `
-ev +BuildErrors
Invoke-BuildStep $VSMessage {
$buildArgs = 'build\build.proj', "/t:$VSTarget", "/p:Configuration=$Configuration", "/p:ReleaseLabel=$ReleaseLabel", "/p:IncludeApex=$IncludeApex", '/v:m', '/m'
if ($BuildNumber)
{
$buildArgs += "/p:BuildNumber=$BuildNumber"
}
If ($SkipDelaySigning)
{
$buildArgs += "/p:SkipSigning=true"
}
if ($Binlog)
{
$buildArgs += "-bl:msbuild.build.binlog"
}
# Build and (If not $SkipUnitTest) Pack, Core unit tests, and Unit tests for VS
Trace-Log ". `"$MSBuildExe`" $buildArgs"
& $MSBuildExe @buildArgs
if (-not $?)
{
Write-Error "Failed - $VSMessage"
exit 1
}
} `
-ev +BuildErrors
Invoke-BuildStep 'Creating the EndToEnd test package' {
$msbuildArgs = "test\TestUtilities\CreateEndToEndTestPackage\CreateEndToEndTestPackage.proj", "/p:Configuration=$Configuration", "/restore:false", "/property:BuildProjectReferences=false"
if ($Binlog)
{
$restoreArgs += "-bl:msbuild.createendtoendtestpackage.binlog"
}
Trace-Log ". `"$MSBuildExe`" $msbuildArgs"
& $MSBuildExe @msbuildArgs
} `
-args $Configuration `
-skip:(-not $PackageEndToEnd) `
-ev +BuildErrors
Invoke-BuildStep 'Running Restore RTM' {
# Restore for VS
$restoreArgs = "build\build.proj", "/t:RestoreVS", "/p:Configuration=$Configuration", "/p:BuildRTM=true", "/p:ReleaseLabel=$ReleaseLabel", "/p:ExcludeTestProjects=true", "/v:m", "/m"
if ($BuildNumber)
{
$restoreArgs += "/p:BuildNumber=$BuildNumber"
}
if ($Binlog)
{
$restoreArgs += "-bl:msbuild.restore.binlog"
}
Trace-Log ". `"$MSBuildExe`" $restoreArgs"
& $MSBuildExe @restoreArgs
if (-not $?)
{
Write-Error "Restore failed!"
exit 1
}
} `
-skip:(-not $CI)`
-ev +BuildErrors
Invoke-BuildStep 'Packing RTM' {
# Build and (If not $SkipUnitTest) Pack, Core unit tests, and Unit tests for VS
$packArgs = "build\build.proj", "/t:BuildVS`;Pack", "/p:Configuration=$Configuration", "/p:BuildRTM=true", "/p:ReleaseLabel=$ReleaseLabel", "/p:ExcludeTestProjects=true", "/v:m", "/m"
if ($BuildNumber)
{
$packArgs += "/p:BuildNumber=$BuildNumber"
}
if ($Binlog)
{
$packArgs += "-bl:msbuild.pack.binlog"
}
Trace-Log ". `"$MSBuildExe`" $packArgs"
& $MSBuildExe @packArgs
if (-not $?)
{
Write-Error "Packing RTM build failed!"
exit 1
}
} `
-skip:(-not $CI)`
-ev +BuildErrors
## Calculating Build time
$endTime = [DateTime]::UtcNow
Trace-Log "Build #$BuildNumber ended at $endTime"
Trace-Log "Time elapsed $(Format-ElapsedTime ($endTime - $startTime))"
Trace-Log ('=' * 60)
if ($BuildErrors) {
$ErrorLines = $BuildErrors | %{ ">>> $($_.Exception.Message)" }
Write-Error "Build's completed with $($BuildErrors.Count) error(s):`r`n$($ErrorLines -join "`r`n")" -ErrorAction Stop
}
Write-Host ("`r`n" * 3)