1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-11 17:38:59 +00:00

feat(windows): add Windows support Phase 4 - testing and CI

- Pester test suite for PowerShell scripts (Core, Clean, Commands)
- Go tests for TUI tools (analyze, status)
- GitHub Actions workflow for Windows CI
- Build and test automation scripts (test.ps1, build.ps1)
This commit is contained in:
Bhadra
2026-01-08 16:41:03 +05:30
parent 8a37f63bc7
commit 230ca07c7f
8 changed files with 1475 additions and 0 deletions

174
windows/scripts/build.ps1 Normal file
View File

@@ -0,0 +1,174 @@
# Mole Windows - Build Script
# Builds Go binaries and validates PowerShell scripts
#Requires -Version 5.1
param(
[switch]$Clean,
[switch]$Release,
[switch]$Validate,
[switch]$ShowHelp
)
$ErrorActionPreference = "Stop"
# Get script directory
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$windowsDir = Split-Path -Parent $scriptDir
$binDir = Join-Path $windowsDir "bin"
function Show-BuildHelp {
Write-Host ""
Write-Host "Mole Windows Build Script" -ForegroundColor Cyan
Write-Host ""
Write-Host "Usage: .\build.ps1 [options]"
Write-Host ""
Write-Host "Options:"
Write-Host " -Clean Clean build artifacts before building"
Write-Host " -Release Build optimized release binaries"
Write-Host " -Validate Validate PowerShell script syntax"
Write-Host " -ShowHelp Show this help message"
Write-Host ""
}
if ($ShowHelp) {
Show-BuildHelp
return
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Mole Windows - Build" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# ============================================================================
# Clean
# ============================================================================
if ($Clean) {
Write-Host "[Clean] Removing build artifacts..." -ForegroundColor Yellow
$artifacts = @(
(Join-Path $binDir "analyze.exe"),
(Join-Path $binDir "status.exe"),
(Join-Path $windowsDir "coverage-go.out"),
(Join-Path $windowsDir "coverage-pester.xml")
)
foreach ($artifact in $artifacts) {
if (Test-Path $artifact) {
Remove-Item $artifact -Force
Write-Host " Removed: $artifact" -ForegroundColor Gray
}
}
Write-Host ""
}
# ============================================================================
# Validate PowerShell Scripts
# ============================================================================
if ($Validate) {
Write-Host "[Validate] Checking PowerShell script syntax..." -ForegroundColor Yellow
$scripts = Get-ChildItem -Path $windowsDir -Filter "*.ps1" -Recurse
$errors = @()
foreach ($script in $scripts) {
try {
$null = [System.Management.Automation.Language.Parser]::ParseFile(
$script.FullName,
[ref]$null,
[ref]$null
)
Write-Host " OK: $($script.Name)" -ForegroundColor Green
}
catch {
Write-Host " ERROR: $($script.Name)" -ForegroundColor Red
$errors += $script.FullName
}
}
if ($errors.Count -gt 0) {
Write-Host ""
Write-Host " $($errors.Count) script(s) have syntax errors!" -ForegroundColor Red
exit 1
}
Write-Host ""
}
# ============================================================================
# Build Go Binaries
# ============================================================================
Write-Host "[Build] Building Go binaries..." -ForegroundColor Yellow
# Check if Go is installed
$goVersion = & go version 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host " Error: Go is not installed" -ForegroundColor Red
Write-Host " Please install Go from https://golang.org/dl/" -ForegroundColor Gray
exit 1
}
Write-Host " $goVersion" -ForegroundColor Gray
Write-Host ""
# Create bin directory if needed
if (-not (Test-Path $binDir)) {
New-Item -ItemType Directory -Path $binDir -Force | Out-Null
}
Push-Location $windowsDir
try {
# Build flags
$ldflags = ""
if ($Release) {
$ldflags = "-s -w" # Strip debug info for smaller binaries
}
# Build analyze
Write-Host " Building analyze.exe..." -ForegroundColor Gray
if ($Release) {
& go build -ldflags "$ldflags" -o "$binDir\analyze.exe" "./cmd/analyze/"
}
else {
& go build -o "$binDir\analyze.exe" "./cmd/analyze/"
}
if ($LASTEXITCODE -ne 0) {
Write-Host " Failed to build analyze.exe" -ForegroundColor Red
exit 1
}
$analyzeSize = (Get-Item "$binDir\analyze.exe").Length / 1MB
Write-Host " Built: analyze.exe ($([math]::Round($analyzeSize, 2)) MB)" -ForegroundColor Green
# Build status
Write-Host " Building status.exe..." -ForegroundColor Gray
if ($Release) {
& go build -ldflags "$ldflags" -o "$binDir\status.exe" "./cmd/status/"
}
else {
& go build -o "$binDir\status.exe" "./cmd/status/"
}
if ($LASTEXITCODE -ne 0) {
Write-Host " Failed to build status.exe" -ForegroundColor Red
exit 1
}
$statusSize = (Get-Item "$binDir\status.exe").Length / 1MB
Write-Host " Built: status.exe ($([math]::Round($statusSize, 2)) MB)" -ForegroundColor Green
}
finally {
Pop-Location
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Build complete!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""

141
windows/scripts/test.ps1 Normal file
View File

@@ -0,0 +1,141 @@
# Mole Windows - Test Runner Script
# Runs all tests (Pester for PowerShell, go test for Go)
#Requires -Version 5.1
param(
[switch]$Verbose,
[switch]$NoPester,
[switch]$NoGo,
[switch]$Coverage
)
$ErrorActionPreference = "Stop"
$script:ExitCode = 0
# Get script directory
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$windowsDir = Split-Path -Parent $scriptDir
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Mole Windows - Test Suite" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# ============================================================================
# Pester Tests
# ============================================================================
if (-not $NoPester) {
Write-Host "[Pester] Running PowerShell tests..." -ForegroundColor Yellow
Write-Host ""
# Check if Pester is installed
$pesterModule = Get-Module -ListAvailable -Name Pester | Where-Object { $_.Version -ge "5.0.0" }
if (-not $pesterModule) {
Write-Host " Installing Pester 5.x..." -ForegroundColor Gray
Install-Module -Name Pester -MinimumVersion 5.0.0 -Force -SkipPublisherCheck -Scope CurrentUser
}
Import-Module Pester -MinimumVersion 5.0.0
$testsDir = Join-Path $windowsDir "tests"
$config = New-PesterConfiguration
$config.Run.Path = $testsDir
$config.Run.Exit = $false
$config.Output.Verbosity = if ($Verbose) { "Detailed" } else { "Normal" }
if ($Coverage) {
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.Path = @(
(Join-Path $windowsDir "lib\core\*.ps1"),
(Join-Path $windowsDir "lib\clean\*.ps1"),
(Join-Path $windowsDir "bin\*.ps1")
)
$config.CodeCoverage.OutputPath = Join-Path $windowsDir "coverage-pester.xml"
}
try {
$result = Invoke-Pester -Configuration $config
Write-Host ""
Write-Host "[Pester] Results:" -ForegroundColor Yellow
Write-Host " Passed: $($result.PassedCount)" -ForegroundColor Green
Write-Host " Failed: $($result.FailedCount)" -ForegroundColor $(if ($result.FailedCount -gt 0) { "Red" } else { "Green" })
Write-Host " Skipped: $($result.SkippedCount)" -ForegroundColor Gray
if ($result.FailedCount -gt 0) {
$script:ExitCode = 1
}
}
catch {
Write-Host " Error running Pester tests: $_" -ForegroundColor Red
$script:ExitCode = 1
}
Write-Host ""
}
# ============================================================================
# Go Tests
# ============================================================================
if (-not $NoGo) {
Write-Host "[Go] Running Go tests..." -ForegroundColor Yellow
Write-Host ""
# Check if Go is installed
$goVersion = & go version 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host " Go is not installed, skipping Go tests" -ForegroundColor Gray
}
else {
Write-Host " $goVersion" -ForegroundColor Gray
Write-Host ""
Push-Location $windowsDir
try {
$goArgs = @("test")
if ($Verbose) {
$goArgs += "-v"
}
if ($Coverage) {
$goArgs += "-coverprofile=coverage-go.out"
}
$goArgs += "./..."
& go @goArgs
if ($LASTEXITCODE -ne 0) {
$script:ExitCode = 1
}
else {
Write-Host ""
Write-Host "[Go] All tests passed" -ForegroundColor Green
}
}
finally {
Pop-Location
}
}
Write-Host ""
}
# ============================================================================
# Summary
# ============================================================================
Write-Host "========================================" -ForegroundColor Cyan
if ($script:ExitCode -eq 0) {
Write-Host " All tests passed!" -ForegroundColor Green
}
else {
Write-Host " Some tests failed!" -ForegroundColor Red
}
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
exit $script:ExitCode