forked from StackExchange/StackExchange.Redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
120 lines (98 loc) · 3.39 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
[CmdletBinding(PositionalBinding=$false)]
param(
[string] $Version,
[string] $BuildNumber,
[bool] $CreatePackages,
[bool] $RunTests = $true,
[string] $PullRequestNumber
)
function CalculateVersion() {
if ($Version) {
return $Version
}
$semVersion = '';
$path = $pwd;
while (!$semVersion) {
if (Test-Path (Join-Path $path "semver.txt")) {
$semVersion = Get-Content (Join-Path $path "semver.txt")
break
}
if ($PSScriptRoot -eq $path) {
break
}
$path = Split-Path $path -Parent
}
if (!$semVersion) {
Write-Error "semver.txt was not found in $pwd or any parent directory"
Exit 1
}
return "$semVersion-$BuildNumber"
}
if ($BuildNumber -and $BuildNumber.Length -lt 5) {
$BuildNumber = $BuildNumber.PadLeft(5, "0")
}
Write-Host "Run Parameters:" -ForegroundColor Cyan
Write-Host "Version: $Version"
Write-Host "BuildNumber: $BuildNumber"
Write-Host "CreatePackages: $CreatePackages"
Write-Host "RunTests: $RunTests"
Write-Host "Base Version: $(CalculateVersion)"
$packageOutputFolder = "$PSScriptRoot\.nupkgs"
$projectsToBuild =
'StackExchange.Redis',
'StackExchange.Redis.StrongName',
'NRediSearch'
$testsToRun =
'StackExchange.Redis.Tests'
if (!$Version -and !$BuildNumber) {
Write-Host "ERROR: You must supply either a -Version or -BuildNumber argument. `
Use -Version `"4.0.0`" for explicit version specification, or `
Use -BuildNumber `"12345`" for generation using <semver.txt>-<buildnumber>" -ForegroundColor Yellow
Exit 1
}
if ($PullRequestNumber) {
Write-Host "Building for a pull request (#$PullRequestNumber), skipping packaging." -ForegroundColor Yellow
$CreatePackages = $false
}
if ($RunTests) {
dotnet restore /ConsoleLoggerParameters:Verbosity=Quiet
foreach ($project in $testsToRun) {
Write-Host "Running tests: $project (all frameworks)" -ForegroundColor "Magenta"
#Push-Location ".\tests\$project"
Push-Location ".\$project"
dotnet xunit
if ($LastExitCode -ne 0) {
Write-Host "Error with tests, aborting build." -Foreground "Red"
Pop-Location
Exit 1
}
Write-Host "Tests passed!" -ForegroundColor "Green"
Pop-Location
}
}
if ($CreatePackages) {
mkdir -Force $packageOutputFolder | Out-Null
Write-Host "Clearing existing $packageOutputFolder..." -NoNewline
Get-ChildItem $packageOutputFolder | Remove-Item
Write-Host "done." -ForegroundColor "Green"
Write-Host "Building all packages" -ForegroundColor "Green"
}
foreach ($project in $projectsToBuild) {
Write-Host "Working on $project`:" -ForegroundColor "Magenta"
#Push-Location ".\src\$project"
Push-Location ".\$project"
$semVer = CalculateVersion
$targets = "Restore"
Write-Host " Restoring " -NoNewline -ForegroundColor "Magenta"
if ($CreatePackages) {
$targets += ";Pack"
Write-Host "and packing " -NoNewline -ForegroundColor "Magenta"
}
Write-Host "$project... (Version:" -NoNewline -ForegroundColor "Magenta"
Write-Host $semVer -NoNewline -ForegroundColor "Cyan"
Write-Host ")" -ForegroundColor "Magenta"
dotnet msbuild "/t:$targets" "/p:Configuration=Release" "/p:Version=$semVer" "/p:PackageOutputPath=$packageOutputFolder" "/p:CI=true"
Pop-Location
Write-Host "Done."
Write-Host ""
}