-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathvalidate-ci.ps1
More file actions
103 lines (89 loc) · 3.77 KB
/
validate-ci.ps1
File metadata and controls
103 lines (89 loc) · 3.77 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
# Local CI/CD Validation Script (PowerShell)
# This script runs the same checks as the GitHub Actions workflow
Write-Host "🔄 Running CI/CD Pipeline Validation locally..." -ForegroundColor Green
Write-Host ""
# Set environment variable
$env:CARGO_TERM_COLOR = "always"
Write-Host "📦 Installing Rust toolchain and dependencies..." -ForegroundColor Blue
rustup target add wasm32-unknown-unknown
cargo install cargo-fuzz 2>$null || Write-Host "⚠️ cargo-fuzz already installed" -ForegroundColor Yellow
Write-Host ""
Write-Host "🔍 Running code quality checks..." -ForegroundColor Blue
# Check formatting
Write-Host " 📝 Checking code formatting..." -ForegroundColor Cyan
$cargo_fmt_result = cargo fmt --all -- --check
if ($LASTEXITCODE -eq 0) {
Write-Host " ✅ Code formatting: PASSED" -ForegroundColor Green
} else {
Write-Host " ❌ Code formatting: FAILED" -ForegroundColor Red
Write-Host " Run 'cargo fmt' to fix formatting issues" -ForegroundColor Yellow
exit 1
}
# Run clippy
Write-Host " 🔍 Running clippy linting..." -ForegroundColor Cyan
$cargo_clippy_result = cargo clippy --target wasm32-unknown-unknown -- -D warnings
if ($LASTEXITCODE -eq 0) {
Write-Host " ✅ Clippy linting: PASSED" -ForegroundColor Green
} else {
Write-Host " ❌ Clippy linting: FAILED" -ForegroundColor Red
Write-Host " Fix clippy warnings before committing" -ForegroundColor Yellow
exit 1
}
Write-Host ""
Write-Host "🏗️ Building contract..." -ForegroundColor Blue
# Build WASM contract
Write-Host " 🏗️ Building WASM contract..." -ForegroundColor Cyan
$cargo_build_result = cargo build --target wasm32-unknown-unknown --release
if ($LASTEXITCODE -eq 0) {
Write-Host " ✅ WASM build: PASSED" -ForegroundColor Green
} else {
Write-Host " ❌ WASM build: FAILED" -ForegroundColor Red
exit 1
}
Write-Host ""
Write-Host "🧪 Running tests..." -ForegroundColor Blue
# Run unit tests
Write-Host " 🧪 Running unit tests..." -ForegroundColor Cyan
$cargo_test_result = cargo test
if ($LASTEXITCODE -eq 0) {
Write-Host " ✅ Unit tests: PASSED" -ForegroundColor Green
} else {
Write-Host " ❌ Unit tests: FAILED" -ForegroundColor Red
exit 1
}
# Check fuzz tests
Write-Host " 🔍 Checking fuzz tests..." -ForegroundColor Cyan
$fuzz_dir = "contracts\utility_contracts\fuzz"
if (Test-Path $fuzz_dir) {
Write-Host " ✅ Fuzz tests: AVAILABLE" -ForegroundColor Green
Write-Host " 📁 Fuzz test directory found" -ForegroundColor Cyan
# List available fuzz targets
$cargo_toml = "contracts\utility_contracts\fuzz\Cargo.toml"
if (Test-Path $cargo_toml) {
Write-Host " 🎯 Available fuzz targets:" -ForegroundColor Cyan
$content = Get-Content $cargo_toml
$lines = $content -split "`n"
foreach ($line in $lines) {
if ($line -match "name = ") {
$target = $line -replace ".*name = " -replace ".*"
Write-Host " - $target" -ForegroundColor White
}
}
}
} else {
Write-Host " ⚠️ Fuzz tests: NOT FOUND" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "📊 Pipeline Summary:" -ForegroundColor Green
Write-Host " ✅ Code formatting: PASSED" -ForegroundColor Green
Write-Host " ✅ Clippy linting: PASSED" -ForegroundColor Green
Write-Host " ✅ WASM build: PASSED" -ForegroundColor Green
Write-Host " ✅ Unit tests: PASSED" -ForegroundColor Green
if (Test-Path $fuzz_dir) {
Write-Host " ✅ Fuzz tests: AVAILABLE" -ForegroundColor Green
} else {
Write-Host " ⚠️ Fuzz tests: NOT AVAILABLE" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "🎉 All checks passed! Your code is ready for commit/PR." -ForegroundColor Green
Write-Host "💡 Run this script before committing to ensure CI/CD will pass." -ForegroundColor Cyan