-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
132 lines (111 loc) · 4.17 KB
/
Copy pathbuild.ps1
File metadata and controls
132 lines (111 loc) · 4.17 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
126
127
128
129
130
131
132
# DownSort Build Script
# PowerShell script for building, testing, and packaging the application
param(
[Parameter()]
[ValidateSet('Debug', 'Release')]
[string]$Configuration = 'Release',
[Parameter()]
[switch]$SkipTests,
[Parameter()]
[switch]$Package
)
$ErrorActionPreference = "Stop"
Write-Host "====================================" -ForegroundColor Cyan
Write-Host " DownSort Build Script" -ForegroundColor Cyan
Write-Host "====================================" -ForegroundColor Cyan
Write-Host ""
# Variables
$SolutionFile = "DownSort.sln"
$OutputDir = ".\bin\$Configuration"
$PublishDir = ".\publish"
$ProjectName = "Downsort"
# Step 1: Clean
Write-Host "[1/5] Cleaning previous builds..." -ForegroundColor Yellow
if (Test-Path $OutputDir) {
Remove-Item -Path $OutputDir -Recurse -Force
}
if (Test-Path $PublishDir) {
Remove-Item -Path $PublishDir -Recurse -Force
}
dotnet clean $SolutionFile --configuration $Configuration
Write-Host "Clean completed successfully!" -ForegroundColor Green
Write-Host ""
# Step 2: Restore
Write-Host "[2/5] Restoring NuGet packages..." -ForegroundColor Yellow
dotnet restore $SolutionFile
if ($LASTEXITCODE -ne 0) {
Write-Host "Restore failed!" -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host "Restore completed successfully!" -ForegroundColor Green
Write-Host ""
# Step 3: Build
Write-Host "[3/5] Building solution..." -ForegroundColor Yellow
dotnet build $SolutionFile --configuration $Configuration --no-restore
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed!" -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host "Build completed successfully!" -ForegroundColor Green
Write-Host ""
# Step 4: Test
if (-not $SkipTests) {
Write-Host "[4/5] Running tests..." -ForegroundColor Yellow
dotnet test $SolutionFile --configuration $Configuration --no-build --verbosity normal `
--collect:"XPlat Code Coverage" `
--results-directory:".\TestResults"
if ($LASTEXITCODE -ne 0) {
Write-Host "Tests failed!" -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host "Tests completed successfully!" -ForegroundColor Green
Write-Host ""
# Display coverage summary
Write-Host "Code Coverage Report:" -ForegroundColor Cyan
Write-Host "Check .\TestResults folder for detailed coverage reports" -ForegroundColor Gray
Write-Host ""
} else {
Write-Host "[4/5] Skipping tests..." -ForegroundColor Gray
Write-Host ""
}
# Step 5: Publish
if ($Package) {
Write-Host "[5/5] Publishing application..." -ForegroundColor Yellow
# Publish for Windows x64
dotnet publish ".\$ProjectName\$ProjectName.csproj" `
--configuration $Configuration `
--runtime win-x64 `
--self-contained false `
--output "$PublishDir\win-x64" `
/p:PublishSingleFile=true `
/p:IncludeNativeLibrariesForSelfExtract=true
if ($LASTEXITCODE -ne 0) {
Write-Host "Publish failed!" -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host "Publish completed successfully!" -ForegroundColor Green
Write-Host "Output directory: $PublishDir\win-x64" -ForegroundColor Gray
Write-Host ""
# Create zip package
Write-Host "Creating distribution package..." -ForegroundColor Yellow
$Version = "1.0.0"
$ZipFile = "$PublishDir\DownSort-$Version-win-x64.zip"
Compress-Archive -Path "$PublishDir\win-x64\*" -DestinationPath $ZipFile -Force
Write-Host "Package created: $ZipFile" -ForegroundColor Green
} else {
Write-Host "[5/5] Skipping publish..." -ForegroundColor Gray
}
Write-Host ""
Write-Host "====================================" -ForegroundColor Cyan
Write-Host " Build Completed Successfully!" -ForegroundColor Green
Write-Host "====================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
Write-Host " - Run the application: dotnet run --project $ProjectName\$ProjectName.csproj" -ForegroundColor Gray
if (-not $SkipTests) {
Write-Host " - View test results: .\TestResults" -ForegroundColor Gray
}
if ($Package) {
Write-Host " - Distribution package: $ZipFile" -ForegroundColor Gray
}
Write-Host ""