-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ps1
More file actions
92 lines (76 loc) · 2.16 KB
/
Copy pathtest.ps1
File metadata and controls
92 lines (76 loc) · 2.16 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
param(
[string]$Configuration = "Debug",
[switch]$SkipBuild,
[string]$Filter,
[int]$RetryCount = 3
)
$ErrorActionPreference = "Stop"
$repoRoot = $PSScriptRoot
Set-Location $repoRoot
function Stop-StaleProcesses {
$staleProcesses = @("testhost", "VBCSCompiler")
foreach ($processName in $staleProcesses) {
Get-Process -Name $processName -ErrorAction SilentlyContinue | Stop-Process -Force
}
}
function Invoke-DotNetWithRetry {
param(
[Parameter(Mandatory = $true)]
[string[]]$Arguments,
[Parameter(Mandatory = $true)]
[int]$MaxAttempts
)
for ($attempt = 1; $attempt -le $MaxAttempts; $attempt++) {
$output = & dotnet @Arguments 2>&1
$exitCode = $LASTEXITCODE
$output | Write-Host
if ($exitCode -eq 0) {
return 0
}
$isLastAttempt = $attempt -ge $MaxAttempts
$isTransientLock = ($output | Out-String) -match 'error CS2012|error MSB3021|error MSB3026|being used by another process|file may be locked'
if (-not $isTransientLock -or $isLastAttempt) {
return $exitCode
}
Stop-StaleProcesses
Start-Sleep -Seconds 2
}
return 1
}
Stop-StaleProcesses
dotnet build-server shutdown | Out-Null
$stableDotNetArgs = @(
"--disable-build-servers",
"/nodeReuse:false",
"/p:UseSharedCompilation=false"
)
if (-not $SkipBuild) {
$buildArguments = @(
"build",
"Lokad.Utf8Regex.slnx",
"--configuration", $Configuration,
"--tl:off",
"--nologo",
"-v", "minimal",
"--no-restore"
) + $stableDotNetArgs
$buildExitCode = Invoke-DotNetWithRetry -Arguments $buildArguments -MaxAttempts $RetryCount
if ($buildExitCode -ne 0) {
exit $buildExitCode
}
}
$testArguments = @(
"test",
"Lokad.Utf8Regex.slnx",
"--configuration", $Configuration,
"--tl:off",
"--nologo",
"-v", "minimal",
"--no-build",
"--no-restore"
) + $stableDotNetArgs
if ($Filter) {
$testArguments += @("--filter", $Filter)
}
$testExitCode = Invoke-DotNetWithRetry -Arguments $testArguments -MaxAttempts $RetryCount
exit $testExitCode