-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild.ps1
More file actions
105 lines (92 loc) · 3.75 KB
/
Copy pathbuild.ps1
File metadata and controls
105 lines (92 loc) · 3.75 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Build orchestration for Helios.DedicatedThreadPool (replaces the legacy FAKE build.fsx).
.DESCRIPTION
Cross-platform pwsh build script. Version is read from RELEASE_NOTES.md.
.EXAMPLE
./build.ps1 Build
./build.ps1 Test
./build.ps1 Pack
./build.ps1 All
#>
[CmdletBinding()]
param(
[Parameter(Position = 0)]
[ValidateSet('Restore', 'Build', 'Test', 'Pack', 'Benchmark', 'All')]
[string]$Target = 'Build',
[string]$Configuration = 'Release',
# Pass to Benchmark: runs --job dry (one iteration, no statistics) for CI smoke validation.
[switch]$Smoke
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$RepoRoot = $PSScriptRoot
$SrcDir = Join-Path $RepoRoot 'src'
$Solution = Join-Path $SrcDir 'Helios.DedicatedThreadPool.slnx'
$ArtifactsDir = Join-Path $RepoRoot 'bin'
$NuGetDir = Join-Path $ArtifactsDir 'nuget'
$TestResults = Join-Path $RepoRoot 'TestResults'
$RunSettings = Join-Path $RepoRoot 'coverlet.runsettings'
function Get-ReleaseVersion {
# First "#### <version> <date>" heading in RELEASE_NOTES.md is the current version.
$notes = Join-Path $RepoRoot 'RELEASE_NOTES.md'
foreach ($line in Get-Content $notes) {
if ($line -match '^####\s+(?<v>\S+)') { return $Matches['v'] }
}
throw "Could not parse a version from RELEASE_NOTES.md (expected a '#### <version> <date>' heading)."
}
function Invoke-Dotnet {
# Simple (non-advanced) function: all tokens flow into the automatic $args,
# so dotnet flags like -o/-c are never mistaken for PowerShell parameters.
Write-Host "dotnet $($args -join ' ')" -ForegroundColor Cyan
& dotnet @args
if ($LASTEXITCODE -ne 0) { throw "dotnet $($args -join ' ') failed with exit code $LASTEXITCODE." }
}
function Target-Restore {
Invoke-Dotnet tool restore
Invoke-Dotnet restore $Solution
}
function Target-Build {
Target-Restore
Invoke-Dotnet build $Solution -c $Configuration --no-restore
}
function Target-Test {
Target-Build
# Optional category filter. CI sets TEST_FILTER='Category!=Measurement' to skip the local-only,
# process-wide measurement smokes (idle-CPU / contention) that are flaky on shared/constrained CI
# runners. Unset locally => run everything (the smokes are useful on a real dev box).
$filterArgs = @()
if ($env:TEST_FILTER) { $filterArgs = @('--filter', $env:TEST_FILTER) }
Invoke-Dotnet test $Solution -c $Configuration --no-build `
--logger 'trx' --logger 'console;verbosity=normal' `
--results-directory $TestResults `
--collect 'XPlat Code Coverage' --settings $RunSettings @filterArgs
}
function Target-Pack {
$version = Get-ReleaseVersion
Write-Host "Packing version $version" -ForegroundColor Green
Target-Build
# Build the -p:Key=Value token as a single string so PowerShell's -name:value
# colon parsing doesn't split it before dotnet sees it.
$versionArg = "-p:PackageVersion=$version"
Invoke-Dotnet pack $Solution -c $Configuration --no-build $versionArg -o $NuGetDir
}
function Target-Benchmark {
Target-Build
# Pass --job dry for CI smoke (one iteration, no statistics). Full run omits this.
$bdn = if ($Smoke -or $env:CI) { @('--', '--job', 'dry') } else { @() }
$benchProjects = Get-ChildItem -Path $SrcDir -Recurse -Filter '*.Benchmarks.csproj'
foreach ($proj in $benchProjects) {
Invoke-Dotnet run --project $proj.FullName -c $Configuration --no-build @bdn
}
}
switch ($Target) {
'Restore' { Target-Restore }
'Build' { Target-Build }
'Test' { Target-Test }
'Pack' { Target-Pack }
'Benchmark' { Target-Benchmark }
'All' { Target-Test; Target-Pack }
}
Write-Host "`n$Target complete." -ForegroundColor Green