-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.ps1
More file actions
113 lines (92 loc) · 3.38 KB
/
Copy pathBuild.ps1
File metadata and controls
113 lines (92 loc) · 3.38 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
<#
.SYNOPSIS
Automates dependency setup, .proto compilation, clean, restore, build, and runs tests for the MultilayerCache solution.
#>
param(
[switch]$Clean
)
$SolutionRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$ProtosFolder = Join-Path $SolutionRoot "MultilayerCache.Demo\Protos"
$GeneratedFolder = Join-Path $SolutionRoot "MultilayerCache.Demo\Generated"
# --- Ensure protoc exists ---
function Ensure-Protoc {
Write-Host "Checking for protoc compiler..."
$protocCmd = "protoc"
if (Get-Command $protocCmd -ErrorAction SilentlyContinue) {
Write-Host "protoc found in PATH."
return
}
$localProtocDir = Join-Path $env:USERPROFILE "protoc"
$binDir = Join-Path $localProtocDir "bin"
if (Test-Path $binDir -PathType Container) {
$env:PATH += ";$binDir"
if (Get-Command $protocCmd -ErrorAction SilentlyContinue) {
Write-Host "protoc detected from local folder: $binDir"
return
}
}
$url = "https://github.com/protocolbuffers/protobuf/releases/download/v23.5/protoc-23.5-win64.zip"
$zipPath = Join-Path $env:TEMP "protoc.zip"
try {
Write-Host "Downloading protoc..."
Invoke-WebRequest -Uri $url -OutFile $zipPath -UseBasicParsing
} catch {
Write-Warning "Failed to download protoc from $url. Please download manually."
Write-Error "protoc not installed. Aborting."
exit 1
}
Expand-Archive -Path $zipPath -DestinationPath $localProtocDir -Force
Remove-Item $zipPath -Force
$env:PATH += ";$binDir"
if (Get-Command $protocCmd -ErrorAction SilentlyContinue) {
Write-Host "protoc installed locally to $binDir"
} else {
Write-Error "protoc still not found. Please install manually."
exit 1
}
}
# --- Clean bin/obj folders ---
function Clean-Projects {
Write-Host "Cleaning bin and obj folders..."
Get-ChildItem -Path $SolutionRoot -Recurse -Include bin,obj |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
}
# --- Compile .proto files ---
function Compile-Protos {
Ensure-Protoc
Write-Host "Compiling .proto files..."
if (-not (Test-Path $ProtosFolder)) { New-Item -ItemType Directory -Path $ProtosFolder -Force }
if (-not (Test-Path $GeneratedFolder)) { New-Item -ItemType Directory -Path $GeneratedFolder -Force }
$protoFiles = Get-ChildItem -Path $ProtosFolder -Filter *.proto
if ($protoFiles.Count -eq 0) {
Write-Warning "No .proto files found in $ProtosFolder"
return
}
foreach ($file in $protoFiles) {
Write-Host "Compiling $($file.Name)..."
& protoc --csharp_out=$GeneratedFolder --proto_path=$ProtosFolder $file.FullName
}
}
# --- Restore NuGet packages ---
function Restore-Packages {
Write-Host "Restoring NuGet packages..."
dotnet restore "$SolutionRoot\MultilayerCache.sln"
}
# --- Build all projects ---
function Build-Projects {
Write-Host "Building all projects..."
dotnet build "$SolutionRoot\MultilayerCache.sln" -c Release
}
# --- Run all tests ---
function Run-Tests {
Write-Host "Running tests..."
dotnet test "$SolutionRoot\MultilayerCache.Tests\MultilayerCache.Tests.csproj" -c Release --verbosity normal
}
# --- MAIN ---
Ensure-Protoc
if ($Clean) { Clean-Projects }
Compile-Protos
Restore-Packages
Build-Projects
Run-Tests
Write-Host "✅ Build and tests completed successfully."