-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.ps1
More file actions
286 lines (249 loc) · 8.94 KB
/
Makefile.ps1
File metadata and controls
286 lines (249 loc) · 8.94 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# PowerShell Build Script - AGILira Standard
# Windows equivalent of Makefile for Go development
# Usage: .\Makefile.ps1 [command]
# Example: .\Makefile.ps1 help
param(
[Parameter(Position=0)]
[string]$Command = "help"
)
# Variables
$BinaryName = Split-Path -Leaf (Get-Location)
$ToolsDir = "$env:GOPATH\bin"
if (-not $ToolsDir) { $ToolsDir = "$env:USERPROFILE\go\bin" }
# Colors for output
$Red = "Red"
$Green = "Green"
$Yellow = "Yellow"
$Blue = "Cyan"
function Write-ColorOutput {
param($Message, $Color = "White")
Write-Host $Message -ForegroundColor $Color
}
function Test-ToolExists {
param($ToolName)
$toolPath = Join-Path $ToolsDir "$ToolName.exe"
return Test-Path $toolPath
}
function Invoke-Help {
Write-ColorOutput "Available commands:" $Blue
Write-ColorOutput " help Show this help message" $Green
Write-ColorOutput " test Run tests" $Green
Write-ColorOutput " race Run tests with race detector" $Green
Write-ColorOutput " coverage Run tests with coverage" $Green
Write-ColorOutput " fmt Format Go code" $Green
Write-ColorOutput " vet Run go vet" $Green
Write-ColorOutput " staticcheck Run staticcheck" $Green
Write-ColorOutput " errcheck Run errcheck" $Green
Write-ColorOutput " gosec Run gosec security scanner" $Green
Write-ColorOutput " lint Run all linters" $Green
Write-ColorOutput " security Run security checks" $Green
Write-ColorOutput " check Run all checks (format, vet, lint, security, test)" $Green
Write-ColorOutput " check-race Run all checks including race detector" $Green
Write-ColorOutput " tools Install development tools" $Green
Write-ColorOutput " deps Download and verify dependencies" $Green
Write-ColorOutput " clean Clean build artifacts and test cache" $Green
Write-ColorOutput " build Build the binary" $Green
Write-ColorOutput " install Install the binary to GOPATH/bin" $Green
Write-ColorOutput " bench Run benchmarks" $Green
Write-ColorOutput " ci Run CI checks" $Green
Write-ColorOutput " dev Quick development check" $Green
Write-ColorOutput " pre-commit Run pre-commit checks (alias for 'check')" $Green
Write-ColorOutput " all Run everything from scratch" $Green
Write-ColorOutput " status Show status of installed tools" $Green
}
function Invoke-Test {
Write-ColorOutput "Running tests..." $Yellow
go test -v "./..."
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Invoke-Race {
Write-ColorOutput "Running tests with race detector..." $Yellow
go test -race -v "./..."
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Invoke-Coverage {
Write-ColorOutput "Running tests with coverage..." $Yellow
$testArgs = @("-coverprofile=coverage.out", "./...")
go test @testArgs
if ($LASTEXITCODE -eq 0) {
$coverArgs = @("-html=coverage.out", "-o", "coverage.html")
go tool cover @coverArgs
Write-ColorOutput "Coverage report generated: coverage.html" $Green
}
}
function Invoke-Fmt {
Write-ColorOutput "Formatting Go code..." $Yellow
go fmt "./..."
}
function Invoke-Vet {
Write-ColorOutput "Running go vet..." $Yellow
go vet "./..."
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Invoke-StaticCheck {
Write-ColorOutput "Running staticcheck..." $Yellow
if (-not (Test-ToolExists "staticcheck")) {
Write-ColorOutput "staticcheck not found. Run '.\Makefile.ps1 tools' to install." $Red
exit 1
}
& "$ToolsDir\staticcheck.exe" "./..."
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Invoke-ErrCheck {
Write-ColorOutput "Running errcheck..." $Yellow
if (-not (Test-ToolExists "errcheck")) {
Write-ColorOutput "errcheck not found. Run '.\Makefile.ps1 tools' to install." $Red
exit 1
}
& "$ToolsDir\errcheck.exe" "./..."
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Invoke-GoSec {
Write-ColorOutput "Running gosec security scanner..." $Yellow
if (-not (Test-ToolExists "gosec")) {
Write-ColorOutput "gosec not found. Run '.\Makefile.ps1 tools' to install." $Red
exit 1
}
& "$ToolsDir\gosec.exe" "./..."
if ($LASTEXITCODE -ne 0) {
Write-ColorOutput "⚠️ gosec completed with warnings (may be import-related)" $Yellow
}
}
function Invoke-Lint {
Invoke-StaticCheck
Invoke-ErrCheck
Write-ColorOutput "All linters completed." $Green
}
function Invoke-Security {
Invoke-GoSec
Write-ColorOutput "Security checks completed." $Green
}
function Invoke-Check {
Invoke-Fmt
Invoke-Vet
Invoke-Lint
Invoke-Security
Invoke-Test
Write-ColorOutput "All checks passed!" $Green
}
function Invoke-CheckRace {
Invoke-Fmt
Invoke-Vet
Invoke-Lint
Invoke-Security
Invoke-Race
Write-ColorOutput "All checks with race detection passed!" $Green
}
function Invoke-Tools {
Write-ColorOutput "Installing development tools..." $Yellow
go install honnef.co/go/tools/cmd/staticcheck@latest
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
go install github.com/kisielk/errcheck@latest
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
go install github.com/securego/gosec/v2/cmd/gosec@latest
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-ColorOutput "Tools installed successfully!" $Green
}
function Invoke-Deps {
Write-ColorOutput "Downloading dependencies..." $Yellow
go mod download
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
go mod verify
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
go mod tidy
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Invoke-Clean {
Write-ColorOutput "Cleaning..." $Yellow
go clean
go clean -testcache
if (Test-Path "coverage.out") { Remove-Item "coverage.out" }
if (Test-Path "coverage.html") { Remove-Item "coverage.html" }
if (Test-Path "$BinaryName.exe") { Remove-Item "$BinaryName.exe" }
}
function Invoke-Build {
Write-ColorOutput "Building $BinaryName..." $Yellow
go build -ldflags="-w -s" -o "$BinaryName.exe" .
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Invoke-Install {
Write-ColorOutput "Installing $BinaryName..." $Yellow
go install .
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Invoke-Bench {
Write-ColorOutput "Running benchmarks..." $Yellow
go test -bench=. -benchmem "./..."
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Invoke-CI {
Write-ColorOutput "Running CI checks..." $Blue
Invoke-Fmt
Invoke-Vet
Invoke-Lint
Invoke-Security
Invoke-Test
Invoke-Coverage
Write-ColorOutput "CI checks completed successfully!" $Green
}
function Invoke-Dev {
Write-ColorOutput "Running development checks..." $Blue
Invoke-Fmt
Invoke-Vet
Invoke-Test
Write-ColorOutput "Development checks completed!" $Green
}
function Invoke-All {
Invoke-Clean
Invoke-Tools
Invoke-Deps
Invoke-Check
Invoke-Build
}
function Invoke-Status {
Write-ColorOutput "Development tools status:" $Blue
$staticcheckStatus = if (Test-ToolExists "staticcheck") { "✓ installed" } else { "✗ missing" }
$staticcheckColor = if (Test-ToolExists "staticcheck") { $Green } else { $Red }
Write-Host "staticcheck: " -NoNewline
Write-ColorOutput $staticcheckStatus $staticcheckColor
$errcheckStatus = if (Test-ToolExists "errcheck") { "✓ installed" } else { "✗ missing" }
$errcheckColor = if (Test-ToolExists "errcheck") { $Green } else { $Red }
Write-Host "errcheck: " -NoNewline
Write-ColorOutput $errcheckStatus $errcheckColor
$gosecStatus = if (Test-ToolExists "gosec") { "✓ installed" } else { "✗ missing" }
$gosecColor = if (Test-ToolExists "gosec") { $Green } else { $Red }
Write-Host "gosec: " -NoNewline
Write-ColorOutput $gosecStatus $gosecColor
}
# Main execution
switch ($Command.ToLower()) {
"help" { Invoke-Help }
"test" { Invoke-Test }
"race" { Invoke-Race }
"coverage" { Invoke-Coverage }
"fmt" { Invoke-Fmt }
"vet" { Invoke-Vet }
"staticcheck" { Invoke-StaticCheck }
"errcheck" { Invoke-ErrCheck }
"gosec" { Invoke-GoSec }
"lint" { Invoke-Lint }
"security" { Invoke-Security }
"check" { Invoke-Check }
"check-race" { Invoke-CheckRace }
"tools" { Invoke-Tools }
"deps" { Invoke-Deps }
"clean" { Invoke-Clean }
"build" { Invoke-Build }
"install" { Invoke-Install }
"bench" { Invoke-Bench }
"ci" { Invoke-CI }
"dev" { Invoke-Dev }
"pre-commit" { Invoke-Check }
"all" { Invoke-All }
"status" { Invoke-Status }
default {
Write-ColorOutput "Unknown command: $Command" $Red
Write-ColorOutput "Run '.\Makefile.ps1 help' for available commands." $Yellow
exit 1
}
}