-
Notifications
You must be signed in to change notification settings - Fork 26
/
BuildAndTest.ps1
74 lines (63 loc) · 2.68 KB
/
BuildAndTest.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
Param (
[bool] $E2ETest = $false,
[string] $ChromeVersion = ''
)
$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$buildConfiguration = 'Release'
$buildProjects = Join-Path -Path $scriptDir -ChildPath 'PlanningPokerCore.sln'
$webProject = Join-Path -Path $scriptDir '.\src\Duracellko.PlanningPoker.Web\Duracellko.PlanningPoker.Web.csproj'
try {
Write-Host "Step: dotnet restore" -ForegroundColor Green
Write-Host "dotnet restore `"$buildProjects`""
& dotnet restore $buildProjects
if (!$?) {
throw "dotnet restore failed"
}
Write-Host "Step: dotnet build" -ForegroundColor Green
Write-Host "dotnet build `"$buildProjects`" --configuration $buildConfiguration"
& dotnet build $buildProjects --configuration $buildConfiguration
if (!$?) {
throw "dotnet build failed"
}
Write-Host "Step: unit tests" -ForegroundColor Green
$testFiles = [System.Collections.Generic.List[string]]::new()
$binPath = Join-Path -Path $scriptDir -ChildPath "artifacts\bin"
$testDirectories = Get-ChildItem -Path $binPath -Filter '*.Test' -Directory
$testDirectories | ForEach-Object {
$testProjectName = Split-Path -Path $_ -Leaf
$testFile = Join-Path -Path $_ -ChildPath $buildConfiguration
$testFile = Join-Path -Path $testFile -ChildPath "$testProjectName.dll"
$testFiles.Add($testFile)
}
$testAssemblies = $testFiles.ToArray()
Write-Host "dotnet test $testAssemblies --logger:trx"
& dotnet test $testAssemblies --logger:trx
if (!$?) {
throw "dotnet test failed"
}
if ($E2ETest) {
Write-Host "Phase: End-2-End tests" -ForegroundColor Green
Write-Host "Step: playwright install" -ForegroundColor Green
$playwrightPath = Join-Path -Path $scriptDir -ChildPath "artifacts\bin\Duracellko.PlanningPoker.E2ETest\$buildConfiguration\playwright.ps1"
& $playwrightPath install chromium
if (!$?) {
throw "playwright install failed"
}
Write-Host "Step: End-2-End tests" -ForegroundColor Green
$e2eTestPath = Join-Path -Path $binPath -ChildPath "Duracellko.PlanningPoker.E2ETest\$buildConfiguration\Duracellko.PlanningPoker.E2ETest.dll"
Write-Host "dotnet test `"$e2eTestPath`" --logger:trx"
& dotnet test $e2eTestPath --logger:trx
if (!$?) {
throw "dotnet test failed"
}
}
Write-Host "Step: dotnet publish" -ForegroundColor Green
Write-Host "dotnet publish `"$webProject`" --configuration $buildConfiguration"
& dotnet publish $webProject --configuration $buildConfiguration
if (!$?) {
throw "dotnet publish failed"
}
}
catch {
throw
}