|
1 | | -# Local deployment script for ModVerify to test the update feature. |
2 | | -# This script builds the application twice at different versions, creates an update manifest |
3 | | -# for the newer one, and stages an "installed" copy of the older one — so triggering the |
4 | | -# update flow against the local server actually finds an update. |
| 1 | +# ========================================================================================= |
| 2 | +# Local deployment to test the ModVerify update flow end-to-end. |
| 3 | +# |
| 4 | +# USAGE |
| 5 | +# .\deploy-local.ps1 # single-channel test |
| 6 | +# .\deploy-local.ps1 -DualPublish # also publish to a next-gen channel |
| 7 | +# .\deploy-local.ps1 -DualPublish -CompatibilityUpdater <path> |
| 8 | +# # primary uses compat updater; |
| 9 | +# # next-gen uses build-output updater |
| 10 | +# |
| 11 | +# -CompatibilityUpdater requires -DualPublish. |
| 12 | +# -InstalledVersion / -ServerVersion override the version pair used to set up the test. |
| 13 | +# |
| 14 | +# Builds ModVerify twice (older "installed" + newer "server"), then hands off to the shared |
| 15 | +# Publish-LocalRelease.ps1 in ModdingToolBase for cert generation, manifest signing, and |
| 16 | +# install-dir staging. |
| 17 | +# ========================================================================================= |
5 | 18 |
|
6 | 19 | param( |
7 | | - # Version baked into the "already installed" copy. Must be lower than $ServerVersion |
8 | | - # so the updater treats the server build as newer. |
9 | 20 | [string]$InstalledVersion = "0.0.1-local", |
10 | | - |
11 | | - # Version baked into the build that ends up on the local "server" / in the manifest. |
12 | | - [string]$ServerVersion = "0.0.2-local" |
| 21 | + [string]$ServerVersion = "99.99.99-local", |
| 22 | + [switch]$DualPublish, |
| 23 | + [string]$CompatibilityUpdater |
13 | 24 | ) |
14 | 25 |
|
15 | 26 | $ErrorActionPreference = "Stop" |
16 | 27 |
|
17 | 28 | $root = $PSScriptRoot |
18 | 29 | if ([string]::IsNullOrEmpty($root)) { $root = Get-Location } |
19 | 30 |
|
20 | | -$deployRoot = Join-Path $root ".local_deploy" |
21 | | -$stagingDir = Join-Path $deployRoot "staging" |
22 | | -$serverDir = Join-Path $deployRoot "server" |
23 | | -$installDir = Join-Path $deployRoot "install" |
24 | | - |
25 | | -$toolProj = Join-Path $root "src\ModVerify.CliApp\ModVerify.CliApp.csproj" |
26 | | -$creatorProj = Join-Path $root "modules\ModdingToolBase\src\AnakinApps\ApplicationManifestCreator\ApplicationManifestCreator.csproj" |
27 | | -$signerProj = Join-Path $root "modules\ModdingToolBase\src\AnakinApps\ApplicationManifestSigner\ApplicationManifestSigner.csproj" |
28 | | -$uploaderProj = Join-Path $root "modules\ModdingToolBase\src\AnakinApps\FtpUploader\FtpUploader.csproj" |
29 | | - |
30 | | -$toolExe = "ModVerify.exe" |
31 | | -$updaterExe = "AnakinRaW.ExternalUpdater.exe" |
32 | | -$manifestCreatorDll = "AnakinRaW.ApplicationManifestCreator.dll" |
33 | | -$manifestSignerDll = "AnakinRaW.ApplicationManifestSigner.dll" |
34 | | -$uploaderDll = "AnakinRaW.FtpUploader.dll" |
| 31 | +. (Join-Path $root "modules\ModdingToolBase\scripts\NbgvVersion.ps1") |
35 | 32 |
|
36 | | -$devPfx = Join-Path $deployRoot "dev-signing.pfx" |
37 | | -$devCer = Join-Path $deployRoot "dev-trust.cer" |
38 | | -$devPwd = "devpass" |
| 33 | +$deployRoot = Join-Path $root ".local_deploy" |
| 34 | +$installBuildDir = Join-Path $deployRoot "bin\install" |
| 35 | +$serverBuildDir = Join-Path $deployRoot "bin\tool" |
39 | 36 |
|
40 | | -$versionJsonPath = Join-Path $root "version.json" |
41 | | -$versionJsonBackup = [IO.File]::ReadAllText($versionJsonPath) |
42 | | - |
43 | | -function Set-NbgvVersion { |
44 | | - param([string]$Version) |
45 | | - $json = $versionJsonBackup | ConvertFrom-Json |
46 | | - $json.version = $Version |
47 | | - # publicReleaseRefSpec defaults the build to non-public; clearing it gives us a clean |
48 | | - # "X.Y.Z" InformationalVersion locally without the +gitHash height suffix making |
49 | | - # comparisons noisier than they need to be. |
50 | | - if ($json.PSObject.Properties.Name -contains 'publicReleaseRefSpec') { |
51 | | - $json.publicReleaseRefSpec = @() |
52 | | - } |
53 | | - ($json | ConvertTo-Json -Depth 32) | Set-Content -Path $versionJsonPath -Encoding UTF8 |
54 | | -} |
| 37 | +$toolProj = Join-Path $root "src\ModVerify.CliApp\ModVerify.CliApp.csproj" |
| 38 | +$baseScript = Join-Path $root "modules\ModdingToolBase\scripts\Publish-LocalRelease.ps1" |
55 | 39 |
|
56 | | -try { |
57 | | - |
58 | | -# 1. Clean and Create directories |
59 | 40 | if (Test-Path $deployRoot) { Remove-Item -Recurse -Force $deployRoot } |
60 | | -New-Item -ItemType Directory -Path $stagingDir | Out-Null |
61 | | -New-Item -ItemType Directory -Path $serverDir | Out-Null |
62 | | -New-Item -ItemType Directory -Path $installDir | Out-Null |
63 | | - |
64 | | -Write-Host "--- Building ModVerify (net481) @ installed v$InstalledVersion ---" -ForegroundColor Cyan |
65 | | -Set-NbgvVersion -Version $InstalledVersion |
66 | | -dotnet build $toolProj --configuration Release -f net481 --output "$deployRoot\bin\install" /p:DebugType=None /p:DebugSymbols=false /p:LocalDeploy=true |
67 | | - |
68 | | -Write-Host "--- Building ModVerify (net481) @ server v$ServerVersion ---" -ForegroundColor Cyan |
69 | | -Set-NbgvVersion -Version $ServerVersion |
70 | | -dotnet build $toolProj --configuration Release -f net481 --output "$deployRoot\bin\tool" /p:DebugType=None /p:DebugSymbols=false /p:LocalDeploy=true |
71 | | - |
72 | | -Write-Host "--- Building Manifest Creator ---" -ForegroundColor Cyan |
73 | | -dotnet build $creatorProj --configuration Release --output "$deployRoot\bin\creator" |
| 41 | +New-Item -ItemType Directory -Path $deployRoot | Out-Null |
74 | 42 |
|
75 | | -Write-Host "--- Building Manifest Signer ---" -ForegroundColor Cyan |
76 | | -dotnet build $signerProj --configuration Release --output "$deployRoot\bin\signer" |
77 | | - |
78 | | -Write-Host "--- Building Local Uploader ---" -ForegroundColor Cyan |
79 | | -dotnet build $uploaderProj --configuration Release --output "$deployRoot\bin\uploader" |
80 | | - |
81 | | -Write-Host "--- Generating dev signing cert ---" -ForegroundColor Cyan |
82 | | -$curve = [System.Security.Cryptography.ECCurve]::CreateFromFriendlyName("nistP256") |
83 | | -$ecdsa = [System.Security.Cryptography.ECDsa]::Create($curve) |
84 | | -$req = [System.Security.Cryptography.X509Certificates.CertificateRequest]::new( |
85 | | - "CN=ModVerify Dev Signing", |
86 | | - $ecdsa, |
87 | | - [System.Security.Cryptography.HashAlgorithmName]::SHA256) |
88 | | -$cert = $req.CreateSelfSigned( |
89 | | - [DateTimeOffset]::UtcNow.AddDays(-1), |
90 | | - [DateTimeOffset]::UtcNow.AddYears(10)) |
91 | | -[IO.File]::WriteAllBytes($devPfx, $cert.Export( |
92 | | - [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx, $devPwd)) |
93 | | -[IO.File]::WriteAllBytes($devCer, $cert.Export( |
94 | | - [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert)) |
95 | | -$cert.Dispose() |
96 | | -$ecdsa.Dispose() |
97 | | - |
98 | | -# 2. Prepare staging |
99 | | -Write-Host "--- Preparing Staging ---" -ForegroundColor Cyan |
100 | | -Copy-Item "$deployRoot\bin\tool\$toolExe" $stagingDir |
101 | | -Copy-Item "$deployRoot\bin\tool\$updaterExe" $stagingDir |
102 | | - |
103 | | -# 3. Create Manifest |
104 | | -# Origin must be an absolute URI for the manifest creator. |
105 | | -# Using 127.0.0.1 and file:// is tricky with Flurl/DownloadManager sometimes. |
106 | | -# We'll use the local path and ensure it's formatted correctly. |
107 | | -$serverPath = (Resolve-Path $serverDir).Path |
108 | | -$serverUri = "file:///$($serverPath.Replace('\', '/'))" |
109 | | -# If we have 3 slashes, Flurl/DownloadManager might still fail on Windows if it expects a certain format. |
110 | | -# However, the ManifestCreator just needs a valid URI for the 'Origin' field in the manifest. |
111 | | -Write-Host "--- Creating Manifest (Origin: $serverUri) ---" -ForegroundColor Cyan |
112 | | -dotnet "$deployRoot\bin\creator\$manifestCreatorDll" ` |
113 | | - -a "$stagingDir\$toolExe" ` |
114 | | - --appDataFiles "$stagingDir\$updaterExe" ` |
115 | | - --origin "$serverUri" ` |
116 | | - -o "$stagingDir" ` |
117 | | - -b "beta" |
118 | | - |
119 | | -Write-Host "--- Signing Manifest ---" -ForegroundColor Cyan |
120 | | -dotnet "$deployRoot\bin\signer\$manifestSignerDll" ` |
121 | | - --manifest "$stagingDir\manifest.json" ` |
122 | | - --pfx $devPfx ` |
123 | | - --password $devPwd |
124 | | - |
125 | | -# 4. "Deploy" to server using the local uploader |
126 | | -Write-Host "--- Deploying to Local Server ---" -ForegroundColor Cyan |
127 | | -dotnet "$deployRoot\bin\uploader\$uploaderDll" local --base "$serverDir" --source "$stagingDir" |
128 | | - |
129 | | -# 5. Setup a "test" installation — uses the older-version build so the updater sees the |
130 | | -# staged server build as an upgrade. |
131 | | -Write-Host "--- Setting up Test Installation (v$InstalledVersion) ---" -ForegroundColor Cyan |
132 | | -Copy-Item "$deployRoot\bin\install\*" $installDir -Recurse |
133 | | - |
134 | | -Write-Host "`nLocal deployment complete!" -ForegroundColor Green |
135 | | -Write-Host "Installed version: $InstalledVersion" |
136 | | -Write-Host "Server version: $ServerVersion" |
137 | | -Write-Host "Server directory: $serverDir" |
138 | | -Write-Host "Install directory: $installDir" |
139 | | -Write-Host "`nTo test the update:" |
140 | | -Write-Host "1. Run ModVerify from the install directory with the following command:" |
141 | | -Write-Host " cd '$installDir'" |
142 | | -Write-Host " .\ModVerify.exe updateApplication --updateBranch beta --updateServerUrl '$serverUri'" |
143 | | -Write-Host "`n Note: --updateServerUrl takes a server base URL and resolves to <server>/<branch>/manifest.json." |
144 | | -Write-Host " Use --updateManifestUrl instead if you want to point directly at a full manifest URL." |
145 | | -Write-Host "`n2. To re-test, just rerun this script — every run produces v$InstalledVersion installed against v$ServerVersion on the server." |
146 | | -Write-Host " Override with -InstalledVersion / -ServerVersion to exercise other version transitions." |
| 43 | +$nbgv = Backup-NbgvVersion -RepoRoot $root |
| 44 | +try { |
| 45 | + Write-Host "--- Building ModVerify (net481) @ installed v$InstalledVersion ---" -ForegroundColor Cyan |
| 46 | + Set-NbgvVersion -Snapshot $nbgv -Version $InstalledVersion |
| 47 | + dotnet build $toolProj --configuration Release -f net481 --output $installBuildDir /p:DebugType=None /p:DebugSymbols=false /p:LocalDeploy=true |
| 48 | + |
| 49 | + Write-Host "--- Building ModVerify (net481) @ server v$ServerVersion ---" -ForegroundColor Cyan |
| 50 | + Set-NbgvVersion -Snapshot $nbgv -Version $ServerVersion |
| 51 | + dotnet build $toolProj --configuration Release -f net481 --output $serverBuildDir /p:DebugType=None /p:DebugSymbols=false /p:LocalDeploy=true |
| 52 | + |
| 53 | + $publishParams = @{ |
| 54 | + AppExePath = Join-Path $serverBuildDir "ModVerify.exe" |
| 55 | + UpdaterExePath = Join-Path $serverBuildDir "AnakinRaW.ExternalUpdater.exe" |
| 56 | + DeployRoot = $deployRoot |
| 57 | + InstallBuildDir = $installBuildDir |
| 58 | + Branch = "beta" |
| 59 | + } |
| 60 | + if ($DualPublish) { $publishParams.DualPublish = $true } |
| 61 | + if ($CompatibilityUpdater) { $publishParams.CompatibilityUpdater = $CompatibilityUpdater } |
147 | 62 |
|
| 63 | + & $baseScript @publishParams |
148 | 64 | } |
149 | 65 | finally { |
150 | | - # Always restore version.json verbatim (bytes-in == bytes-out), even if a build step above failed. |
151 | | - [IO.File]::WriteAllText($versionJsonPath, $versionJsonBackup) |
| 66 | + Restore-NbgvVersion -Snapshot $nbgv |
152 | 67 | } |
0 commit comments