-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.ps1
102 lines (78 loc) · 2.4 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
[CmdletBinding(PositionalBinding=$false)]
param(
[string] $Version,
[string] $BuildNumber,
[bool] $CreatePackages = $true,
[bool] $RunTests = $true,
[bool] $IsCI = $false
)
Write-Host "Starting build process for Postcard"
$VersionFile = "$PSScriptRoot/version.txt"
$artifactsDirectory = "$PSScriptRoot/artifacts"
$projectsToBuild = 'Postcard', 'Postcard.Microsoft.DependencyInjection','Renderers\Postcard.Renderers.Razor','Senders\Postcard.Senders.Smtp'
$testProjects = 'Postcard.Tests','Postcard.Tests.Renderers.Razor'
Write-Host "$CreatePackages"
function GetVersion() {
if ($Version) {
return $Version
}
$versionToUse = ''
if (Test-Path $VersionFile) {
$versionToUse = Get-Content $VersionFile
}
if (!$versionToUse) {
Write-Host "version information was not found - $VersionFile"
Exit 1
}
if ($versionToUse -match "-") {
return "$versionToUse-$BuildNumber"
} else {
return "$versionToUse"
}
}
if ($BuildNumber -and $BuildNumber.Length -lt 5) {
$BuildNumber = $BuildNumber.PadLeft(5, "0")
}
$productVersion = $(GetVersion)
if($IsCI)
{
Update-AppveyorBuild -Version "$productVersion"
}
Write-Host "Version: $productVersion"
Write-Host "BuildNumber: $BuildNumber"
Write-Host "CreatePackages: $CreatePackages"
Write-Host "RunTests: $RunTests"
if ($RunTests) {
Write-Host "Preparing to run tests.."
dotnet restore
foreach ($project in $testProjects) {
Write-Host "Running tests for project: $project "
Push-Location ".\tests\$project"
dotnet test
if ($LastExitCode -ne 0) {
Write-Host "Test failures";
Pop-Location
Exit 1
}
Write-Host "All tests passed!"
Pop-Location
}
}
if ($CreatePackages) {
New-Item -ItemType Directory -Force -Path $artifactsDirectory
Get-ChildItem $artifactsDirectory | Remove-Item
}
foreach ($project in $projectsToBuild) {
Write-Host "Building $project`:"
Push-Location ".\src\$project"
$projectVersion = $productVersion
$targets = "Restore"
if ($CreatePackages) {
$targets += ";Pack"
}
Write-Host "$project... Version: $projectVersion"
dotnet msbuild "/t:$targets" "/p:Configuration=Release" "/p:Version=$projectVersion" "/p:PackageOutputPath=$artifactsDirectory"
Pop-Location
Write-Host "Project built"
}
Write-Host "Finished"