-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.ps1
173 lines (149 loc) · 4.88 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
. .\BuildFunctions.ps1
$startTime =
$projectName = "ChurchBulletin"
$base_dir = resolve-path .\
$source_dir = "$base_dir\src"
$unitTestProjectPath = "$source_dir\UnitTests"
$integrationTestProjectPath = "$source_dir\IntegrationTests"
$acceptanceTestProjectPath = "$source_dir\AcceptanceTests"
$uiProjectPath = "$source_dir\UI\Server"
$databaseProjectPath = "$source_dir\Database"
$projectConfig = $env:BuildConfiguration
$framework = "net6.0"
$version = $env:Version
$verbosity = "m"
$build_dir = "$base_dir\build"
$test_dir = "$build_dir\test"
$aliaSql = "$source_dir\Database\scripts\AliaSql.exe"
$databaseAction = $env:DatabaseAction
if ([string]::IsNullOrEmpty($databaseAction)) { $databaseAction = "Rebuild"}
$databaseName = $env:DatabaseName
if ([string]::IsNullOrEmpty($databaseName)) { $databaseName = $projectName}
$script:databaseServer = $env:DatabaseServer
if ([string]::IsNullOrEmpty($script:databaseServer)) { $script:databaseServer = "(LocalDb)\MSSQLLocalDB"}
$databaseScripts = "$source_dir\Database\scripts"
if ([string]::IsNullOrEmpty($version)) { $version = "1.0.0.0"}
if ([string]::IsNullOrEmpty($projectConfig)) {$projectConfig = "Release"}
Function Init {
rm -r -fo $build_dir -ErrorAction Ignore
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="Programming with Palermo" `
/p:Product="Church Bulletin"
}
}
Function UnitTests{
Push-Location -Path $unitTestProjectPath
try {
exec {
& dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura -nologo -v $verbosity --logger:trx `
--results-directory $test_dir --no-build `
--no-restore --configuration $projectConfig `
--collect:"Code Coverage"
}
}
finally {
Pop-Location
}
}
Function IntegrationTest{
Push-Location -Path $integrationTestProjectPath
try {
exec {
& dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura -nologo -v $verbosity --logger:trx `
--results-directory $test_dir --no-build `
--no-restore --configuration $projectConfig `
--collect:"Code Coverage"
}
}
finally {
Pop-Location
}
}
Function AcceptanceTest{
$serverProcess = Start-Process dotnet.exe "run --project $source_dir\UI\Server\UI.Server.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 /p:CoverletOutputFormat=cobertura -nologo -v $verbosity --logger:trx `
--results-directory $test_dir --no-build `
--no-restore --configuration $projectConfig `
--collect:"Code Coverage"
}
}
finally {
Pop-Location
Stop-Process -id $serverProcess.Id
}
}
Function MigrateDatabaseLocal {
exec{
& $aliaSql $databaseAction $script:databaseServer $databaseName $databaseScripts
}
}
Function PackageUI {
exec{
& dotnet publish $uiProjectPath -nologo --no-restore --no-build -v $verbosity --configuration $projectConfig
}
exec{
& dotnet-octo pack --id "$projectName.UI" --version $version --basePath $uiProjectPath\bin\$projectConfig\$framework\publish --outFolder $build_dir --overwrite
}
}
Function PackageDatabase {
exec{
& dotnet-octo pack --id "$projectName.Database" --version $version --basePath $databaseProjectPath --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
PackageUI
PackageDatabase
PackageAcceptanceTests
}
Function PrivateBuild{
$projectConfig = "Debug"
$sw = [Diagnostics.Stopwatch]::StartNew()
Init
Compile
UnitTests
MigrateDatabaseLocal
IntegrationTest
AcceptanceTest
$sw.Stop()
write-host "Build time: " $sw.Elapsed.ToString()
}
Function CIBuild{
$sw = [Diagnostics.Stopwatch]::StartNew()
Init
Compile
UnitTests
MigrateDatabaseLocal
IntegrationTest
Package
$sw.Stop()
write-host "Build time: " $sw.Elapsed.ToString()
}