-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.ps1
More file actions
121 lines (108 loc) · 2.97 KB
/
check.ps1
File metadata and controls
121 lines (108 loc) · 2.97 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
#!/usr/bin/env pwsh
# Local CI Check Script
# Run quality checks locally that are executed in GitHub Actions
param(
[Parameter(Position=0)]
[ValidateSet('black', 'flake8', 'mypy', 'pytest', 'all')]
[string]$Check = 'all'
)
$ErrorActionPreference = 'Continue'
function Write-Header {
param([string]$Message)
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host $Message -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
}
function Write-Success {
param([string]$Message)
Write-Host "[PASS] $Message" -ForegroundColor Green
}
function Write-Error-Message {
param([string]$Message)
Write-Host "[FAIL] $Message" -ForegroundColor Red
}
function Run-Black {
Write-Header "Black: Code Format Check"
black --check src tests 2>&1 | Out-Host
if ($LASTEXITCODE -eq 0) {
Write-Success "Black check passed"
return $true
} else {
Write-Error-Message "Black check failed: Format issues found"
Write-Host "To fix: black src tests" -ForegroundColor Yellow
return $false
}
}
function Run-Flake8 {
Write-Header "Flake8: Code Style Check"
flake8 src tests 2>&1 | Out-Host
if ($LASTEXITCODE -eq 0) {
Write-Success "Flake8 check passed"
return $true
} else {
Write-Error-Message "Flake8 check failed: Style violations found"
return $false
}
}
function Run-Mypy {
Write-Header "Mypy: Type Check"
mypy src 2>&1 | Out-Host
if ($LASTEXITCODE -eq 0) {
Write-Success "Mypy check passed"
return $true
} else {
Write-Error-Message "Mypy check failed: Type errors found"
return $false
}
}
function Run-Pytest {
Write-Header "Pytest: Test Execution"
pytest --cov=src/serdevmock --cov-report=xml --cov-report=term 2>&1 | Out-Host
if ($LASTEXITCODE -eq 0) {
Write-Success "Pytest check passed"
return $true
} else {
Write-Error-Message "Pytest check failed: Tests failed"
return $false
}
}
# Main execution
$results = @{}
switch ($Check) {
'black' {
$results['black'] = Run-Black
}
'flake8' {
$results['flake8'] = Run-Flake8
}
'mypy' {
$results['mypy'] = Run-Mypy
}
'pytest' {
$results['pytest'] = Run-Pytest
}
'all' {
$results['black'] = Run-Black
$results['flake8'] = Run-Flake8
$results['mypy'] = Run-Mypy
$results['pytest'] = Run-Pytest
}
}
# Results summary
Write-Header "Check Results Summary"
$allPassed = $true
foreach ($key in $results.Keys) {
if ($results[$key]) {
Write-Host " [PASS] $key" -ForegroundColor Green
} else {
Write-Host " [FAIL] $key" -ForegroundColor Red
$allPassed = $false
}
}
if ($allPassed) {
Write-Host "`nAll checks passed!" -ForegroundColor Green
exit 0
} else {
Write-Host "`nSome checks failed" -ForegroundColor Red
exit 1
}