-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.ps1
More file actions
56 lines (46 loc) · 2.14 KB
/
Build.ps1
File metadata and controls
56 lines (46 loc) · 2.14 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
#Requires -Version 7.0
param(
[switch]$SkipTests
)
Begin {
$ErrorActionPreference = "stop"
}
Process {
function Exec([scriptblock]$Command) {
& $Command
if ($LASTEXITCODE -ne 0) {
throw ("An error occurred while executing command: {0}" -f $Command)
}
}
$workingDir = Join-Path $PSScriptRoot "src"
$outputDir = Join-Path $PSScriptRoot ".output"
$nupkgsPath = Join-Path $outputDir "*.nupkg"
try {
Push-Location $workingDir
Remove-Item $outputDir -Force -Recurse -ErrorAction SilentlyContinue
# Install GitVersion which is specified in the .config/dotnet-tools.json
# https://learn.microsoft.com/en-us/dotnet/core/tools/local-tools-how-to-use
# We install it as a local tool so developers don't have to install it globally
Exec { & dotnet tool restore }
# We use "SemVer" because that's the default behavior of the GitVersion.MsBuild targets
# https://github.com/GitTools/GitVersion/blob/5.12.0/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets#L55
$version = Exec { & dotnet dotnet-gitversion /output json /showvariable SemVer }
# Change the build number in Azure DevOps
Write-Host "##vso[build.updatebuildnumber]$version"
Exec { & dotnet clean -c Release }
Exec { & dotnet build -c Release /p:Version=$version }
if (-not $SkipTests) {
Exec { & dotnet test -c Release --no-build --results-directory "$outputDir" --no-restore --logger "trx" --logger "console;verbosity=detailed" --blame-hang-timeout 10m }
}
Exec { & dotnet pack -c Release --no-build --output "$outputDir" /p:Version=$version }
if (($null -ne $env:NUGET_SOURCE) -and ($null -ne $env:NUGET_API_KEY)) {
Exec { & dotnet nuget push "$nupkgsPath" -s $env:NUGET_SOURCE -k $env:NUGET_API_KEY --skip-duplicate }
}
elseif (($null -ne $env:NUGET_SOURCE) -and ($null -ne $env:VSS_NUGET_ACCESSTOKEN)) {
Exec { & dotnet nuget push "$nupkgsPath" -s $env:NUGET_SOURCE -k "az-api-key" --skip-duplicate }
}
}
finally {
Pop-Location
}
}