forked from xunit/xunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
206 lines (168 loc) · 8.83 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
param(
[string]$target = "test",
[string]$configuration = "Release",
[string]$buildAssemblyVersion = "",
[string]$buildSemanticVersion = ""
)
if ($PSScriptRoot -eq $null) {
write-host "This build script requires PowerShell 3 or later." -ForegroundColor Red
exit -1
}
$buildModuleFile = join-path $PSScriptRoot "tools\build\xunit-build-module.psm1"
if ((test-path $buildModuleFile) -eq $false) {
write-host "Could not find build module. Did you forget to 'git submodule update --init'?" -ForegroundColor Red
exit -1
}
Set-StrictMode -Version 2
Import-Module $buildModuleFile -Scope Local -Force -ArgumentList "4.1.0"
Set-Location $PSScriptRoot
$packageOutputFolder = (join-path (Get-Location) "artifacts\packages")
$parallelFlags = "-parallel all -maxthreads 16"
$nonparallelFlags = "-parallel collections -maxthreads 16"
$testOutputFolder = (join-path (Get-Location) "artifacts\test")
$binlogOutputFolder = (join-path (Get-Location) "artifacts\build")
$solutionFolder = Get-Location
$signClientVersion = "0.9.0"
$signClientFolder = (join-path (Get-Location) "packages\SignClient.$signClientVersion")
$signClientAppSettings = (join-path (Get-Location) "tools\SignClient\appsettings.json")
# Helper functions
function _xunit_x64([string]$command) {
_exec ("src\xunit.console\bin\" + $configuration + "\net452\win7-x86\xunit.console.exe " + $command)
}
function _xunit_x86([string]$command) {
_exec ("src\xunit.console\bin\" + $configuration + "_x86\net452\win7-x86\xunit.console.x86.exe " + $command)
}
function _xunit_netcore([string]$targetFramework, [string]$command) {
_exec ("dotnet src\xunit.console\bin\" + $configuration + "\" + $targetFramework + "\xunit.console.dll " + $command)
}
# Top-level targets
function __target_appveyor() {
__target_ci
__target__signpackages
__target__pushmyget
}
function __target_build() {
__target_restore
_build_step "Compiling binaries"
_msbuild "xunit.vs2017.sln" $configuration -binlogFile (join-path $binlogOutputFolder "build.binlog")
_msbuild "src\xunit.console\xunit.console.csproj" ($configuration + "_x86") -binlogFile (join-path $binlogOutputFolder "build_x86.binlog")
}
function __target_ci() {
$script:parallelFlags = "-parallel none -maxthreads 1"
$script:nonparallelFlags = "-parallel none -maxthreads 1"
__target__setversion
__target_test
__target__publish
__target__packages
}
function __target_packagerestore() {
__target_restore
}
function __target_packages() {
__target_build
__target__publish
__target__packages
}
function __target_register() {
__target_packages
__target__register
}
function __target_restore() {
_build_step "Restoring NuGet packages"
_dotnet "restore xunit.vs2017.sln"
}
function __target_test() {
__target_build
__target__test32
__target__test64
__target__testcore
}
# Dependent targets
function __target__packages() {
_build_step "Creating NuGet packages"
Get-ChildItem -Recurse -Filter *.nuspec | _nuget_pack -outputFolder $packageOutputFolder -configuration $configuration
}
function __target__publish() {
_build_step "Publishing projects for packaging"
_dotnet "publish src\xunit.console --configuration $configuration --framework netcoreapp1.0"
_dotnet "publish src\xunit.console --configuration $configuration --framework netcoreapp2.0"
_dotnet "publish src\xunit.runner.visualstudio --configuration $configuration --framework netcoreapp1.0"
}
function __target__pushmyget() {
_build_step "Pushing packages to MyGet"
if ($env:MyGetApiKey -eq $null) {
Write-Host -ForegroundColor Yellow "Skipping MyGet push because environment variable 'MyGetApiKey' is not set."
Write-Host ""
} else {
Get-ChildItem -Filter *.nupkg $packageOutputFolder | _nuget_push -source https://www.myget.org/F/xunit/api/v2/package -apiKey $env:MyGetApiKey
}
}
function __target__register() {
_download_nuget
_build_step "Registering dotnet-test to NuGet package cache"
$nugetCachePath = Join-Path (Join-Path $env:HOME ".nuget") "packages"
$packageInstallFolder = Join-Path (Join-Path $nugetCachePath "dotnet-xunit") "99.99.99-dev"
if (Test-Path $packageInstallFolder) {
Remove-Item $packageInstallFolder -Recurse -Force -ErrorAction SilentlyContinue
}
_exec ('& "' + $nugetExe + '" add artifacts\packages\dotnet-xunit.99.99.99-dev.nupkg -NonInteractive -Expand -Source "' + $nugetCachePath + '"')
}
function __target__setversion() {
if ($buildAssemblyVersion -ne "") {
_build_step ("Setting assembly version: '" + $buildAssemblyVersion + "'")
Get-ChildItem -Recurse -Filter GlobalAssemblyInfo.cs | _replace -match '\("99\.99\.99\.0"\)' -replacement ('("' + $buildAssemblyVersion + '")')
}
if ($buildSemanticVersion -ne "") {
_build_step ("Setting semantic version: '" + $buildSemanticVersion + "'")
Get-ChildItem -Recurse -Filter GlobalAssemblyInfo.cs | _replace -match '\("99\.99\.99-dev"\)' -replacement ('("' + $buildSemanticVersion + '")')
Get-ChildItem -Recurse -Filter *.nuspec | _replace -match '99\.99\.99-dev' -replacement $buildSemanticVersion
}
}
function __target__signpackages() {
if ($env:SignClientSecret -ne $null) {
if ((test-path $signClientFolder) -eq $false) {
_build_step ("Downloading SignClient " + $signClientVersion)
_exec ('& "' + $nugetExe + '" install SignClient -version ' + $signClientVersion + ' -SolutionDir "' + $solutionFolder + '" -Verbosity quiet -NonInteractive')
}
_build_step "Signing NuGet packages"
$appPath = (join-path $signClientFolder "tools\netcoreapp2.0\SignClient.dll")
$nupgks = Get-ChildItem (join-path $packageOutputFolder "*.nupkg") | ForEach-Object { $_.FullName }
foreach ($nupkg in $nupgks) {
$cmd = '& dotnet "' + $appPath + '" sign -c "' + $signClientAppSettings + '" -r ' + $env:SignClientUser + ' -s ' + $env:SignClientSecret + ' -n "xUnit.net" -d "xUnit.net" -u "https://github.com/xunit/xunit" -i "' + $nupkg + '"'
$msg = $cmd.Replace($env:SignClientSecret, '[Redacted]')
$msg = $msg.Replace($env:SignClientUser, '[Redacted]')
_exec $cmd $msg
}
}
}
function __target__test32() {
_build_step "Running tests: 32-bit .NET 4.x"
$v2_assemblies = [System.String]::Join(" ", (Get-ChildItem -Recurse -Include test.xunit.*.dll | Where-Object { $_.FullName -match "bin\\" + $configuration + "\\net452" } | ForEach-Object { $_.FullName }))
_xunit_x86 ("test\test.xunit1\bin\" + $configuration + "\net40\test.xunit1.dll -xml artifacts\test\v1-x86.xml -html artifacts\test\v1-x86.html " + $nonparallelFlags)
_xunit_x86 ($v2_assemblies + " -xml artifacts\test\v2-x86.xml -html artifacts\test\v2-x86.html -appdomains denied -serialize " + $parallelFlags)
}
function __target__test64() {
_build_step "Running tests: 64-bit .NET 4.x"
$v2_assemblies = [System.String]::Join(" ", (Get-ChildItem -Recurse -Include test.xunit.*.dll | Where-Object { $_.FullName -match "bin\\" + $configuration + "\\net452" } | ForEach-Object { $_.FullName }))
_xunit_x64 ("test\test.xunit1\bin\" + $configuration + "\net40\test.xunit1.dll -xml artifacts\test\v1-x64.xml -html artifacts\test\v1-x64.html " + $nonparallelFlags)
_xunit_x64 ($v2_assemblies + " -xml artifacts\test\v2-x64.xml -html artifacts\test\v2-x64.html -appdomains denied -serialize " + $parallelFlags)
}
function __target__testcore() {
_build_step "Running tests: .NET Core 2.0"
$netcore_assemblies = [System.String]::Join(" ", (Get-ChildItem -Recurse -Include test.xunit.*.dll | Where-Object { $_.FullName -match "bin\\" + $configuration + "\\netcoreapp2.0" } | ForEach-Object { $_.FullName }))
_xunit_netcore "netcoreapp2.0" ($netcore_assemblies + " -xml artifacts\test\v2-netcore.xml -html artifacts\test\v2-netcore.html -serialize " + $nonparallelFlags)
}
# Dispatch
$targetFunction = (Get-ChildItem ("Function:__target_" + $target.ToLowerInvariant()) -ErrorAction SilentlyContinue)
if ($targetFunction -eq $null) {
_fatal "Unknown target '$target'"
}
_build_step "Performing pre-build verifications"
_require dotnet "Could not find 'dotnet'. Please ensure .NET CLI Tooling is installed."
_verify_dotnetsdk_version "2.0.0"
_require msbuild "Could not find 'msbuild'. Please ensure MSBUILD.EXE v15 is on the path."
_verify_msbuild_version "15.3.0"
_mkdir $packageOutputFolder
_mkdir $testOutputFolder
_mkdir $binlogOutputFolder
& $targetFunction