-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathBuild.ps1
140 lines (123 loc) · 3.7 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[Switch]
$SkipTests,
[Parameter(Mandatory = $false)]
[Switch]
$SkipPerfTests,
[Parameter(Mandatory = $false)]
[Switch]
$SkipSamples
)
echo "build: Build started"
try
{
Push-Location "$PSScriptRoot"
if (Test-Path .\artifacts)
{
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
}
echo "build: Restoring packages for solution"
& dotnet restore --no-cache
if ($LASTEXITCODE -ne 0)
{
echo "Error returned by dotnet restore. Aborting build."
exit 1
}
$branch = @{ $true = $env:GITHUB_REF_NAME; $false = $( git symbolic-ref --short -q HEAD ) }[$env:GITHUB_REF_NAME -ne $NULL]
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:GITHUB_RUN_NUMBER, 10); $false = "local" }[$env:GITHUB_RUN_NUMBER -ne $NULL]
$suffix = @{ $true = ""; $false = "$($branch.Substring(0,[math]::Min(10, $branch.Length)) )-$revision" }[$branch -ne "dev" -and $revision -ne "local"]
echo "build: Version suffix is $suffix"
$sinkProjectPath = "$PSScriptRoot/src/Serilog.Sinks.MSSqlServer"
try
{
Push-Location "$sinkProjectPath"
echo "build: Packaging sink main project in $sinkProjectPath"
if ($suffix)
{
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
}
else
{
& dotnet pack -c Release -o ..\..\artifacts
}
if ($LASTEXITCODE -ne 0)
{
echo "Error returned by dotnet pack. Aborting build."
exit 1
}
}
finally
{
Pop-Location
}
if ($SkipTests -eq $false)
{
$testProjectPath = "$PSScriptRoot/test/Serilog.Sinks.MSSqlServer.Tests"
try
{
Push-Location "$testProjectPath"
# Run tests for different targets in sequence to avoid database tests
# to fail because of concurrency problems
foreach ($tfm in @( "net462", "net472", "net8.0" ))
{
echo "build: Testing project in $testProjectPath for target $tfm"
& dotnet test -c Release --collect "XPlat Code Coverage" --framework "$tfm" --results-directory "./TestResults/$tfm"
if ($LASTEXITCODE -ne 0)
{
exit 2
}
}
}
finally
{
Pop-Location
}
}
if ($SkipPerfTests -eq $false)
{
# The performance benchmark tests should at least build without errors during PR validation
$perfTestProjectPath = "$PSScriptRoot/test/Serilog.Sinks.MSSqlServer.PerformanceTests"
try
{
Push-Location "$perfTestProjectPath"
echo "build: Building performance test project in $perfTestProjectPath"
& dotnet build -c Release
if ($LASTEXITCODE -ne 0)
{
exit 3
}
}
finally
{
Pop-Location
}
}
if ($SkipSamples -eq $false)
{
foreach ($src in Get-ChildItem "$PSScriptRoot/sample/*.csproj" -File -Recurse)
{
try
{
Push-Location $src.DirectoryName
echo "build: Building sample project $( $src.FullName )"
& dotnet build -c Release -o ..\..\artifacts
if ($LASTEXITCODE -ne 0)
{
echo "Error returned by dotnet build. Aborting build."
exit 4
}
}
finally
{
Pop-Location
}
}
}
}
finally
{
Pop-Location
}