forked from devstress/FlinkDotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit-validation.ps1
More file actions
125 lines (108 loc) · 3.75 KB
/
Copy pathpre-commit-validation.ps1
File metadata and controls
125 lines (108 loc) · 3.75 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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Pre-commit hook to enforce build and test validation
.DESCRIPTION
This script automatically runs before any commit to ensure that
functionality changes do not break builds or critical tests.
Implements enforcement to prevent build failures from being committed.
.EXAMPLE
./pre-commit-validation.ps1
#>
# Colors for output
$Green = "`e[32m"
$Red = "`e[31m"
$Yellow = "`e[33m"
$Blue = "`e[34m"
$Reset = "`e[0m"
function Write-Success {
param([string]$Message)
Write-Host "${Green}✅ $Message${Reset}"
}
function Write-Error {
param([string]$Message)
Write-Host "${Red}❌ $Message${Reset}"
}
function Write-Warning {
param([string]$Message)
Write-Host "${Yellow}⚠️ $Message${Reset}"
}
function Write-Info {
param([string]$Message)
Write-Host "${Blue}ℹ️ $Message${Reset}"
}
Write-Info "=== Pre-Commit Build and Test Validation ==="
# Check if we have any staged changes
try {
$stagedFiles = git diff --cached --name-only 2>$null
if (-not $stagedFiles) {
Write-Info "No staged changes found. Skipping validation."
exit 0
}
# Check if staged changes include code files
$codeChanges = $stagedFiles | Where-Object { $_ -match '\.(cs|csproj|sln|json)$' }
if (-not $codeChanges) {
Write-Info "No code changes detected. Skipping validation."
exit 0
}
Write-Info "Code changes detected:"
foreach ($file in $codeChanges) {
Write-Info " - $file"
}
} catch {
Write-Warning "Could not check git status. Proceeding with validation."
}
# Run the main validation script
Write-Info "Running build and test validation..."
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$ValidationScript = Join-Path $ScriptDir "validate-build-and-tests.ps1"
if (-not (Test-Path $ValidationScript)) {
Write-Error "Validation script not found: $ValidationScript"
Write-Error "Cannot proceed with commit."
exit 1
}
try {
# Run validation with Release configuration
& $ValidationScript -Configuration Release
$validationExitCode = $LASTEXITCODE
switch ($validationExitCode) {
0 {
Write-Success "=== PRE-COMMIT VALIDATION PASSED ==="
Write-Success "All builds and tests passed. Commit allowed."
exit 0
}
1 {
Write-Error "=== PRE-COMMIT VALIDATION FAILED ==="
Write-Error "Build failures detected. Commit BLOCKED."
Write-Error ""
Write-Error "ENFORCEMENT RULE: All functionality changes must build successfully."
Write-Error "Please fix build errors before committing:"
Write-Error " 1. Run: ./validate-build-and-tests.ps1"
Write-Error " 2. Fix any build errors"
Write-Error " 3. Re-run validation"
Write-Error " 4. Try commit again"
exit 1
}
2 {
Write-Warning "=== PRE-COMMIT VALIDATION: BUILD PASSED, TESTS FAILED ==="
Write-Warning "Builds succeeded but some tests failed."
Write-Warning "Commit allowed, but consider fixing test failures."
Write-Info ""
Write-Info "To fix test failures:"
Write-Info " 1. Run: ./validate-build-and-tests.ps1"
Write-Info " 2. Review test failure details"
Write-Info " 3. Fix failing tests"
exit 0
}
default {
Write-Error "=== PRE-COMMIT VALIDATION ERROR ==="
Write-Error "Unexpected validation result. Commit BLOCKED for safety."
exit 1
}
}
} catch {
Write-Error "=== PRE-COMMIT VALIDATION ERROR ==="
Write-Error "Failed to run validation: $_"
Write-Error "Commit BLOCKED for safety."
exit 1
}