-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathbuild-all-versions.ps1
More file actions
404 lines (330 loc) · 11.7 KB
/
Copy pathbuild-all-versions.ps1
File metadata and controls
404 lines (330 loc) · 11.7 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
param(
[string]$RepoRoot = ".",
[switch]$SkipUi,
[switch]$NoMerge,
[string]$SourceBranch
)
$ErrorActionPreference = "Stop"
# --- Configuration ------------------------------------------------------------
$branches = @(
@{ Branch = "master"; Version = "1.29.1" },
@{ Branch = "ssl-tauri-discord-1.34.2"; Version = "1.34.2" },
# @{ Branch = "ssl-tauri-discord-1.37.0"; Version = "1.37.0" },
@{ Branch = "ssl-tauri-discord-1.39.1"; Version = "1.39.1" },
@{ Branch = "ssl-tauri-discord-1.40.8"; Version = "1.40.8" },
@{ Branch = "ssl-tauri-discord-1.41.1"; Version = "1.41.1" },
@{ Branch = "ssl-tauri-discord-1.42.0"; Version = "1.42.0" }
)
$repoRoot = (Resolve-Path $RepoRoot).Path
$uiDir = Join-Path $repoRoot "TournamentAssistantUI"
$pluginDir = Join-Path $repoRoot "TournamentAssistant"
$pluginProject = Join-Path $pluginDir "TournamentAssistant.csproj"
$pluginUserFile = Join-Path $pluginDir "TournamentAssistant.csproj.user"
$artifactsRoot = Join-Path $repoRoot "Artifacts"
# Adjust if your Beat Saber installations live somewhere else
$beatSaberBaseDir = "O:\BSManager\BSInstances"
# Tauri output locations
$uiWebBuildDir = Join-Path $uiDir "build"
$tauriExePath = Join-Path $uiDir "src-tauri\target\release\taui.exe"
# Plugin output guesses. We'll probe these in order.
$pluginOutputCandidates = @(
(Join-Path $pluginDir "bin\Release\TournamentAssistant.dll"),
(Join-Path $pluginDir "bin\Release\net472\TournamentAssistant.dll"),
(Join-Path $pluginDir "bin\Release\net48\TournamentAssistant.dll"),
(Join-Path $pluginDir "bin\Release\net462\TournamentAssistant.dll")
)
# --- Helpers -----------------------------------------------------------------
function Write-Section {
param([string]$Message)
Write-Host ""
Write-Host "==== $Message ====" -ForegroundColor Cyan
}
function Require-Command {
param([string]$CommandName)
if (-not (Get-Command $CommandName -ErrorAction SilentlyContinue)) {
throw "Required command not found: $CommandName"
}
}
function Run-Step {
param(
[string]$WorkingDirectory,
[string]$FilePath,
[string[]]$Arguments = @()
)
Write-Host "[$WorkingDirectory] $FilePath $($Arguments -join ' ')"
Push-Location $WorkingDirectory
try {
& $FilePath @Arguments
if ($LASTEXITCODE -ne 0) {
throw "Command failed with exit code $LASTEXITCODE"
}
}
finally {
Pop-Location
}
}
function Ensure-Directory {
param([string]$Path)
if (-not (Test-Path $Path)) {
New-Item -ItemType Directory -Path $Path | Out-Null
}
}
function Clear-Directory {
param([string]$Path)
if (Test-Path $Path) {
Remove-Item $Path -Recurse -Force
}
New-Item -ItemType Directory -Path $Path | Out-Null
}
function Set-BeatSaberDir {
param(
[string]$UserFilePath,
[string]$BeatSaberDir
)
if (-not (Test-Path $UserFilePath)) {
throw "Could not find $UserFilePath"
}
$content = Get-Content $UserFilePath -Raw
if ($content -match '<BeatSaberDir>.*?</BeatSaberDir>') {
$escapedDir = [System.Security.SecurityElement]::Escape($BeatSaberDir)
$content = [regex]::Replace(
$content,
'<BeatSaberDir>.*?</BeatSaberDir>',
"<BeatSaberDir>$escapedDir</BeatSaberDir>",
[System.Text.RegularExpressions.RegexOptions]::Singleline
)
}
else {
$escapedDir = [System.Security.SecurityElement]::Escape($BeatSaberDir)
if ($content -match '</PropertyGroup>') {
$content = [regex]::Replace(
$content,
'</PropertyGroup>',
" <BeatSaberDir>$escapedDir</BeatSaberDir>`r`n</PropertyGroup>",
[System.Text.RegularExpressions.RegexOptions]::Singleline,
1
)
}
else {
$content = @"
<Project>
<PropertyGroup>
<BeatSaberDir>$escapedDir</BeatSaberDir>
</PropertyGroup>
</Project>
"@
}
}
Set-Content -Path $UserFilePath -Value $content -Encoding UTF8
Write-Host "Updated BeatSaberDir -> $BeatSaberDir" -ForegroundColor Yellow
}
function Resolve-PluginOutput {
param([string[]]$Candidates)
foreach ($candidate in $Candidates) {
if (Test-Path $candidate) {
return $candidate
}
}
$binDir = Join-Path $pluginDir "bin"
if (Test-Path $binDir) {
$dll = Get-ChildItem -Path $binDir -Recurse -File -Filter "TournamentAssistant.dll" |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if ($dll) {
return $dll.FullName
}
}
throw "Could not find built TournamentAssistant.dll under $binDir"
}
function Get-CurrentBranch {
Push-Location $repoRoot
try {
$branch = (& git branch --show-current).Trim()
if (-not $branch) {
throw "Failed to determine current branch."
}
return $branch
}
finally {
Pop-Location
}
}
function Copy-DirectoryContents {
param(
[string]$SourceDir,
[string]$DestinationDir
)
Ensure-Directory $DestinationDir
Copy-Item (Join-Path $SourceDir "*") $DestinationDir -Recurse -Force
}
function Restore-TrackedBuildChanges {
Push-Location $repoRoot
try {
& git restore --worktree -- .
if ($LASTEXITCODE -ne 0) {
throw "Failed to restore tracked build changes in the repository."
}
$submodulePaths = (& git config --file .gitmodules --get-regexp path 2>$null) |
ForEach-Object { ($_ -split '\s+', 2)[1] }
foreach ($submodulePath in $submodulePaths) {
$fullPath = Join-Path $repoRoot $submodulePath
if (-not (Test-Path $fullPath)) {
continue
}
Push-Location $fullPath
try {
& git restore --worktree -- .
if ($LASTEXITCODE -ne 0) {
throw "Failed to restore tracked build changes in submodule $submodulePath."
}
}
finally {
Pop-Location
}
}
}
finally {
Pop-Location
}
}
# --- Validation ---------------------------------------------------------------
Write-Section "Validating prerequisites"
Require-Command "git"
Require-Command "npm"
Require-Command "dotnet"
if (-not (Test-Path $uiDir)) { throw "Missing UI directory: $uiDir" }
if (-not (Test-Path $pluginProject)) { throw "Missing plugin project: $pluginProject" }
if (-not (Test-Path $pluginUserFile)) { throw "Missing plugin user file: $pluginUserFile" }
Push-Location $repoRoot
try {
$status = (& git status --porcelain)
if ($status) {
throw "Working tree is not clean. Please commit/stash changes before running this script."
}
& git fetch --all --prune
if ($LASTEXITCODE -ne 0) {
throw "git fetch failed."
}
}
finally {
Pop-Location
}
$currentBranch = Get-CurrentBranch
$resolvedSourceRef = if ([string]::IsNullOrWhiteSpace($SourceBranch)) { $currentBranch } else { $SourceBranch }
Push-Location $repoRoot
try {
$sourceCommit = (& git rev-parse --verify "$resolvedSourceRef^{commit}").Trim()
if ($LASTEXITCODE -ne 0 -or -not $sourceCommit) {
throw "Failed to resolve source ref: $resolvedSourceRef"
}
}
finally {
Pop-Location
}
Write-Host "Starting branch: $currentBranch"
Write-Host "Build source: $resolvedSourceRef ($sourceCommit)"
# Version builds use detached HEADs, so temporary merges never advance or update
# the named version branches. This script intentionally never pushes any refs.
try {
Clear-Directory $artifactsRoot
# --- Build UI once from the selected source ----------------------------------
if (-not $SkipUi) {
Write-Section "Building UI from $resolvedSourceRef"
Push-Location $repoRoot
try {
& git checkout --detach $sourceCommit
if ($LASTEXITCODE -ne 0) { throw "Failed to checkout source commit $sourceCommit" }
}
finally {
Pop-Location
}
$uiArtifactsDir = Join-Path $artifactsRoot "UI"
$uiWebArtifactsDir = Join-Path $uiArtifactsDir "Website"
$uiDesktopArtifactsDir = Join-Path $uiArtifactsDir "Desktop"
Ensure-Directory $uiArtifactsDir
Ensure-Directory $uiWebArtifactsDir
Ensure-Directory $uiDesktopArtifactsDir
Run-Step -WorkingDirectory $uiDir -FilePath "powershell" -Arguments @("-ExecutionPolicy", "Bypass", "-File", ".\build_protos.ps1")
Run-Step -WorkingDirectory $uiDir -FilePath "npm" -Arguments @("install")
Run-Step -WorkingDirectory $uiDir -FilePath "npm" -Arguments @("run", "build")
if (-not (Test-Path $uiWebBuildDir)) {
throw "UI web build output not found: $uiWebBuildDir"
}
Copy-DirectoryContents -SourceDir $uiWebBuildDir -DestinationDir $uiWebArtifactsDir
Write-Host "Copied website build -> $uiWebArtifactsDir" -ForegroundColor Green
Run-Step -WorkingDirectory $uiDir -FilePath "npm" -Arguments @("run", "tauri", "build")
if (-not (Test-Path $tauriExePath)) {
throw "Tauri exe not found: $tauriExePath"
}
Copy-Item $tauriExePath (Join-Path $uiDesktopArtifactsDir "taui.exe") -Force
Write-Host "Copied desktop build -> $uiDesktopArtifactsDir\taui.exe" -ForegroundColor Green
Restore-TrackedBuildChanges
}
# --- Build plugin for each game version --------------------------------------
Write-Section "Building plugin for all versions"
foreach ($entry in $branches) {
$branch = $entry.Branch
$version = $entry.Version
$beatSaberDir = Join-Path $beatSaberBaseDir $version
$pluginArtifactsDir = Join-Path $artifactsRoot "Plugin"
Ensure-Directory $pluginArtifactsDir
Write-Section "Branch: $branch | Version: $version"
Push-Location $repoRoot
try {
& git checkout --detach $branch
if ($LASTEXITCODE -ne 0) { throw "Failed to checkout $branch in detached mode" }
$versionCommit = (& git rev-parse HEAD).Trim()
if ((-not $NoMerge) -and ($versionCommit -ne $sourceCommit)) {
& git merge --no-edit $sourceCommit
if ($LASTEXITCODE -ne 0) {
throw "Temporary merge of $resolvedSourceRef into $branch failed"
}
}
}
finally {
Pop-Location
}
if (-not (Test-Path $beatSaberDir)) {
throw "Beat Saber directory does not exist for $version : $beatSaberDir"
}
Set-BeatSaberDir -UserFilePath $pluginUserFile -BeatSaberDir $beatSaberDir
# Clean old outputs so we don't accidentally grab a stale dll
$pluginBinDir = Join-Path $pluginDir "bin"
if (Test-Path $pluginBinDir) {
Remove-Item $pluginBinDir -Recurse -Force
}
Run-Step -WorkingDirectory $repoRoot -FilePath "dotnet" -Arguments @("build", $pluginProject, "-c", "Release")
$builtDll = Resolve-PluginOutput -Candidates $pluginOutputCandidates
$artifactDllName = "TournamentAssistant_$version.dll"
$artifactDllPath = Join-Path $pluginArtifactsDir $artifactDllName
Copy-Item $builtDll $artifactDllPath -Force
Write-Host "Copied plugin -> $artifactDllPath" -ForegroundColor Green
Restore-TrackedBuildChanges
}
Write-Section "Done"
Write-Host "Artifacts written to: $artifactsRoot" -ForegroundColor Green
}
finally {
Write-Section "Restoring original branch"
Push-Location $repoRoot
try {
& git rev-parse -q --verify MERGE_HEAD *> $null
if ($LASTEXITCODE -eq 0) {
& git merge --abort
}
}
finally {
Pop-Location
}
Restore-TrackedBuildChanges
Push-Location $repoRoot
try {
& git checkout $currentBranch
if ($LASTEXITCODE -ne 0) {
throw "Failed to restore original branch: $currentBranch"
}
}
finally {
Pop-Location
}
}