-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.ps1
86 lines (68 loc) · 3.04 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
Param(
[switch] $Release,
[string] $SigningCertThumbprint,
[string] $TimestampServer
)
$ErrorActionPreference = 'Stop'
# Options
$configuration = 'Release'
$artifactsDir = Join-Path (Resolve-Path .) 'artifacts'
$packagesDir = Join-Path $artifactsDir 'Packages'
$testResultsDir = Join-Path $artifactsDir 'Test results'
$logsDir = Join-Path $artifactsDir 'Logs'
# Detection
. $PSScriptRoot\build\Get-DetectedCiVersion.ps1
$versionInfo = Get-DetectedCiVersion -Release:$Release
Update-CiServerBuildName $versionInfo.ProductVersion
Write-Host "Building using version $($versionInfo.ProductVersion)"
$dotnetArgs = @(
'--configuration', $configuration
'/p:RepositoryCommit=' + $versionInfo.CommitHash
'/p:Version=' + $versionInfo.ProductVersion
'/p:PackageVersion=' + $versionInfo.PackageVersion
'/p:FileVersion=' + $versionInfo.FileVersion
'/p:ContinuousIntegrationBuild=' + ($env:CI -or $env:TF_BUILD)
)
# Build
dotnet build /bl:"$logsDir\build.binlog" @dotnetArgs
if ($LastExitCode) { exit 1 }
if ($SigningCertThumbprint) {
. build\SignTool.ps1
SignTool $SigningCertThumbprint $TimestampServer (
Get-ChildItem src\AmbientTasks\bin\$configuration -Recurse -Include AmbientTasks.dll)
}
# Pack
Remove-Item -Recurse -Force $packagesDir -ErrorAction Ignore
. build\ValidateMetadata.ps1
ValidateMetadata $versionInfo.ProductVersion -Release:$Release
dotnet pack --no-build --output $packagesDir /bl:"$logsDir\pack.binlog" @dotnetArgs
if ($LastExitCode) { exit 1 }
if ($SigningCertThumbprint) {
# Waiting for 'dotnet sign' to become available (https://github.com/NuGet/Home/issues/7939)
$nuget = 'tools\nuget.exe'
if (-not (Test-Path $nuget)) {
New-Item -ItemType Directory -Force -Path tools
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $nuget
}
# Workaround for https://github.com/NuGet/Home/issues/10446
foreach ($extension in 'nupkg', 'snupkg') {
& $nuget sign $packagesDir\*.$extension -CertificateFingerprint $SigningCertThumbprint -Timestamper $TimestampServer
}
}
# Test
Remove-Item -Recurse -Force $testResultsDir -ErrorAction Ignore
dotnet test --no-build --configuration $configuration --logger trx --results-directory $testResultsDir /p:AltCover=true /p:AltCoverXmlReport="$testResultsDir\coverage.xml" /p:AltCoverAssemblyExcludeFilter=AmbientTasks.Tests /p:AltCoverVerbosity=Warning /bl:"$logsDir\test.binlog"
if ($LastExitCode) { $testsFailed = true }
if ($env:CODECOV_TOKEN) {
dotnet tool install Codecov.Tool --tool-path tools
$codecov = 'tools\codecov'
foreach ($coverageFile in Get-ChildItem "$testResultsDir\coverage.*.xml") {
$tfm = $coverageFile.Name.Substring(
'coverage.'.Length,
$coverageFile.Name.Length - 'coverage.'.Length - '.xml'.Length)
& $codecov --name $tfm --file $coverageFile --token $env:CODECOV_TOKEN
if ($LastExitCode) { exit 1 }
}
}
if ($testsFailed) { exit 1 }