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 BuildZedAndItsFriends {
60 Write-Output "Building Zed and its friends, for channel: $channel"
61 # Build zed.exe, cli.exe and auto_update_helper.exe
62 cargo build --release --package zed --package cli --package auto_update_helper
63 Copy-Item -Path ".\target\release\zed.exe" -Destination "$innoDir\Zed.exe" -Force
64 Copy-Item -Path ".\target\release\cli.exe" -Destination "$innoDir\cli.exe" -Force
65 Copy-Item -Path ".\target\release\auto_update_helper.exe" -Destination "$innoDir\auto_update_helper.exe" -Force
66 # Build explorer_command_injector.dll
67 switch ($channel) {
68 "stable" {
69 cargo build --release --features stable --no-default-features --package explorer_command_injector
70 }
71 "preview" {
72 cargo build --release --features preview --no-default-features --package explorer_command_injector
73 }
74 default {
75 cargo build --release --package explorer_command_injector
76 }
77 }
78 Copy-Item -Path ".\target\release\explorer_command_injector.dll" -Destination "$innoDir\zed_explorer_command_injector.dll" -Force
79}
80
81function ZipZedAndItsFriendsDebug {
82 $items = @(
83 ".\target\release\zed.pdb",
84 ".\target\release\cli.pdb",
85 ".\target\release\auto_update_helper.pdb",
86 ".\target\release\explorer_command_injector.pdb"
87 )
88
89 Compress-Archive -Path $items -DestinationPath ".\target\release\zed-$env:RELEASE_VERSION-$env:ZED_RELEASE_CHANNEL.dbg.zip" -Force
90}
91
92function MakeAppx {
93 switch ($channel) {
94 "stable" {
95 $manifestFile = "$env:ZED_WORKSPACE\crates\explorer_command_injector\AppxManifest.xml"
96 }
97 "preview" {
98 $manifestFile = "$env:ZED_WORKSPACE\crates\explorer_command_injector\AppxManifest-Preview.xml"
99 }
100 default {
101 $manifestFile = "$env:ZED_WORKSPACE\crates\explorer_command_injector\AppxManifest-Nightly.xml"
102 }
103 }
104 Copy-Item -Path "$manifestFile" -Destination "$innoDir\make_appx\AppxManifest.xml"
105 # Add makeAppx.exe to Path
106 $sdk = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64"
107 $env:Path += ';' + $sdk
108 makeAppx.exe pack /d "$innoDir\make_appx" /p "$innoDir\zed_explorer_command_injector.appx" /nv
109}
110
111function SignZedAndItsFriends {
112 $files = "$innoDir\Zed.exe,$innoDir\cli.exe,$innoDir\auto_update_helper.exe,$innoDir\zed_explorer_command_injector.dll,$innoDir\zed_explorer_command_injector.appx"
113 & "$innoDir\sign.ps1" $files
114}
115
116function CollectFiles {
117 Move-Item -Path "$innoDir\zed_explorer_command_injector.appx" -Destination "$innoDir\appx\zed_explorer_command_injector.appx" -Force
118 Move-Item -Path "$innoDir\zed_explorer_command_injector.dll" -Destination "$innoDir\appx\zed_explorer_command_injector.dll" -Force
119 Move-Item -Path "$innoDir\cli.exe" -Destination "$innoDir\bin\zed.exe" -Force
120 Move-Item -Path "$innoDir\auto_update_helper.exe" -Destination "$innoDir\tools\auto_update_helper.exe" -Force
121}
122
123function BuildInstaller {
124 $issFilePath = "$innoDir\zed.iss"
125 switch ($channel) {
126 "stable" {
127 $appId = "{{2DB0DA96-CA55-49BB-AF4F-64AF36A86712}"
128 $appIconName = "app-icon"
129 $appName = "Zed"
130 $appDisplayName = "Zed"
131 $appSetupName = "ZedEditorUserSetup-x64-$env:RELEASE_VERSION"
132 # The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
133 $appMutex = "Zed-Stable-Instance-Mutex"
134 $appExeName = "Zed"
135 $regValueName = "Zed"
136 $appUserId = "ZedIndustries.Zed"
137 $appShellNameShort = "Z&ed"
138 $appAppxFullName = "ZedIndustries.Zed_1.0.0.0_neutral__japxn1gcva8rg"
139 }
140 "preview" {
141 $appId = "{{F70E4811-D0E2-4D88-AC99-D63752799F95}"
142 $appIconName = "app-icon-preview"
143 $appName = "Zed Preview"
144 $appDisplayName = "Zed Preview"
145 $appSetupName = "ZedEditorUserSetup-x64-$env:RELEASE_VERSION-preview"
146 # The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
147 $appMutex = "Zed-Preview-Instance-Mutex"
148 $appExeName = "Zed"
149 $regValueName = "ZedPreview"
150 $appUserId = "ZedIndustries.Zed.Preview"
151 $appShellNameShort = "Z&ed Preview"
152 $appAppxFullName = "ZedIndustries.Zed.Preview_1.0.0.0_neutral__japxn1gcva8rg"
153 }
154 "nightly" {
155 $appId = "{{1BDB21D3-14E7-433C-843C-9C97382B2FE0}"
156 $appIconName = "app-icon-nightly"
157 $appName = "Zed Nightly"
158 $appDisplayName = "Zed Nightly"
159 $appSetupName = "ZedEditorUserSetup-x64-$env:RELEASE_VERSION-nightly"
160 # The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
161 $appMutex = "Zed-Nightly-Instance-Mutex"
162 $appExeName = "Zed"
163 $regValueName = "ZedNightly"
164 $appUserId = "ZedIndustries.Zed.Nightly"
165 $appShellNameShort = "Z&ed Editor Nightly"
166 $appAppxFullName = "ZedIndustries.Zed.Nightly_1.0.0.0_neutral__japxn1gcva8rg"
167 }
168 "dev" {
169 $appId = "{{8357632E-24A4-4F32-BA97-E575B4D1FE5D}"
170 $appIconName = "app-icon-nightly"
171 $appName = "Zed Dev"
172 $appDisplayName = "Zed Dev"
173 $appSetupName = "ZedEditorUserSetup-x64-$env:RELEASE_VERSION-dev"
174 # The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
175 $appMutex = "Zed-Dev-Instance-Mutex"
176 $appExeName = "Zed"
177 $regValueName = "ZedDev"
178 $appUserId = "ZedIndustries.Zed.Dev"
179 $appShellNameShort = "Z&ed Dev"
180 $appAppxFullName = "ZedIndustries.Zed.Dev_1.0.0.0_neutral__japxn1gcva8rg"
181 }
182 default {
183 Write-Error "can't bundle installer for $channel."
184 exit 1
185 }
186 }
187
188 # Windows runner 2022 default has iscc in PATH, https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md
189 # Currently, we are using Windows 2022 runner.
190 # Windows runner 2025 doesn't have iscc in PATH for now, https://github.com/actions/runner-images/issues/11228
191 # $innoSetupPath = "iscc.exe"
192 $innoSetupPath = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
193
194 $definitions = @{
195 "AppId" = $appId
196 "AppIconName" = $appIconName
197 "OutputDir" = "$env:ZED_WORKSPACE\target"
198 "AppSetupName" = $appSetupName
199 "AppName" = $appName
200 "AppDisplayName" = $appDisplayName
201 "RegValueName" = $regValueName
202 "AppMutex" = $appMutex
203 "AppExeName" = $appExeName
204 "ResourcesDir" = "$innoDir"
205 "ShellNameShort" = $appShellNameShort
206 "AppUserId" = $appUserId
207 "Version" = "$env:RELEASE_VERSION"
208 "SourceDir" = "$env:ZED_WORKSPACE"
209 "AppxFullName" = $appAppxFullName
210 }
211
212 $signTool = "powershell.exe -ExecutionPolicy Bypass -File $innoDir\sign.ps1 `$f"
213
214 $defs = @()
215 foreach ($key in $definitions.Keys) {
216 $defs += "/d$key=`"$($definitions[$key])`""
217 }
218
219 $innoArgs = @($issFilePath) + $defs + "/sDefaultsign=`"$signTool`""
220
221 # Execute Inno Setup
222 Write-Host "🚀 Running Inno Setup: $innoSetupPath $innoArgs"
223 $process = Start-Process -FilePath $innoSetupPath -ArgumentList $innoArgs -NoNewWindow -Wait -PassThru
224
225 if ($process.ExitCode -eq 0) {
226 Write-Host "✅ Inno Setup successfully compiled the installer"
227 Write-Output "SETUP_PATH=target/$appSetupName.exe" >> $env:GITHUB_ENV
228 $script:buildSuccess = $true
229 }
230 else {
231 Write-Host "❌ Inno Setup failed: $($process.ExitCode)"
232 $script:buildSuccess = $false
233 }
234}
235
236ParseZedWorkspace
237$innoDir = "$env:ZED_WORKSPACE\inno"
238
239CheckEnvironmentVariables
240PrepareForBundle
241BuildZedAndItsFriends
242MakeAppx
243SignZedAndItsFriends
244ZipZedAndItsFriendsDebug
245CollectFiles
246BuildInstaller
247
248$debugArchive = ".\target\release\zed-$env:RELEASE_VERSION-$env:ZED_RELEASE_CHANNEL.dbg.zip"
249$debugStoreKey = "$env:ZED_RELEASE_CHANNEL/zed-$env:RELEASE_VERSION-$env:ZED_RELEASE_CHANNEL.dbg.zip"
250UploadToBlobStorePublic -BucketName "zed-debug-symbols" -FileToUpload $debugArchive -BlobStoreKey $debugStoreKey
251
252if ($buildSuccess) {
253 Write-Output "Build successful"
254 if ($Install) {
255 Write-Output "Installing Zed..."
256 Start-Process -FilePath "$env:ZED_WORKSPACE/target/ZedEditorUserSetup-x64-$env:RELEASE_VERSION.exe"
257 }
258 exit 0
259}
260else {
261 Write-Output "Build failed"
262 exit 1
263}