-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
87 lines (71 loc) · 2.25 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
83
84
85
86
87
param (
[string]$Output = "./artifacts",
[string]$CurrentBranch ='',
[bool]$OnlyBuild = $False
)
# Utils
function EnsureLastExitCode($message){
if ($LASTEXITCODE -ne 0) {
throw $message
}
}
# Parameters
"----------------------------------------"
"Output: $Output"
$Location = Get-Location
"Location: $Location"
"OnlyBuild: $OnlyBuild"
if ((Test-Path $output) -eq $True) {
"Clean: $Output"
Remove-Item -Recurse -Force $Output
}
# Git Information
if ($CurrentBranch -eq '') {
$CurrentBranch = git branch --show-current | Out-String
EnsureLastExitCode("git branch --show-current failed")
}
$CurrentBranch = $CurrentBranch.Trim()
"----------------------------------------"
"CurrentBranch: $CurrentBranch"
if ($CurrentBranch -eq '') {
Write-Error "Not branch or tag"
return
}
# Install tools
"----------------------------------------"
"Restoring dotnet tools"
dotnet tool restore
EnsureLastExitCode("Restore failed")
# Get GitVersion
"----------------------------------------"
"Getting GitVersion"
$Version = dotnet gitversion /output json /showvariable SemVer | Out-String -NoNewline
EnsureLastExitCode("Could not get SemVer from gitversion")
$Version = $Version.Trim()
"Git version: '$Version'"
"##vso[build.updatebuildnumber]$Version"
$PreReleaseTag = dotnet gitversion /output json /showvariable PreReleaseTag | Out-String -NoNewline
EnsureLastExitCode("Could not get PrReleaseTag from gitversion")
$PreReleaseTag = $PreReleaseTag.Trim()
$IsPreRelease = $PreReleaseTag -ne ''
"PreReleaseTag: $PreReleaseTag, IsPreRelease: $IsPreRelease"
# Build and test
"----------------------------------------"
"Build"
dotnet restore
dotnet build -c Release --no-restore
EnsureLastExitCode("dotnet build failed")
if ($OnlyBuild -eq $False) {
"----------------------------------------"
"Run tests"
dotnet test -c Release --logger trx -r $Output --no-restore --no-build
EnsureLastExitCode("dotnet test failed")
"----------------------------------------"
"Pack NuGet"
dotnet pack -c Release -o $Output -p:Version=$Version -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
EnsureLastExitCode("dotnet pack failed")
Set-Location $Location
}
"----------------------------------------"
"DONE"
Set-Location $Location