forked from NSPG13/agent-bounties
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreflight.ps1
More file actions
134 lines (114 loc) · 4.03 KB
/
Copy pathpreflight.ps1
File metadata and controls
134 lines (114 loc) · 4.03 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
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
param(
[ValidateSet("core", "full")]
[string] $Mode = "core"
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
$env:Path = "$env:USERPROFILE\.cargo\bin;$repoRoot\.tools\foundry;$env:Path"
$failures = New-Object System.Collections.Generic.List[string]
$warnings = New-Object System.Collections.Generic.List[string]
$minimumRustMajor = 1
$minimumRustMinor = 88
function Test-RequiredCommand {
param(
[Parameter(Mandatory = $true)]
[string] $Name,
[Parameter(Mandatory = $true)]
[string] $Purpose
)
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
$failures.Add("$Name is required for $Purpose")
}
}
function Test-OptionalCommand {
param(
[Parameter(Mandatory = $true)]
[string] $Name,
[Parameter(Mandatory = $true)]
[string] $Purpose
)
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
$warnings.Add("$Name is optional; install it for $Purpose")
}
}
function Test-MinimumVersion {
param(
[Parameter(Mandatory = $true)]
[string] $Name,
[Parameter(Mandatory = $true)]
[int] $MinimumMajor,
[Parameter(Mandatory = $true)]
[int] $MinimumMinor,
[Parameter(Mandatory = $true)]
[string] $Purpose
)
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
return
}
$previousErrorActionPreference = $ErrorActionPreference
try {
# Windows PowerShell can promote native stderr warnings to terminating
# errors even when the command exits successfully. Version checks care
# about the exit code and stdout, so handle those explicitly.
$ErrorActionPreference = "SilentlyContinue"
$versionOutput = & $Name --version 2>$null
$versionExitCode = $LASTEXITCODE
}
finally {
$ErrorActionPreference = $previousErrorActionPreference
}
if ($versionExitCode -ne 0) {
$failures.Add("$Name --version failed for $Purpose with exit code $versionExitCode")
return
}
if ($versionOutput -notmatch '^\S+\s+(\d+)\.(\d+)\.') {
$failures.Add("could not parse $Name version for $Purpose")
return
}
$major = [int] $Matches[1]
$minor = [int] $Matches[2]
if ($major -lt $MinimumMajor -or ($major -eq $MinimumMajor -and $minor -lt $MinimumMinor)) {
$failures.Add("$Name $MinimumMajor.$MinimumMinor or newer is required for $Purpose; found $versionOutput")
}
}
Test-RequiredCommand rustc "Rust compiler commands"
Test-RequiredCommand cargo "Rust workspace commands"
Test-RequiredCommand npm "TypeScript SDK checks"
Test-MinimumVersion rustc $minimumRustMajor $minimumRustMinor "the locked dependency graph"
Test-MinimumVersion cargo $minimumRustMajor $minimumRustMinor "the locked dependency graph"
$pythonCommand = Get-Command python -ErrorAction SilentlyContinue
if (-not $pythonCommand) {
$pythonCommand = Get-Command py -ErrorAction SilentlyContinue
}
if (-not $pythonCommand) {
$failures.Add("python or py is required for Python SDK checks")
}
if ($Mode -eq "full") {
Test-RequiredCommand forge "Base escrow contract tests"
$minimumFreeMb = 4096
}
else {
$minimumFreeMb = 512
}
Test-OptionalCommand docker "Postgres durability smoke tests"
$driveName = (Get-Item $repoRoot).PSDrive.Name
$driveRoot = (Get-Item $repoRoot).PSDrive.Root
try {
$freeBytes = [System.IO.DriveInfo]::new($driveRoot).AvailableFreeSpace
}
catch {
$freeBytes = (Get-PSDrive -Name $driveName).Free
}
$freeMb = [math]::Floor($freeBytes / 1MB)
if ($freeMb -lt $minimumFreeMb) {
$failures.Add("free disk on drive $driveName is ${freeMb}MB; $Mode mode expects at least ${minimumFreeMb}MB. If this is a development checkout, run cargo clean to remove generated target output.")
}
if ($warnings.Count -gt 0) {
foreach ($warning in $warnings) {
Write-Warning $warning
}
}
if ($failures.Count -gt 0) {
Write-Error ("Preflight failed:`n- " + ($failures -join "`n- "))
}
Write-Host "preflight=$Mode ok free_mb=$freeMb"