-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.ps1
82 lines (75 loc) · 2.5 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
param(
[Parameter(Mandatory=$true)]
[string]$stage
)
Set-StrictMode -Version Latest
$FormatEnumerationLimit = -1
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
trap {
"ERROR: $_" | Write-Host
($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1' | Write-Host
($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1' | Write-Host
Exit 1
}
function exec([ScriptBlock]$externalCommand, [string]$stderrPrefix='', [int[]]$successExitCodes=@(0)) {
$eap = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
try {
&$externalCommand 2>&1 | ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
"$stderrPrefix$_"
} else {
"$_"
}
}
if ($LASTEXITCODE -notin $successExitCodes) {
throw "$externalCommand failed with exit code $LASTEXITCODE"
}
} finally {
$ErrorActionPreference = $eap
}
}
function Invoke-StageDependencies {
exec {
dotnet tool restore
}
exec {
dotnet restore
}
}
function Invoke-StageBuild {
exec {
dotnet build --no-restore --configuration Release
}
}
function Invoke-StageTest {
# execute unit tests and gather code coverage statistics.
# see https://github.com/spekt/junit.testlogger/blob/master/docs/gitlab-recommendation.md
# see https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/VSTestIntegration.md
exec {
dotnet test `
--no-build `
--configuration Release `
--test-adapter-path . `
--logger 'junit;MethodFormat=Class;FailureBodyFormat=Verbose' `
--collect 'XPlat Code Coverage' `
--settings MailBounceDetector.Tests/coverlet.runsettings
}
# generate coverage report.
Get-ChildItem -Recurse TestResults.xml | ForEach-Object {
Push-Location $_.Directory
Write-Host "Running the unit tests in $($_.Name)..."
exec {
dotnet tool run reportgenerator `
"-reports:$(Resolve-Path */coverage.opencover.xml)" `
-targetdir:coverage-report
}
Compress-Archive `
-CompressionLevel Optimal `
-Path coverage-report/* `
-DestinationPath coverage-report.zip
Pop-Location
}
}
Invoke-Expression "Invoke-Stage$([System.Globalization.CultureInfo]::InvariantCulture.TextInfo.ToTitleCase($stage))"