forked from csgsolutions/Csg.ListQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
119 lines (100 loc) · 3.75 KB
/
build.ps1
File metadata and controls
119 lines (100 loc) · 3.75 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
#!/usr/bin/env powershell
#requires -version 4
#
# CSG Build Script
# Copyright 2017 Cornerstone Solutions Group
Param(
[alias("c")][string]
$Configuration = "Release",
[string]
$BuildToolsVersion = "1.0-latest",
[switch]
$NoTest,
[switch]
$NoPackage,
[string]
$PullRequestNumber="",
[string]
$TestLogger = "trx;logfilename=TEST-$(get-date -format yyyyMMddHHmmss).trx"
)
. "$PSScriptRoot/bootstrap.ps1"
$Solution = "$(Get-Item -Path *.sln | Select-Object -First 1)"
$PackageProjects = @(
".\src\Csg.ListQuery\Csg.ListQuery.csproj",
".\src\Csg.ListQuery.Sql\Csg.ListQuery.Sql.csproj",
".\src\Csg.ListQuery.Server.Abstractions\Csg.ListQuery.Server.Abstractions.csproj",
".\src\Csg.ListQuery.Client.Abstractions\Csg.ListQuery.Client.Abstractions.csproj",
".\src\Csg.ListQuery.AspNetCore\Csg.ListQuery.AspNetCore.csproj"
)
$PublishProjects = @(
#".\src\Web\Web.csproj"
)
$TestProjects = Get-Item -Path tests\**\*Tests.csproj | %{ $_.FullName }
$SkipPackage = $NoPackage.IsPresent
if ($PullRequestNumber) {
Write-Host "Building for a pull request (#$PullRequestNumber), skipping packaging." -ForegroundColor Yellow
$SkipPackage = $true
}
Write-Host "==============================================================================" -ForegroundColor DarkYellow
Write-Host "The Build Script for Csg.ListQuery"
Write-Host "==============================================================================" -ForegroundColor DarkYellow
Write-Host "Build Tools:`t$BuildToolsVersion"
Write-Host "Solution:`t$Solution"
Write-Host "Skip Tests:`t$NoTest"
Write-Host "Pull Req:`t$PullRequestNumber"
Write-Host "==============================================================================" -ForegroundColor DarkYellow
try {
Get-BuildTools -Version $BuildToolsVersion | Out-Null
# Uncomment if you need to use msbuild commands in this file
#$msbuild = Find-MSBuild
Write-Host "Restoring Packages..." -ForegroundColor Magenta
dotnet restore $SOLUTION -v m
# Comment above and uncomment below if you need to use msbuild directly (if you have sdk and legacy projects)
# & $msbuild /t:Restore $SOLUTION
if ($LASTEXITCODE -ne 0) {
throw "Package restore failed with exit code $LASTEXITCODE."
}
Write-Host "Performing build..." -ForegroundColor Magenta
dotnet build $SOLUTION --configuration $Configuration -v m
if ($LASTEXITCODE -ne 0) {
throw "Build failed with exit code $LASTEXITCODE."
}
if ( !($NoTest.IsPresent) -and $TestProjects.Length -gt 0 ) {
Write-Host "Performing tests..." -ForegroundColor Magenta
foreach ($test_proj in $TestProjects) {
Write-Host "Testing $test_proj"
dotnet test $test_proj --no-build --configuration $Configuration --logger $TestLogger
if ($LASTEXITCODE -ne 0) {
throw "Test failed with code $LASTEXITCODE"
}
}
}
if ( !($SkipPackage) -and $PackageProjects.Length -gt 0 ) {
Write-Host "Packaging..." -ForegroundColor Magenta
foreach ($pack_proj in $PackageProjects){
Write-Host "Packing $pack_proj"
dotnet pack $pack_proj --no-build --configuration $Configuration
if ($LASTEXITCODE -ne 0) {
throw "Pack failed with code $result"
}
}
}
if ( !($SkipPackage) -and $PublishProjects.Length -gt 0 ) {
Write-Host "Publishing..." -ForegroundColor Magenta
foreach ($pub_proj in $PublishProjects){
Write-Host "Publishing $pack_proj"
dotnet publish $pub_proj --no-build --no-restore --configuration $Configuration
if ($LASTEXITCODE -ne 0) {
throw "Publish failed with code $result"
}
}
}
Write-Host "All Done. This build is great! (as far as I can tell)" -ForegroundColor Green
exit 0
} catch {
Write-Host "ERROR: An error occurred and the build was aborted." -ForegroundColor White -BackgroundColor Red
Write-Error $_
exit 3
} finally {
Remove-Module 'BuildTools' -ErrorAction Ignore
}