forked from csgsolutions/Csg.Extensions.Testing.SqlLocalDb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
82 lines (73 loc) · 2.5 KB
/
build.ps1
File metadata and controls
82 lines (73 loc) · 2.5 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
#!/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,
[string]
$BuildNumber=""
)
$Solution = "$(Get-Item -Path *.sln | Select-Object -First 1)"
$OutputPackages = @(
".\src\Csg.Extensions.Testing.SqlLocalDb\Csg.Extensions.Testing.SqlLocalDb.csproj"
)
$TestProjects = @() #Get-Item -Path tests\**\*Tests.csproj | %{ $_.FullName }
Write-Host "=============================================================================="
Write-Host "The Build Script"
Write-Host "=============================================================================="
if ($BuildNumber) {
$BuildNumber = $BuildNumber.PadLeft(5, "0")
}
try {
. "$PSScriptRoot/bootstrap.ps1"
Get-BuildTools -Version $BuildToolsVersion | Out-Null
# RESTORE
Write-Host "Restoring Packages..." -ForegroundColor Magenta
dotnet restore $SOLUTION
if ($LASTEXITCODE -ne 0) {
throw "Package restore failed with exit code $LASTEXITCODE."
}
# BUILD SOLUTION
Write-Host "Performing build..." -ForegroundColor Magenta
dotnet build $SOLUTION --configuration $Configuration /p:BuildNumber=$BuildNumber
if ($LASTEXITCODE -ne 0) {
throw "Build failed with exit code $LASTEXITCODE."
}
# RUN TESTS
if ( !($NoTest.IsPresent) -and $TestProjects.Length -gt 0 ) {
Write-Host "Performing tests..." -ForegroundColor Magenta
foreach ($test_proj in $TestProjects) {
Write-Host "Testing $test_proj"
#Note: The --logger parameter is for specifically for mstest to make it output test results
dotnet test $test_proj --no-build --configuration $Configuration --logger "trx;logfilename=TEST-$(get-date -format yyyyMMddHHmmss).xml"
if ($LASTEXITCODE -ne 0) {
throw "Test failed with code $LASTEXITCODE"
}
}
}
# CREATE NUGET PACKAGES
if ( $OutputPackages.Length -gt 0 ) {
Write-Host "Packaging..." -ForegroundColor Magenta
foreach ($pack_proj in $OutputPackages){
Write-Host "Packing $pack_proj"
dotnet pack $pack_proj --no-build --configuration $Configuration /p:BuildNumber=$BuildNumber
if ($LASTEXITCODE -ne 0) {
throw "Pack 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
}