-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-and-test.ps1
executable file
·47 lines (39 loc) · 1.18 KB
/
build-and-test.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
#!/usr/bin/pwsh
[CmdletBinding(PositionalBinding=$false)]
param (
[string]$configuration = "Debug",
[switch]$noTest
)
Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
function Fail([string]$message) {
throw $message
}
function Single([string]$pattern) {
$items = @(Get-Item $pattern)
if ($items.Length -ne 1) {
$itemsList = $items -Join "`n"
Fail "Expected single item, found`n$itemsList`n"
}
return $items[0]
}
try {
# build
$solution = Single "$PSScriptRoot/*.sln"
dotnet restore $solution || Fail "Failed to restore solution"
dotnet build $solution --configuration $configuration || Fail "Failed to build solution"
# test
if (-Not $noTest) {
dotnet test --no-restore --no-build --configuration $configuration || Fail "Error running tests."
}
# create package
dotnet pack --no-restore --no-build --configuration $configuration $solution || Fail "Error creating package."
$package = Single "$PSScriptRoot/artifacts/packages/$configuration/*.nupkg"
Write-Host "Package generated at '$package'"
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
exit 1
}