-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
200 lines (172 loc) · 6.22 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
. .\BuildFunctions.ps1
$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"
$mauiProjectPath = "$source_dir\UI\Maui"
$projectConfig = $env:BuildConfiguration
$framework = "net8.0"
$version = $env:BUILD_BUILDNUMBER
$verbosity = "minimal"
$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 = $projectName
if ([string]::IsNullOrEmpty($databaseName)) { $databaseName = $projectName}
$script:databaseServer = "(LocalDb)\MSSQLLocalDB"
if ([string]::IsNullOrEmpty($script:databaseServer)) { $script:databaseServer = "(LocalDb)\MSSQLLocalDB"}
$databaseScripts = "$source_dir\Database\scripts"
if ([string]::IsNullOrEmpty($version)) { $version = "1.0.0"}
if ([string]::IsNullOrEmpty($projectConfig)) {$projectConfig = "Release"}
Function Init {
& cmd.exe /c rd /S /Q build
mkdir $build_dir > $null
exec {
& dotnet clean $source_dir\exclude-maui.slnf -nologo -v $verbosity
}
exec {
& dotnet restore $source_dir\exclude-maui.slnf -nologo --interactive -v $verbosity
}
Write-Output $projectConfig
Write-Output $version
}
Function Compile{
exec {
& dotnet build $source_dir\exclude-maui.slnf -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 -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{
$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 -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 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 PackageScript {
exec{
& dotnet publish $uiProjectPath -nologo --no-restore --no-build -v $verbosity --configuration $projectConfig
}
exec{
& dotnet-octo pack --id "$projectName.Script" --version $version --basePath $uiProjectPath --include "*.ps1" --outFolder $build_dir --overwrite
}
}
Function PackageMaui {
$keystoreFilePath = [Environment]::GetEnvironmentVariable("keystoreFilepath","User")
$signingStorePass = [Environment]::GetEnvironmentVariable("signingStorePass","User")
$signingKeyPass = [Environment]::GetEnvironmentVariable("signingKeyPass","User")
Write-Output "keystoreFilepath: $keystoreFilePath"
exec{
& dotnet publish $mauiProjectPath -nologo --no-restore -v $verbosity -c Release -f net8.0-android -p:AndroidPackageFormat=aab -p:AndroidKeyStore=True -p:AndroidSigningKeyStore=$keystoreFilePath -p:AndroidSigningStorePass=OnionArch8 -p:AndroidSigningKeyAlias=release -p:AndroidSigningKeyPass=OnionArch8
}
exec{
& dotnet-octo pack --id "$projectName.Maui" --version $version --basePath $mauiProjectPath\bin\$projectConfig\net8.0-android\publish --include "*-Signed.aab" --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
PackageScript
# PackageMaui
}
Function PrivateBuild{
$projectConfig = "Debug"
[Environment]::SetEnvironmentVariable("containerAppURL", "localhost:7174", "User")
$sw = [Diagnostics.Stopwatch]::StartNew()
Init
Compile
UnitTests
MigrateDatabaseLocal
IntegrationTest
AcceptanceTest
$sw.Stop()
write-host "BUILD SUCCEEDED - Build time: " $sw.Elapsed.ToString() -ForegroundColor Green
}
Function CIBuild{
$sw = [Diagnostics.Stopwatch]::StartNew()
Init
Compile
UnitTests
MigrateDatabaseLocal
IntegrationTest
Package
$sw.Stop()
write-host "BUILD SUCCEEDED - Build time: " $sw.Elapsed.ToString() -ForegroundColor Green
}