-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.ps1
150 lines (128 loc) · 4.13 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
. ./BuildFunctions.ps1
$startTime =
$projectName = "BlazorMvc"
$base_dir = resolve-path .\
$source_dir = "$base_dir"
$unitTestProjectPath = "$source_dir\UnitTests"
$integrationTestProjectPath = "$source_dir\IntegrationTests"
$acceptanceTestProjectPath = "$source_dir\AcceptanceTests"
$projectPath = "$source_dir\Sample.WebAssemblyNet6"
$projectConfig = $env:BuildConfiguration
$framework = "net6.0"
$version = $env:BUILD_BUILDNUMBER
$verbosity = "minimal"
$build_dir = "$base_dir\build"
$test_dir = "$build_dir\test"
if ([string]::IsNullOrEmpty($version)) { $version = "1.0.0"}
if ([string]::IsNullOrEmpty($projectConfig)) {$projectConfig = "Release"}
Function Init {
& cmd.exe /c rd /S /Q build
md $build_dir > $null
exec {
& dotnet clean $source_dir\$projectName.sln -nologo -v $verbosity
}
exec {
& dotnet restore $source_dir\$projectName.sln -nologo --interactive -v $verbosity
}
Write-Output $projectConfig
Write-Output $version
}
Function Compile{
exec {
& dotnet build $source_dir\$projectName.sln -nologo --no-restore -v `
$verbosity -maxcpucount --configuration $projectConfig --no-incremental `
/p:TreatWarningsAsErrors="true" `
/p:Version=$version /p:Authors="Jeffrey Palermo" `
/p:Product="BlazorMvc"
}
}
Function UnitTests{
Push-Location -Path $unitTestProjectPath
try {
exec {
& dotnet test /p:CollectCoverage=true -nologo -v $verbosity --logger:trx `
--results-directory $test_dir\UnitTests --no-build `
--no-restore --configuration $projectConfig `
--collect:"XPlat Code Coverage"
}
}
finally {
Pop-Location
}
}
Function IntegrationTest{
Push-Location -Path $integrationTestProjectPath
try {
exec {
& dotnet test /p:CollectCoverage=true -nologo -v $verbosity --logger:trx `
--results-directory $test_dir\IntegrationTests --no-build `
--no-restore --configuration $projectConfig `
--collect:"XPlat Code Coverage"
}
}
finally {
Pop-Location
}
}
Function AcceptanceTest{
[Environment]::SetEnvironmentVariable("AppURL", "localhost:7025", "User")
$serverProcess = Start-Process dotnet.exe "run --project $source_dir\Sample.WebAssemblyNet6\Sample.WebAssemblyNet6.csproj --configuration $projectConfig -nologo --no-restore --no-build -v $verbosity" -PassThru
Start-Sleep 1 #let the server process spin up for 1 second
Push-Location -Path $acceptanceTestProjectPath
try {
exec {
& dotnet test /p:CollectCoverage=true -nologo -v $verbosity --logger:trx `
--results-directory $test_dir\AcceptanceTests --no-build `
--no-restore --configuration $projectConfig `
--collect:"XPlat Code Coverage"
}
}
finally {
Pop-Location
Stop-Process -id $serverProcess.Id
}
}
Function PackageDistributable {
exec{
& dotnet publish $projectPath -nologo --no-restore --no-build -v $verbosity --configuration $projectConfig
}
exec{
& dotnet-octo pack --id "$projectName" --version $version --basePath $projectPath\bin\$projectConfig\$framework\publish --outFolder $build_dir --overwrite
}
}
Function PackageAcceptanceTests {
# Use Debug configuration so full symbols are available to display better error messages in test failures
exec{
& dotnet publish $acceptanceTestProjectPath -nologo --no-restore -v $verbosity --configuration Debug
}
exec{
& dotnet-octo pack --id "$projectName.AcceptanceTests" --version $version --basePath $acceptanceTestProjectPath\bin\Debug\$framework\publish --outFolder $build_dir --overwrite
}
}
Function Package{
Write-Output "Packaging nuget packages"
dotnet tool install --global Octopus.DotNet.Cli | Write-Output $_ -ErrorAction SilentlyContinue #prevents red color is already installed
PackageDistributable
PackageAcceptanceTests
}
Function PrivateBuild{
$projectConfig = "Debug"
$sw = [Diagnostics.Stopwatch]::StartNew()
Init
Compile
UnitTests
IntegrationTest
AcceptanceTest
$sw.Stop()
write-host "BUILD SUCCEEDED - Build time: " $sw.Elapsed.ToString() -ForegroundColor Green
}
Function CIBuild{
$sw = [Diagnostics.Stopwatch]::StartNew()
Init
Compile
UnitTests
IntegrationTest
Package
$sw.Stop()
write-host "BUILD SUCCEEDED - Build time: " $sw.Elapsed.ToString() -ForegroundColor Green
}