-
-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathbuild.ps1
More file actions
210 lines (171 loc) · 7.79 KB
/
build.ps1
File metadata and controls
210 lines (171 loc) · 7.79 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Builds the ARK Breeding Stats solution.
.PARAMETER Configuration
Build configuration (Debug or Release). Default is Debug.
.PARAMETER Clean
Perform a clean build.
.PARAMETER SkipTests
Skip running tests after a successful build.
.EXAMPLE
.\build.ps1
.\build.ps1 -Configuration Release
.\build.ps1 -Clean
.\build.ps1 -SkipTests
#>
param(
[ValidateSet('Debug', 'Release')]
[string]$Configuration = 'Debug',
[switch]$Clean,
[switch]$SkipTests
)
$ErrorActionPreference = 'Stop'
$RepoRoot = $PSScriptRoot
$WorkPath = Join-Path $RepoRoot '.work'
New-Item -ItemType Directory -Path $WorkPath -ErrorAction SilentlyContinue | Out-Null
# Pinned Inno Setup version — update here to upgrade
$InnoSetupVersion = '6.7.1'
# ── Tool discovery ────────────────────────────────────────────────────────────
function Get-InnoSetup {
# 1. System install
$iscc = Get-Command 'ISCC.exe' -ErrorAction SilentlyContinue
if ($iscc) { return $iscc.Path }
$InnoSetupDir = Join-Path $WorkPath 'innosetup'
$InnoSetupExe = Join-Path $InnoSetupDir 'ISCC.exe'
# 2. Already downloaded locally
if (Test-Path $InnoSetupExe) { return $InnoSetupExe }
# 3. Download from GitHub releases and install to local tools folder
$tag = "is-$($InnoSetupVersion.Replace('.', '_'))"
$url = "https://github.com/jrsoftware/issrc/releases/download/$tag/innosetup-$InnoSetupVersion.exe"
$installer = Join-Path $WorkPath "innosetup-$InnoSetupVersion.exe"
Write-Host " Downloading Inno Setup $InnoSetupVersion..." -ForegroundColor Gray
Invoke-WebRequest -Uri $url -OutFile $installer -UseBasicParsing
Write-Host " Installing Inno Setup to $InnoSetupDir ..." -ForegroundColor Gray
& $installer /VERYSILENT /SUPPRESSMSGBOXES /NORESTART "/DIR=$InnoSetupDir"
if ($LASTEXITCODE -ne 0) {
Write-Error "Inno Setup installation failed (exit $LASTEXITCODE)."
exit 1
}
return $InnoSetupExe
}
# ── Build steps ───────────────────────────────────────────────────────────────
function Invoke-GenerateManifest {
Write-Host "`nGenerating _manifest.json..." -ForegroundColor Gray
$projectDir = Join-Path $PSScriptRoot 'ARKBreedingStats'
$project = Join-Path $projectDir 'ARKBreedingStats.csproj'
$asbVersion = (dotnet msbuild $project -getProperty:FileVersion).Trim()
$namePatterns = Get-Content (Join-Path $projectDir 'json\namePatternTemplates.json') -Raw
$npVersion = [regex]::Match($namePatterns, '"version"\s*:\s*"([\d.]+)"').Groups[1].Value
$imagePacks = Get-Content (Join-Path $projectDir 'json\imagePacks.json') -Raw
$ipVersion = [regex]::Match($imagePacks, '"version"\s*:\s*"([\d.]+)"').Groups[1].Value
$manifest = @"
{
"format": "1.0",
"modules":{
"ARK Smart Breeding": {
"version": "$asbVersion"
},
"NamePatternTemplates": {
"Category": "Name Pattern Templates",
"Name": "Name Pattern Templates",
"Description": "Templates for naming patterns",
"Url": "https://raw.githubusercontent.com/cadon/ARKStatsExtractor/refs/heads/master/ARKBreedingStats/json/namePatternTemplates.json",
"LocalPath": "json/namePatternTemplates.json",
"optional": true,
"version": "$npVersion"
},
"SpeciesImagePacks": {
"Category": "Images",
"Name": "Species image packs",
"Url": "https://raw.githubusercontent.com/cadon/ARKStatsExtractor/refs/heads/master/ARKBreedingStats/json/imagePacks.json",
"LocalPath": "json/imagePacks.json",
"version": "$ipVersion"
}
}
}
"@
[System.IO.File]::WriteAllText(
(Join-Path $projectDir '_manifest.json'),
$manifest.TrimStart(),
[System.Text.Encoding]::UTF8)
Write-Host " version=$asbVersion namePatterns=$npVersion imagePacks=$ipVersion" -ForegroundColor Gray
}
function Invoke-Build {
$solution = Join-Path $PSScriptRoot "ARKBreedingStats.sln"
if (-not (Test-Path $solution)) {
Write-Error "Solution file not found: $solution"
exit 1
}
$cleanArgs = if ($Clean) { @('--no-incremental') } else { @() }
Write-Host "`nBuilding solution..." -ForegroundColor Gray
dotnet build $solution --configuration $Configuration @cleanArgs
if ($LASTEXITCODE -ne 0) {
Write-Host "`n=== Build Failed ===" -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host "`n=== Build Succeeded ===" -ForegroundColor Green
}
function Invoke-PackageRelease {
$project = Join-Path $PSScriptRoot "ARKBreedingStats\ARKBreedingStats.csproj"
$publishDir = Join-Path $WorkPath "dist"
$outputDir = Join-Path $WorkPath "publish"
# dotnet publish (vs build) resolves runtime-specific NuGet assets and writes a clean
# deps.json that works on machines without a local NuGet package cache.
# Note: --no-build is intentionally omitted so publish can flatten runtime-specific
# assets (e.g. runtimes/win/lib/net10.0/) into the output directory correctly.
Write-Host "`nPublishing..." -ForegroundColor Gray
dotnet publish $project --configuration Release --output "$publishDir"
if ($LASTEXITCODE -ne 0) {
Write-Host "`n=== Publish Failed ===" -ForegroundColor Red
exit $LASTEXITCODE
}
# Publish updater as single-file exe
$updaterProject = Join-Path $PSScriptRoot "ASB-Updater\ASB Updater.csproj"
Write-Host "`nPublishing updater (single-file)..." -ForegroundColor Gray
dotnet publish $updaterProject --configuration Release --output "$publishDir"
if ($LASTEXITCODE -ne 0) {
Write-Host "`n=== Updater Publish Failed ===" -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host "`nPackaging release..." -ForegroundColor Cyan
Get-ChildItem $publishDir -Filter *.pdb | Remove-Item -Force
Get-ChildItem $publishDir -Filter *.xml | Remove-Item -Force
$version = (Get-Item (Join-Path $publishDir "ARK Smart Breeding.exe")).VersionInfo.FileVersion
if (-not (Test-Path $outputDir)) { New-Item -ItemType Directory -Path $outputDir | Out-Null }
$zipPath = Join-Path $outputDir "ARK.Smart.Breeding_$version.zip"
Compress-Archive -Force -Path "$publishDir\*" -DestinationPath $zipPath
Write-Host " Created: $zipPath" -ForegroundColor Green
$iscc = Get-InnoSetup
Write-Host " Running Inno Setup..." -ForegroundColor Gray
& $iscc (Join-Path $PSScriptRoot "setup.iss")
if ($LASTEXITCODE -ne 0) {
Write-Host "`n=== Installer Build Failed ===" -ForegroundColor Red
exit $LASTEXITCODE
}
}
function Invoke-Tests {
$testProject = Join-Path $PSScriptRoot "ARKBreedingStats.Tests\ARKBreedingStats.Tests.csproj"
Write-Host "`nRunning tests..." -ForegroundColor Gray
dotnet test $testProject --no-build --configuration $Configuration --logger "console;verbosity=normal"
if ($LASTEXITCODE -ne 0) {
Write-Host "`n=== Tests Failed ===" -ForegroundColor Red
exit $LASTEXITCODE
}
Write-Host "`n=== Tests Passed ===" -ForegroundColor Green
}
# ── Main ──────────────────────────────────────────────────────────────────────
Write-Host "=== ARK Breeding Stats Build Script ===" -ForegroundColor Cyan
Write-Host "Configuration: $Configuration" -ForegroundColor Gray
Invoke-GenerateManifest
Invoke-Build
if ($Configuration -eq 'Release') {
Invoke-PackageRelease
}
if (-not $SkipTests) {
Invoke-Tests
}
else {
Write-Host "Skipping tests (-SkipTests specified)." -ForegroundColor Gray
}
exit 0