-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.ps1
245 lines (202 loc) · 7.27 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
242
243
244
245
# SPDX-License-Identifier: Apache-2.0
# Licensed to the Ed-Fi Alliance under one or more agreements.
# The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
# See the LICENSE and NOTICES files in the project root for more information.
<#
.SYNOPSIS
Automation script for running build operations from the command line.
.DESCRIPTION
Provides automation of the following tasks:
* Build: runs `dotnet build` with several implicit steps
(clean, restore, inject version information).
* Publish: creates the publish files.
* CreateZip: adds published files to a Zip file.
* UnitTest: runs the unit tests.
* IntegrationTest: runs the Integration tests.
.EXAMPLE
.\build.ps1 build -Configuration Release -Version "2.0.0" -BuildCounter 45
Overrides the default build configuration (Debug) to build in release
mode with assembly version 2.0.0.45.
.EXAMPLE
.\build.ps1 CreateZip
The files published in zip archives.
.EXAMPLE
.\build.ps1 unittest
Output: test results displayed in the console and saved to XML files.
.EXAMPLE
.\build.ps1 integrationtest
Output: test results displayed in the console and saved to XML files.
#>
[CmdLetBinding()]
param(
# Command to execute, defaults to "Build".
[string]
[ValidateSet("DotnetClean", "Build", "Publish", "CreateZip", "UnitTest", "IntegrationTest")]
$Command = "Build",
[switch] $SelfContained,
# Assembly and package version number, defaults 4.0.0
[string]
$Version = "4.0.0",
# Build counter from the automation tool.
[string]
$BuildCounter = "1",
# .NET project build configuration, defaults to "Debug". Options are: Debug, Release.
[string]
[ValidateSet("Debug", "Release")]
$Configuration = "Debug"
)
$Env:MSBUILDDISABLENODEREUSE = "1"
#$solution = "Application\Ed-Fi-ODS-Tools.sln"
$solutionRoot = "$PSScriptRoot/src"
$maintainers = "Ed-Fi Alliance, LLC and contributors"
Import-Module -Name ("$PSScriptRoot/eng/build-helpers.psm1") -Force
$publishOutputPath = "$solutionRoot/../publish"
$publishFddDirectoryName = "EdFi.AnalyticsMiddleTier"
$publishScdDirectoryName = "EdFi.AnalyticsMiddleTier-win10.x64"
$publishFddOutputDirectory = "$publishOutputPath/$publishFddDirectoryName"
$publishScdOutputDirectory = "$publishOutputPath/$publishScdDirectoryName"
$publishFddZipFile = "$publishFddDirectoryName-$Version.zip"
$publishScdZipFile = "$publishScdDirectoryName-$Version.zip"
$testProjectName = "EdFi.AnalyticsMiddleTier.Tests"
function DotnetClean {
Invoke-Execute { dotnet clean $solutionRoot -c $Configuration --nologo -v minimal }
}
function CleanPublishFddOutputDirectory {
if (Test-Path -Path $publishFddOutputDirectory) {
Remove-Item -Recurse ("$publishFddOutputDirectory/*.*")
}
if (Test-Path -Path ("$publishOutputPath/$publishFddZipFile")) {
Remove-Item -Recurse ("$publishOutputPath/$publishFddZipFile")
}
}
function CleanPublishScdOutputDirectory {
if (Test-Path -Path $publishScdOutputDirectory) {
Remove-Item -Recurse ("$publishScdOutputDirectory/*.*")
}
if (Test-Path -Path ("$publishOutputPath/$publishScdZipFile")) {
Remove-Item -Recurse ("$publishOutputPath/$publishScdZipFile")
}
}
function AssemblyInfo {
Invoke-Execute {
$assembly_version = "$Version.$BuildCounter"
$year = (Get-Date -Format yyyy)
Invoke-RegenerateFile ("$solutionRoot/Directory.Build.props") @"
<Project>
<!-- This file is generated by the build script. -->
<PropertyGroup>
<Product>Ed-Fi AMT</Product>
<Authors>$maintainers</Authors>
<Company>$maintainers</Company>
<Copyright>Copyright © $year Ed-Fi Alliance</Copyright>
<VersionPrefix>$assembly_version</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
"@
}
}
function Compile {
Invoke-Execute {
dotnet --info
dotnet build $solutionRoot -c $Configuration --nologo
}
}
function Publish {
Invoke-Execute {
$project = "$solutionRoot/EdFi.AnalyticsMiddleTier.Console"
if ($SelfContained) {
CleanPublishScdOutputDirectory
Write-Host "Self contained." -ForegroundColor Cyan
dotnet publish $project -c $Configuration /p:EnvironmentName=Production -o "$publishScdOutputDirectory" --self-contained -r win-x64 --nologo
}
else
{
CleanPublishFddOutputDirectory
Write-Host "Not self contained." -ForegroundColor Cyan
dotnet publish $project -c $Configuration /p:EnvironmentName=Production -o "$publishFddOutputDirectory" --no-self-contained --no-build --nologo
}
}
}
function CreateZip {
Invoke-Execute {
$fddPackDestination = ("$publishOutputPath/$publishFddZipFile")
$scdPackDestination = ("$publishOutputPath/$publishScdZipFile")
if(Test-Path $publishFddOutputDirectory){
if (Test-Path $fddPackDestination) {
Remove-Item $fddPackDestination
}
Compress-Archive -Path $publishFddOutputDirectory/* -DestinationPath $fddPackDestination
}
if(Test-Path $publishScdOutputDirectory){
if (Test-Path $scdPackDestination) {
Remove-Item $scdPackDestination
}
Compress-Archive -Path $publishScdOutputDirectory/* -DestinationPath $scdPackDestination
}
}
}
function RunTests {
param (
# File search filter
[string]
$Filter,
[string]
$Category
)
$testAssemblyPath = "$solutionRoot/$Filter/bin/$Configuration"
$testAssemblies = Get-ChildItem -Path $testAssemblyPath -Filter "$Filter.dll" -Recurse
if ($testAssemblies.Length -eq 0) {
Write-Host "no test assemblies found in $testAssemblyPath"
}
$testAssemblies | ForEach-Object {
Write-Host "Executing: dotnet test $($_)"
Invoke-Execute { dotnet test --filter Category=$Category $_ }
}
}
function UnitTests {
Invoke-Execute { RunTests -Filter $testProjectName -Category UnitTest}
}
function IntegrationTests {
Invoke-Execute { RunTests -Filter $testProjectName -Category IntegrationTest}
}
function Invoke-Build {
Write-Host "Building Version $Version" -ForegroundColor Cyan
Invoke-Step { DotnetClean }
Invoke-Step { AssemblyInfo }
Invoke-Step { Compile }
}
function Invoke-Publish {
Invoke-Build
Invoke-Step { Publish }
}
function Invoke-Clean {
Invoke-Step { DotnetClean }
}
function Invoke-PublishClean {
Invoke-Step { CleanPublishFddOutputDirectory }
Invoke-Step { CleanPublishScdOutputDirectory }
}
function Invoke-UnitTests {
Invoke-Step { UnitTests }
}
function Invoke-IntegrationTests {
Invoke-Step { IntegrationTests }
}
function Invoke-CreateZip {
Invoke-Step { CreateZip }
}
Invoke-Main {
switch ($Command) {
DotnetClean {
Invoke-Clean
Invoke-PublishClean
}
Build { Invoke-Build }
UnitTest { Invoke-UnitTests }
IntegrationTest { Invoke-IntegrationTests }
Publish { Invoke-Publish }
CreateZip { Invoke-CreateZip }
default { throw "Command '$Command' is not recognized" }
}
}