-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.ps1
More file actions
260 lines (214 loc) · 7.33 KB
/
build.ps1
File metadata and controls
260 lines (214 loc) · 7.33 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# 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.
[CmdLetBinding()]
<#
.SYNOPSIS
Automation script for running build operations from the command line.
.DESCRIPTION
Provides automation of the following tasks:
* Clean: runs `dotnet clean`
* Build: runs `dotnet build` with several implicit steps
(clean, restore, inject version information).
* UnitTest: executes NUnit tests in projects named `*.UnitTests`, which
do not connect to a database.
.EXAMPLE
.\build-dms.ps1 build -Configuration Release -Version "2.0" -BuildCounter 45
Overrides the default build configuration (Debug) to build in release
mode with assembly version 2.0.45.
.EXAMPLE
.\build-dms.ps1 unittest
Output: test results displayed in the console and saved to XML files.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '', Justification = 'False positive')]
param(
# Command to execute, defaults to "Build".
[string]
[ValidateSet("Clean", "Build", "BuildAndPublish", "Package", "Push", "UnitTest")]
$Command = "Build",
# Assembly and package version number for the Data Management Service. The
# current package number is configured in the build automation tool and
# passed to this script.
[string]
$Version = "0.1",
# .NET project build configuration, defaults to "Debug". Options are: Debug, Release.
[string]
[ValidateSet("Debug", "Release")]
$Configuration = "Debug",
# Ed-Fi's official NuGet package feed for package download and distribution.
[string]
$EdFiNuGetFeed = "https://pkgs.dev.azure.com/ed-fi-alliance/Ed-Fi-Alliance-OSS/_packaging/EdFi/nuget/v3/index.json",
# API key for accessing the feed above. Only required with the Push
# command.
[string]
$NuGetApiKey,
# Full path of a package file to push to the NuGet feed. Optional, only
# applies with the Push command. If not set, then the script looks for a
# NuGet package corresponding to the provided $Version and $BuildCounter.
[string]
$PackageFile,
# Only required with local builds and testing.
[switch]
$IsLocalBuild
)
$solutionRoot = "$PSScriptRoot/src"
$csprojFolderName = "EdFi.AdminConsole.InstanceManagementWorker"
$defaultSolution = "$solutionRoot/EdFi.AdminConsole.InstanceManagement.sln"
$projectName = "Ed-Fi-Admin-Console-Instance-Management-Worker-Process"
$packageName = "Ed-Fi-Admin-Console-Instance-Management-Worker-Process"
$testResults = "$PSScriptRoot/TestResults"
$maintainers = "Ed-Fi Alliance, LLC and contributors"
Import-Module -Name "$PSScriptRoot/eng/build-helpers.psm1" -Force
function DotNetClean {
Invoke-Execute { dotnet clean $defaultSolution -c $Configuration --nologo -v minimal }
}
function Restore {
Invoke-Execute { dotnet restore $defaultSolution }
}
function AssemblyInfo {
Invoke-Execute {
$assembly_version = $Version
Invoke-RegenerateFile "$PSScriptRoot/Directory.Build.props" @"
<Project>
<!-- This file is generated by the build script. -->
<PropertyGroup>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<ErrorLog>results.sarif,version=2.1</ErrorLog>
<Product>Ed-Fi Admin Console Instance Management Worker Process</Product>
<Authors>$maintainers</Authors>
<Company>$maintainers</Company>
<Copyright>Copyright © ${(Get-Date).year)} Ed-Fi Alliance</Copyright>
<VersionPrefix>$assembly_version</VersionPrefix>
<VersionSuffix></VersionSuffix>
</PropertyGroup>
</Project>
"@
}
}
function Compile {
Invoke-Execute {
dotnet build $defaultSolution -c $Configuration --nologo --no-restore
}
}
function Publish {
Invoke-Execute {
$outputPath = "$solutionRoot/$csprojFolderName/publish"
dotnet publish $defaultSolution -c $Configuration /p:EnvironmentName=Production -o $outputPath --no-build --nologo
}
}
function RunDotNetPack {
param (
[string]
$PackageVersion,
[string]
$ProjectName,
[string]
$NuspecFileName
)
dotnet pack "$ProjectName.csproj" --no-build --no-restore --output "$PSScriptRoot" --configuration $Configuration
}
function Package {
Invoke-Execute {
$baseProjectFullName = "$solutionRoot/$csprojFolderName/$csprojFolderName"
RunDotNetPack -PackageVersion $Version -projectName $baseProjectFullName $baseProjectFullName
}
}
function Push {
param (
[string]
$PackageVersion = $Version
)
if (-not $NuGetApiKey) {
throw "Cannot push a NuGet package without providing an API key in the `NuGetApiKey` argument."
}
if (-not $PackageFile) {
$PackageFile = "$PSScriptRoot/EdFi.AdminConsole.InstanceManagementWorker.$Version.nupkg"
}
DotnetPush -PackageFileName $PackageFile
}
function DotnetPush {
param (
[string]
$PackageFileName
)
Write-Host "Pushing $PackageFileName to $EdFiNuGetFeed"
dotnet nuget push $PackageFileName --api-key $NuGetApiKey --source $EdFiNuGetFeed
}
function RunTests {
param (
# File search filter
[string]
$Filter
)
$testAssemblyPath = "$solutionRoot/$Filter/bin/$Configuration/"
$testAssemblies = Get-ChildItem -Path $testAssemblyPath -Filter "$Filter.dll" -Recurse
if ($testAssemblies.Length -eq 0) {
Write-Output "no test assemblies found in $testAssemblyPath"
}
$testAssemblies | ForEach-Object {
Write-Output "Executing: dotnet test $($_)"
Invoke-Execute {
dotnet test $_ `
--logger "trx;LogFileName=$($_).trx" `
--nologo
}
}
}
function UnitTests {
Invoke-Execute { RunTests -Filter "*.UnitTests" }
}
function Invoke-Build {
Invoke-Step { DotNetClean }
Invoke-Step { Restore }
Invoke-Step { Compile }
}
function Invoke-SetAssemblyInfo {
Write-Output "Setting Assembly Information"
Invoke-Step { AssemblyInfo }
}
function Invoke-BuildAndPublish {
Invoke-Build
Invoke-Step { Publish }
}
function Invoke-Clean {
Invoke-Step { DotNetClean }
}
function Invoke-TestExecution {
param (
[ValidateSet("UnitTests",
ErrorMessage = "Please specify a valid Test Type name from the list.",
IgnoreCase = $true)]
# File search filter
[string]
$Filter
)
switch ($Filter) {
UnitTests { Invoke-Step { UnitTests } }
Default { "Unknow Test Type" }
}
}
function Invoke-Package {
Invoke-Step { Package }
}
function Invoke-Push {
Invoke-Step { Push }
}
Invoke-Main {
if ($IsLocalBuild) {
$nugetExePath = Install-NugetCli
Set-Alias nuget $nugetExePath -Scope Global -Verbose
}
switch ($Command) {
Clean { Invoke-Clean }
Build { Invoke-Build }
BuildAndPublish {
Invoke-SetAssemblyInfo
Invoke-BuildAndPublish
}
Package { Invoke-Package }
Push { Invoke-Push }
UnitTest { Invoke-TestExecution UnitTests }
default { throw "Command '$Command' is not recognized" }
}
}