Skip to content

Commit e690cfc

Browse files
author
agilira
committed
Added Makefile.ps1
1 parent 18e2440 commit e690cfc

File tree

1 file changed

+284
-0
lines changed

1 file changed

+284
-0
lines changed

Makefile.ps1

Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
# PowerShell Build Script - AGILira Standard
2+
# Windows equivalent of Makefile for Go development
3+
# Usage: .\Makefile.ps1 [command]
4+
# Example: .\Makefile.ps1 help
5+
6+
param(
7+
[Parameter(Position=0)]
8+
[string]$Command = "help"
9+
)
10+
11+
# Variables
12+
$BinaryName = Split-Path -Leaf (Get-Location)
13+
$ToolsDir = "$env:GOPATH\bin"
14+
if (-not $ToolsDir) { $ToolsDir = "$env:USERPROFILE\go\bin" }
15+
16+
# Colors for output
17+
$Red = "Red"
18+
$Green = "Green"
19+
$Yellow = "Yellow"
20+
$Blue = "Cyan"
21+
22+
function Write-ColorOutput {
23+
param($Message, $Color = "White")
24+
Write-Host $Message -ForegroundColor $Color
25+
}
26+
27+
function Test-ToolExists {
28+
param($ToolName)
29+
$toolPath = Join-Path $ToolsDir "$ToolName.exe"
30+
return Test-Path $toolPath
31+
}
32+
33+
function Invoke-Help {
34+
Write-ColorOutput "Available commands:" $Blue
35+
Write-ColorOutput " help Show this help message" $Green
36+
Write-ColorOutput " test Run tests" $Green
37+
Write-ColorOutput " race Run tests with race detector" $Green
38+
Write-ColorOutput " coverage Run tests with coverage" $Green
39+
Write-ColorOutput " fmt Format Go code" $Green
40+
Write-ColorOutput " vet Run go vet" $Green
41+
Write-ColorOutput " staticcheck Run staticcheck" $Green
42+
Write-ColorOutput " errcheck Run errcheck" $Green
43+
Write-ColorOutput " gosec Run gosec security scanner" $Green
44+
Write-ColorOutput " lint Run all linters" $Green
45+
Write-ColorOutput " security Run security checks" $Green
46+
Write-ColorOutput " check Run all checks (format, vet, lint, security, test)" $Green
47+
Write-ColorOutput " check-race Run all checks including race detector" $Green
48+
Write-ColorOutput " tools Install development tools" $Green
49+
Write-ColorOutput " deps Download and verify dependencies" $Green
50+
Write-ColorOutput " clean Clean build artifacts and test cache" $Green
51+
Write-ColorOutput " build Build the binary" $Green
52+
Write-ColorOutput " install Install the binary to GOPATH/bin" $Green
53+
Write-ColorOutput " bench Run benchmarks" $Green
54+
Write-ColorOutput " ci Run CI checks" $Green
55+
Write-ColorOutput " dev Quick development check" $Green
56+
Write-ColorOutput " pre-commit Run pre-commit checks (alias for 'check')" $Green
57+
Write-ColorOutput " all Run everything from scratch" $Green
58+
Write-ColorOutput " status Show status of installed tools" $Green
59+
}
60+
61+
function Invoke-Test {
62+
Write-ColorOutput "Running tests..." $Yellow
63+
go test -v ./...
64+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
65+
}
66+
67+
function Invoke-Race {
68+
Write-ColorOutput "Running tests with race detector..." $Yellow
69+
go test -race -v ./...
70+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
71+
}
72+
73+
function Invoke-Coverage {
74+
Write-ColorOutput "Running tests with coverage..." $Yellow
75+
go test -coverprofile=coverage.out ./...
76+
if ($LASTEXITCODE -eq 0) {
77+
go tool cover -html=coverage.out -o coverage.html
78+
Write-ColorOutput "Coverage report generated: coverage.html" $Green
79+
}
80+
}
81+
82+
function Invoke-Fmt {
83+
Write-ColorOutput "Formatting Go code..." $Yellow
84+
go fmt ./...
85+
}
86+
87+
function Invoke-Vet {
88+
Write-ColorOutput "Running go vet..." $Yellow
89+
go vet ./...
90+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
91+
}
92+
93+
function Invoke-StaticCheck {
94+
Write-ColorOutput "Running staticcheck..." $Yellow
95+
if (-not (Test-ToolExists "staticcheck")) {
96+
Write-ColorOutput "staticcheck not found. Run '.\Makefile.ps1 tools' to install." $Red
97+
exit 1
98+
}
99+
& "$ToolsDir\staticcheck.exe" ./...
100+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
101+
}
102+
103+
function Invoke-ErrCheck {
104+
Write-ColorOutput "Running errcheck..." $Yellow
105+
if (-not (Test-ToolExists "errcheck")) {
106+
Write-ColorOutput "errcheck not found. Run '.\Makefile.ps1 tools' to install." $Red
107+
exit 1
108+
}
109+
& "$ToolsDir\errcheck.exe" ./...
110+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
111+
}
112+
113+
function Invoke-GoSec {
114+
Write-ColorOutput "Running gosec security scanner..." $Yellow
115+
if (-not (Test-ToolExists "gosec")) {
116+
Write-ColorOutput "gosec not found. Run '.\Makefile.ps1 tools' to install." $Red
117+
exit 1
118+
}
119+
& "$ToolsDir\gosec.exe" ./...
120+
if ($LASTEXITCODE -ne 0) {
121+
Write-ColorOutput "⚠️ gosec completed with warnings (may be import-related)" $Yellow
122+
}
123+
}
124+
125+
function Invoke-Lint {
126+
Invoke-StaticCheck
127+
Invoke-ErrCheck
128+
Write-ColorOutput "All linters completed." $Green
129+
}
130+
131+
function Invoke-Security {
132+
Invoke-GoSec
133+
Write-ColorOutput "Security checks completed." $Green
134+
}
135+
136+
function Invoke-Check {
137+
Invoke-Fmt
138+
Invoke-Vet
139+
Invoke-Lint
140+
Invoke-Security
141+
Invoke-Test
142+
Write-ColorOutput "All checks passed!" $Green
143+
}
144+
145+
function Invoke-CheckRace {
146+
Invoke-Fmt
147+
Invoke-Vet
148+
Invoke-Lint
149+
Invoke-Security
150+
Invoke-Race
151+
Write-ColorOutput "All checks with race detection passed!" $Green
152+
}
153+
154+
function Invoke-Tools {
155+
Write-ColorOutput "Installing development tools..." $Yellow
156+
go install honnef.co/go/tools/cmd/staticcheck@latest
157+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
158+
159+
go install github.com/kisielk/errcheck@latest
160+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
161+
162+
go install github.com/securecode/gosec/v2/cmd/gosec@latest
163+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
164+
165+
Write-ColorOutput "Tools installed successfully!" $Green
166+
}
167+
168+
function Invoke-Deps {
169+
Write-ColorOutput "Downloading dependencies..." $Yellow
170+
go mod download
171+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
172+
173+
go mod verify
174+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
175+
176+
go mod tidy
177+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
178+
}
179+
180+
function Invoke-Clean {
181+
Write-ColorOutput "Cleaning..." $Yellow
182+
go clean
183+
go clean -testcache
184+
if (Test-Path "coverage.out") { Remove-Item "coverage.out" }
185+
if (Test-Path "coverage.html") { Remove-Item "coverage.html" }
186+
if (Test-Path "$BinaryName.exe") { Remove-Item "$BinaryName.exe" }
187+
}
188+
189+
function Invoke-Build {
190+
Write-ColorOutput "Building $BinaryName..." $Yellow
191+
go build -ldflags="-w -s" -o "$BinaryName.exe" .
192+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
193+
}
194+
195+
function Invoke-Install {
196+
Write-ColorOutput "Installing $BinaryName..." $Yellow
197+
go install .
198+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
199+
}
200+
201+
function Invoke-Bench {
202+
Write-ColorOutput "Running benchmarks..." $Yellow
203+
go test -bench=. -benchmem ./...
204+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
205+
}
206+
207+
function Invoke-CI {
208+
Write-ColorOutput "Running CI checks..." $Blue
209+
Invoke-Fmt
210+
Invoke-Vet
211+
Invoke-Lint
212+
Invoke-Security
213+
Invoke-Test
214+
Invoke-Coverage
215+
Write-ColorOutput "CI checks completed successfully!" $Green
216+
}
217+
218+
function Invoke-Dev {
219+
Write-ColorOutput "Running development checks..." $Blue
220+
Invoke-Fmt
221+
Invoke-Vet
222+
Invoke-Test
223+
Write-ColorOutput "Development checks completed!" $Green
224+
}
225+
226+
function Invoke-All {
227+
Invoke-Clean
228+
Invoke-Tools
229+
Invoke-Deps
230+
Invoke-Check
231+
Invoke-Build
232+
}
233+
234+
function Invoke-Status {
235+
Write-ColorOutput "Development tools status:" $Blue
236+
237+
$staticcheckStatus = if (Test-ToolExists "staticcheck") { "✓ installed" } else { "✗ missing" }
238+
$staticcheckColor = if (Test-ToolExists "staticcheck") { $Green } else { $Red }
239+
Write-Host "staticcheck: " -NoNewline
240+
Write-ColorOutput $staticcheckStatus $staticcheckColor
241+
242+
$errcheckStatus = if (Test-ToolExists "errcheck") { "✓ installed" } else { "✗ missing" }
243+
$errcheckColor = if (Test-ToolExists "errcheck") { $Green } else { $Red }
244+
Write-Host "errcheck: " -NoNewline
245+
Write-ColorOutput $errcheckStatus $errcheckColor
246+
247+
$gosecStatus = if (Test-ToolExists "gosec") { "✓ installed" } else { "✗ missing" }
248+
$gosecColor = if (Test-ToolExists "gosec") { $Green } else { $Red }
249+
Write-Host "gosec: " -NoNewline
250+
Write-ColorOutput $gosecStatus $gosecColor
251+
}
252+
253+
# Main execution
254+
switch ($Command.ToLower()) {
255+
"help" { Invoke-Help }
256+
"test" { Invoke-Test }
257+
"race" { Invoke-Race }
258+
"coverage" { Invoke-Coverage }
259+
"fmt" { Invoke-Fmt }
260+
"vet" { Invoke-Vet }
261+
"staticcheck" { Invoke-StaticCheck }
262+
"errcheck" { Invoke-ErrCheck }
263+
"gosec" { Invoke-GoSec }
264+
"lint" { Invoke-Lint }
265+
"security" { Invoke-Security }
266+
"check" { Invoke-Check }
267+
"check-race" { Invoke-CheckRace }
268+
"tools" { Invoke-Tools }
269+
"deps" { Invoke-Deps }
270+
"clean" { Invoke-Clean }
271+
"build" { Invoke-Build }
272+
"install" { Invoke-Install }
273+
"bench" { Invoke-Bench }
274+
"ci" { Invoke-CI }
275+
"dev" { Invoke-Dev }
276+
"pre-commit" { Invoke-Check }
277+
"all" { Invoke-All }
278+
"status" { Invoke-Status }
279+
default {
280+
Write-ColorOutput "Unknown command: $Command" $Red
281+
Write-ColorOutput "Run '.\Makefile.ps1 help' for available commands." $Yellow
282+
exit 1
283+
}
284+
}

0 commit comments

Comments
 (0)