bundle-windows.ps1

  1[CmdletBinding()]
  2Param(
  3    [Parameter()][Alias('i')][switch]$Install,
  4    [Parameter()][Alias('h')][switch]$Help,
  5    [Parameter()][string]$Name
  6)
  7
  8. "$PSScriptRoot/lib/blob-store.ps1"
  9. "$PSScriptRoot/lib/workspace.ps1"
 10
 11# https://stackoverflow.com/questions/57949031/powershell-script-stops-if-program-fails-like-bash-set-o-errexit
 12$ErrorActionPreference = 'Stop'
 13$PSNativeCommandUseErrorActionPreference = $true
 14
 15$buildSuccess = $false
 16
 17if ($Help) {
 18    Write-Output "Usage: test.ps1 [-Install] [-Help]"
 19    Write-Output "Build the installer for Windows.\n"
 20    Write-Output "Options:"
 21    Write-Output "  -Install, -i  Run the installer after building."
 22    Write-Output "  -Help, -h     Show this help message."
 23    exit 0
 24}
 25
 26Push-Location -Path crates/zed
 27$channel = Get-Content "RELEASE_CHANNEL"
 28$env:ZED_RELEASE_CHANNEL = $channel
 29Pop-Location
 30
 31function CheckEnvironmentVariables {
 32    $requiredVars = @(
 33        'ZED_WORKSPACE', 'RELEASE_VERSION', 'ZED_RELEASE_CHANNEL',
 34        'AZURE_TENANT_ID', 'AZURE_CLIENT_ID', 'AZURE_CLIENT_SECRET',
 35        'ACCOUNT_NAME', 'CERT_PROFILE_NAME', 'ENDPOINT',
 36        'FILE_DIGEST', 'TIMESTAMP_DIGEST', 'TIMESTAMP_SERVER'
 37    )
 38
 39    foreach ($var in $requiredVars) {
 40        if (-not (Test-Path "env:$var")) {
 41            Write-Error "$var is not set"
 42            exit 1
 43        }
 44    }
 45}
 46
 47function PrepareForBundle {
 48    if (Test-Path "$innoDir") {
 49        Remove-Item -Path "$innoDir" -Recurse -Force
 50    }
 51    New-Item -Path "$innoDir" -ItemType Directory -Force
 52    Copy-Item -Path "$env:ZED_WORKSPACE\crates\zed\resources\windows\*" -Destination "$innoDir" -Recurse -Force
 53    New-Item -Path "$innoDir\make_appx" -ItemType Directory -Force
 54    New-Item -Path "$innoDir\appx" -ItemType Directory -Force
 55    New-Item -Path "$innoDir\bin" -ItemType Directory -Force
 56    New-Item -Path "$innoDir\tools" -ItemType Directory -Force
 57}
 58
 59function GenerateLicenses {
 60    $oldErrorActionPreference = $ErrorActionPreference
 61    $ErrorActionPreference = 'Continue'
 62    . $PSScriptRoot/generate-licenses.ps1
 63    $ErrorActionPreference = $oldErrorActionPreference
 64}
 65
 66function BuildZedAndItsFriends {
 67    Write-Output "Building Zed and its friends, for channel: $channel"
 68    # Build zed.exe, cli.exe and auto_update_helper.exe
 69    cargo build --release --package zed --package cli --package auto_update_helper
 70    Copy-Item -Path ".\target\release\zed.exe" -Destination "$innoDir\Zed.exe" -Force
 71    Copy-Item -Path ".\target\release\cli.exe" -Destination "$innoDir\cli.exe" -Force
 72    Copy-Item -Path ".\target\release\auto_update_helper.exe" -Destination "$innoDir\auto_update_helper.exe" -Force
 73    # Build explorer_command_injector.dll
 74    switch ($channel) {
 75        "stable" {
 76            cargo build --release --features stable --no-default-features --package explorer_command_injector
 77        }
 78        "preview" {
 79            cargo build --release --features preview --no-default-features --package explorer_command_injector
 80        }
 81        default {
 82            cargo build --release --package explorer_command_injector
 83        }
 84    }
 85    Copy-Item -Path ".\target\release\explorer_command_injector.dll" -Destination "$innoDir\zed_explorer_command_injector.dll" -Force
 86}
 87
 88function ZipZedAndItsFriendsDebug {
 89    $items = @(
 90        ".\target\release\zed.pdb",
 91        ".\target\release\cli.pdb",
 92        ".\target\release\auto_update_helper.pdb",
 93        ".\target\release\explorer_command_injector.pdb"
 94    )
 95
 96    Compress-Archive -Path $items -DestinationPath ".\target\release\zed-$env:RELEASE_VERSION-$env:ZED_RELEASE_CHANNEL.dbg.zip" -Force
 97}
 98
 99
100function UploadToSentry {
101    if (-not (Get-Command "sentry-cli" -ErrorAction SilentlyContinue)) {
102        Write-Output "sentry-cli not found. skipping sentry upload."
103        Write-Output "install with: 'winget install -e --id=Sentry.sentry-cli'"
104        return
105    }
106    if (-not (Test-Path "env:SENTRY_AUTH_TOKEN")) {
107        Write-Output "missing SENTRY_AUTH_TOKEN. skipping sentry upload."
108        return
109    }
110    Write-Output "Uploading zed debug symbols to sentry..."
111    sentry-cli debug-files upload --include-sources --wait -p zed -o zed-dev .\target\release\
112}
113
114function MakeAppx {
115    switch ($channel) {
116        "stable" {
117            $manifestFile = "$env:ZED_WORKSPACE\crates\explorer_command_injector\AppxManifest.xml"
118        }
119        "preview" {
120            $manifestFile = "$env:ZED_WORKSPACE\crates\explorer_command_injector\AppxManifest-Preview.xml"
121        }
122        default {
123            $manifestFile = "$env:ZED_WORKSPACE\crates\explorer_command_injector\AppxManifest-Nightly.xml"
124        }
125    }
126    Copy-Item -Path "$manifestFile" -Destination "$innoDir\make_appx\AppxManifest.xml"
127    # Add makeAppx.exe to Path
128    $sdk = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64"
129    $env:Path += ';' + $sdk
130    makeAppx.exe pack /d "$innoDir\make_appx" /p "$innoDir\zed_explorer_command_injector.appx" /nv
131}
132
133function SignZedAndItsFriends {
134    $files = "$innoDir\Zed.exe,$innoDir\cli.exe,$innoDir\auto_update_helper.exe,$innoDir\zed_explorer_command_injector.dll,$innoDir\zed_explorer_command_injector.appx"
135    & "$innoDir\sign.ps1" $files
136}
137
138function CollectFiles {
139    Move-Item -Path "$innoDir\zed_explorer_command_injector.appx" -Destination "$innoDir\appx\zed_explorer_command_injector.appx" -Force
140    Move-Item -Path "$innoDir\zed_explorer_command_injector.dll" -Destination "$innoDir\appx\zed_explorer_command_injector.dll" -Force
141    Move-Item -Path "$innoDir\cli.exe" -Destination "$innoDir\bin\zed.exe" -Force
142    Move-Item -Path "$innoDir\auto_update_helper.exe" -Destination "$innoDir\tools\auto_update_helper.exe" -Force
143}
144
145function BuildInstaller {
146    $issFilePath = "$innoDir\zed.iss"
147    switch ($channel) {
148        "stable" {
149            $appId = "{{2DB0DA96-CA55-49BB-AF4F-64AF36A86712}"
150            $appIconName = "app-icon"
151            $appName = "Zed"
152            $appDisplayName = "Zed"
153            $appSetupName = "ZedEditorUserSetup-x64-$env:RELEASE_VERSION"
154            # The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
155            $appMutex = "Zed-Stable-Instance-Mutex"
156            $appExeName = "Zed"
157            $regValueName = "Zed"
158            $appUserId = "ZedIndustries.Zed"
159            $appShellNameShort = "Z&ed"
160            $appAppxFullName = "ZedIndustries.Zed_1.0.0.0_neutral__japxn1gcva8rg"
161        }
162        "preview" {
163            $appId = "{{F70E4811-D0E2-4D88-AC99-D63752799F95}"
164            $appIconName = "app-icon-preview"
165            $appName = "Zed Preview"
166            $appDisplayName = "Zed Preview"
167            $appSetupName = "ZedEditorUserSetup-x64-$env:RELEASE_VERSION-preview"
168            # The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
169            $appMutex = "Zed-Preview-Instance-Mutex"
170            $appExeName = "Zed"
171            $regValueName = "ZedPreview"
172            $appUserId = "ZedIndustries.Zed.Preview"
173            $appShellNameShort = "Z&ed Preview"
174            $appAppxFullName = "ZedIndustries.Zed.Preview_1.0.0.0_neutral__japxn1gcva8rg"
175        }
176        "nightly" {
177            $appId = "{{1BDB21D3-14E7-433C-843C-9C97382B2FE0}"
178            $appIconName = "app-icon-nightly"
179            $appName = "Zed Nightly"
180            $appDisplayName = "Zed Nightly"
181            $appSetupName = "ZedEditorUserSetup-x64-$env:RELEASE_VERSION-nightly"
182            # The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
183            $appMutex = "Zed-Nightly-Instance-Mutex"
184            $appExeName = "Zed"
185            $regValueName = "ZedNightly"
186            $appUserId = "ZedIndustries.Zed.Nightly"
187            $appShellNameShort = "Z&ed Editor Nightly"
188            $appAppxFullName = "ZedIndustries.Zed.Nightly_1.0.0.0_neutral__japxn1gcva8rg"
189        }
190        "dev" {
191            $appId = "{{8357632E-24A4-4F32-BA97-E575B4D1FE5D}"
192            $appIconName = "app-icon-dev"
193            $appName = "Zed Dev"
194            $appDisplayName = "Zed Dev"
195            $appSetupName = "ZedEditorUserSetup-x64-$env:RELEASE_VERSION-dev"
196            # The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
197            $appMutex = "Zed-Dev-Instance-Mutex"
198            $appExeName = "Zed"
199            $regValueName = "ZedDev"
200            $appUserId = "ZedIndustries.Zed.Dev"
201            $appShellNameShort = "Z&ed Dev"
202            $appAppxFullName = "ZedIndustries.Zed.Dev_1.0.0.0_neutral__japxn1gcva8rg"
203        }
204        default {
205            Write-Error "can't bundle installer for $channel."
206            exit 1
207        }
208    }
209
210    # Windows runner 2022 default has iscc in PATH, https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md
211    # Currently, we are using Windows 2022 runner.
212    # Windows runner 2025 doesn't have iscc in PATH for now, https://github.com/actions/runner-images/issues/11228
213    # $innoSetupPath = "iscc.exe"
214    $innoSetupPath = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
215
216    $definitions = @{
217        "AppId"          = $appId
218        "AppIconName"    = $appIconName
219        "OutputDir"      = "$env:ZED_WORKSPACE\target"
220        "AppSetupName"   = $appSetupName
221        "AppName"        = $appName
222        "AppDisplayName" = $appDisplayName
223        "RegValueName"   = $regValueName
224        "AppMutex"       = $appMutex
225        "AppExeName"     = $appExeName
226        "ResourcesDir"   = "$innoDir"
227        "ShellNameShort" = $appShellNameShort
228        "AppUserId"      = $appUserId
229        "Version"        = "$env:RELEASE_VERSION"
230        "SourceDir"      = "$env:ZED_WORKSPACE"
231        "AppxFullName"   = $appAppxFullName
232    }
233
234    $signTool = "powershell.exe -ExecutionPolicy Bypass -File $innoDir\sign.ps1 `$f"
235
236    $defs = @()
237    foreach ($key in $definitions.Keys) {
238        $defs += "/d$key=`"$($definitions[$key])`""
239    }
240
241    $innoArgs = @($issFilePath) + $defs + "/sDefaultsign=`"$signTool`""
242
243    # Execute Inno Setup
244    Write-Host "🚀 Running Inno Setup: $innoSetupPath $innoArgs"
245    $process = Start-Process -FilePath $innoSetupPath -ArgumentList $innoArgs -NoNewWindow -Wait -PassThru
246
247    if ($process.ExitCode -eq 0) {
248        Write-Host "✅ Inno Setup successfully compiled the installer"
249        Write-Output "SETUP_PATH=target/$appSetupName.exe" >> $env:GITHUB_ENV
250        $script:buildSuccess = $true
251    }
252    else {
253        Write-Host "❌ Inno Setup failed: $($process.ExitCode)"
254        $script:buildSuccess = $false
255    }
256}
257
258ParseZedWorkspace
259$innoDir = "$env:ZED_WORKSPACE\inno"
260$debugArchive = ".\target\release\zed-$env:RELEASE_VERSION-$env:ZED_RELEASE_CHANNEL.dbg.zip"
261$debugStoreKey = "$env:ZED_RELEASE_CHANNEL/zed-$env:RELEASE_VERSION-$env:ZED_RELEASE_CHANNEL.dbg.zip"
262
263CheckEnvironmentVariables
264PrepareForBundle
265GenerateLicenses
266BuildZedAndItsFriends
267MakeAppx
268SignZedAndItsFriends
269ZipZedAndItsFriendsDebug
270CollectFiles
271BuildInstaller
272
273UploadToBlobStorePublic -BucketName "zed-debug-symbols" -FileToUpload $debugArchive -BlobStoreKey $debugStoreKey
274UploadToSentry
275
276if ($buildSuccess) {
277    Write-Output "Build successful"
278    if ($Install) {
279        Write-Output "Installing Zed..."
280        Start-Process -FilePath "$env:ZED_WORKSPACE/target/ZedEditorUserSetup-x64-$env:RELEASE_VERSION.exe"
281    }
282    exit 0
283}
284else {
285    Write-Output "Build failed"
286    exit 1
287}