-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
70 lines (56 loc) · 1.5 KB
/
build.ps1
File metadata and controls
70 lines (56 loc) · 1.5 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
Param(
[string]$Mode = "all"
)
$ErrorActionPreference = "Stop"
function Write-Info($Message) {
Write-Host "[INFO] $Message"
}
function Write-FailAndExit($Message) {
Write-Error "[ERROR] $Message"
exit 1
}
function Invoke-Go {
param(
[string[]]$GoArgs
)
& go @GoArgs
if ($LASTEXITCODE -ne 0) {
throw "go $($GoArgs -join ' ') failed with exit code $LASTEXITCODE"
}
}
function Ensure-Bin {
param(
[string]$BinDir
)
if (-not (Test-Path $BinDir)) {
New-Item -ItemType Directory -Path $BinDir | Out-Null
}
}
$ValidModes = @("all", "unit", "integration", "build-only")
if (-not ($ValidModes -contains $Mode)) {
Write-FailAndExit "Invalid mode '$Mode'. Use one of: $($ValidModes -join ', ')"
}
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ScriptDir
$BinDir = Join-Path $ScriptDir "bin"
$BinaryPath = Join-Path $BinDir "game-list.exe"
Write-Info "Mode: $Mode"
Ensure-Bin -BinDir $BinDir
try {
Write-Info "Building binary -> $BinaryPath"
Invoke-Go -GoArgs @("build", "-o", $BinaryPath, ".")
Write-Info "Build succeeded"
if ($Mode -eq "unit" -or $Mode -eq "all") {
Write-Info "Running unit tests"
Invoke-Go -GoArgs @("test", "-run", "_Unit$", "./...")
Write-Info "Unit tests passed"
}
if ($Mode -eq "integration" -or $Mode -eq "all") {
Write-Info "Running integration tests"
Invoke-Go -GoArgs @("test", "-run", "_Integration$", "./tests/integration/...")
Write-Info "Integration tests passed"
}
Write-Info "Completed mode '$Mode'"
} catch {
Write-FailAndExit $_
}