-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
166 lines (142 loc) · 6.74 KB
/
Copy pathbuild.ps1
File metadata and controls
166 lines (142 loc) · 6.74 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
param(
[string]$Version = "",
[switch]$Package,
[switch]$SkipZip,
[string]$ArtifactsDir = ""
)
$ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot
try { & git config --local core.hooksPath .githooks 2>$null } catch {}
$BuildDir = Join-Path $PSScriptRoot "dist"
$StateFile = Join-Path $PSScriptRoot ".local_build_state.json"
$CreatePackage = $Package -and -not $SkipZip
if ($Version) {
if ($Version -notmatch '^\d{4}\.\d+\.\d+\.\d+(-([A-Fa-f0-9]{4}|beta))?$') {
throw "Invalid -Version '$Version'. Expected YYYY.M.D.N (release), YYYY.M.D.N-XXXX (dev), or YYYY.M.D.N-beta (prerelease)."
}
$FullVersion = $Version
}
else {
$Today = Get-Date -Format "yyyy.M.d"
$BuildCount = 0
if (Test-Path $StateFile) {
$State = Get-Content $StateFile | ConvertFrom-Json
if ($State.Date -eq $Today) { $BuildCount = [int]$State.Count + 1 }
}
$UID = [Guid]::NewGuid().ToString().Substring(0, 4).ToUpper()
$FullVersion = "$Today.$BuildCount-$UID"
@{ Date = $Today; Count = $BuildCount } | ConvertTo-Json | Out-File $StateFile -Encoding utf8
}
$AsmVersion = ($FullVersion -split '-')[0]
$VersionFile = Join-Path $PSScriptRoot "version.txt"
[System.IO.File]::WriteAllText($VersionFile, $FullVersion, [System.Text.UTF8Encoding]::new($false))
Write-Host "Building Version: $FullVersion" -ForegroundColor Magenta
if (Test-Path $BuildDir) { Remove-Item $BuildDir -Recurse -Force }
New-Item -ItemType Directory $BuildDir -Force | Out-Null
$gitSha = "<unknown>"
try {
$resolved = & git rev-parse --short=12 HEAD 2>$null
if ($LASTEXITCODE -eq 0 -and $resolved) { $gitSha = $resolved.Trim() }
}
catch { }
$gitDirty = ""
try {
$statusOut = & git status --porcelain 2>$null
if ($LASTEXITCODE -eq 0 -and $statusOut) { $gitDirty = "-dirty" }
}
catch { }
$buildTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
if ($env:GITHUB_ACTIONS -eq 'true') {
$isDev = $FullVersion -match '-'
}
else {
$isDev = ($FullVersion -match '-') -or ($gitDirty -ne "")
}
$isDevLiteral = if ($isDev) { "true" } else { "false" }
Write-Host "BuildInfo: GitSha=$gitSha$gitDirty BuildTime=$buildTime IsDevBuild=$isDevLiteral" -ForegroundColor DarkGray
$BuildInfoProps = @(
"/p:BuildInfoGitSha=$gitSha$gitDirty",
"/p:BuildInfoBuildTime=$buildTime",
"/p:BuildInfoIsDevBuild=$isDevLiteral"
)
Write-Host "`n--- Publishing ---" -ForegroundColor Cyan
$ProgFilesX86 = [Environment]::GetEnvironmentVariable('ProgramFiles(x86)')
$VsInstaller = Join-Path $ProgFilesX86 'Microsoft Visual Studio\Installer'
if (Test-Path (Join-Path $VsInstaller 'vswhere.exe')) {
if ($env:PATH -notlike "*$VsInstaller*") { $env:PATH = "$VsInstaller;$env:PATH" }
}
else {
Write-Warning "vswhere.exe not found at $VsInstaller -- AOT link step may fail. Install Visual Studio Build Tools with the Desktop C++ workload."
}
$AotPubArgs = @("-c", "Release", "-r", "win-x64", "--self-contained", "true",
"/p:Version=$AsmVersion",
"-o", $BuildDir, "--nologo")
$WatchdogPubArgs = $AotPubArgs + $BuildInfoProps
dotnet publish "src/VrcResolver/VrcResolver.csproj" @WatchdogPubArgs
if ($LASTEXITCODE -ne 0) { throw "VrcResolver publish failed" }
dotnet publish "src/VrcResolver.Updater/VrcResolver.Updater.csproj" @AotPubArgs
if ($LASTEXITCODE -ne 0) { throw "VrcResolver.Updater publish failed" }
$UpdaterExe = Join-Path $BuildDir "vrcresolver.Updater.exe"
if (Test-Path $UpdaterExe) {
Copy-Item $UpdaterExe (Join-Path $BuildDir "vrcresolver.Updater.next.exe") -Force
}
else {
throw "vrcresolver.Updater.exe missing after publish"
}
dotnet publish "src/VrcResolver.Uninstaller/VrcResolver.Uninstaller.csproj" @AotPubArgs
if ($LASTEXITCODE -ne 0) { throw "VrcResolver.Uninstaller publish failed" }
foreach ($StaleName in @("WKVRCProxy.exe", "WKVRCProxy.Updater.exe", "WKVRCProxy.Updater.next.exe")) {
$StalePath = Join-Path $BuildDir $StaleName
if (Test-Path $StalePath) { Remove-Item $StalePath -Force }
}
$BuildTools = Join-Path $BuildDir "tools"
New-Item -ItemType Directory $BuildTools -Force | Out-Null
$YtDlpPubArgs = @("-c", "Release", "-r", "win-x64", "--self-contained", "true",
"/p:Version=$AsmVersion",
"-o", $BuildTools, "--nologo")
dotnet publish "src/VrcResolver.YtDlp/VrcResolver.YtDlp.csproj" @YtDlpPubArgs
if ($LASTEXITCODE -ne 0) { throw "VrcResolver.YtDlp publish failed" }
$BuildData = Join-Path $BuildDir "data"
New-Item -ItemType Directory $BuildData -Force | Out-Null
$KnownHashesSrc = Join-Path $PSScriptRoot "data/wrapper_hashes.txt"
if (Test-Path $KnownHashesSrc) {
Copy-Item $KnownHashesSrc (Join-Path $BuildData "wrapper_hashes.txt") -Force
}
else {
Write-Warning "data/wrapper_hashes.txt missing from repo -- shipping empty list"
"" | Out-File (Join-Path $BuildData "wrapper_hashes.txt") -Encoding utf8 -NoNewline
}
Get-ChildItem $BuildDir -Filter "*.pdb" -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue
$InstallManifestPath = Join-Path $BuildData "release-manifest.tsv"
$InstallManifestLines = Get-ChildItem $BuildDir -Recurse -File |
Where-Object { $_.FullName -ne $InstallManifestPath } |
Sort-Object FullName |
ForEach-Object {
$relPath = $_.FullName.Substring($BuildDir.Length + 1) -replace '\\', '/'
$sha = (Get-FileHash $_.FullName -Algorithm SHA256).Hash
"$sha`t$($_.Length)`t$relPath"
}
[System.IO.File]::WriteAllLines($InstallManifestPath, [string[]]$InstallManifestLines, [System.Text.UTF8Encoding]::new($false))
if ($CreatePackage) {
$ArtifactRoot = if ($ArtifactsDir) { $ArtifactsDir } else { $BuildDir }
if (-not [System.IO.Path]::IsPathRooted($ArtifactRoot)) {
$ArtifactRoot = Join-Path $PSScriptRoot $ArtifactRoot
}
if (-not (Test-Path $ArtifactRoot)) { New-Item -ItemType Directory $ArtifactRoot -Force | Out-Null }
$ManifestPath = Join-Path $ArtifactRoot "vrcresolver-v$FullVersion.manifest.tsv"
$ZipPath = Join-Path $ArtifactRoot "vrcresolver-v$FullVersion.zip"
if (Test-Path $ZipPath) { Remove-Item $ZipPath -Force }
$PackageFiles = Get-ChildItem $BuildDir -Recurse -File |
Sort-Object FullName
$manifestLines = $PackageFiles | ForEach-Object {
$relPath = $_.FullName.Substring($BuildDir.Length + 1) -replace '\\', '/'
$sha = (Get-FileHash $_.FullName -Algorithm SHA256).Hash
"$sha`t$($_.Length)`t$relPath"
}
$PackageInputs = Get-ChildItem $BuildDir -Force | ForEach-Object { $_.FullName }
[System.IO.File]::WriteAllLines($ManifestPath, [string[]]$manifestLines, [System.Text.UTF8Encoding]::new($false))
Write-Host "Manifest: $ManifestPath ($($manifestLines.Count) files)" -ForegroundColor Cyan
Compress-Archive -Path $PackageInputs -DestinationPath $ZipPath
Write-Host "`nRelease zip: $ZipPath" -ForegroundColor Green
}
Write-Host "`nBuild complete: v$FullVersion" -ForegroundColor Green