@@ -15,11 +15,68 @@ param (
1515 [string ] $outputPath = " " , # defaults to "publish\CoderDesktop-$version-$arch.exe"
1616
1717 [Parameter (Mandatory = $false )]
18- [switch ] $keepBuildTemp = $false
18+ [switch ] $keepBuildTemp = $false ,
19+
20+ [Parameter (Mandatory = $false )]
21+ [switch ] $sign = $false
22+ )
23+
24+ $ErrorActionPreference = " Stop"
25+
26+ $ourAssemblies = @ (
27+ " Coder Desktop.exe" ,
28+ " Coder Desktop.dll" ,
29+ " CoderVpnService.exe" ,
30+ " CoderVpnService.dll" ,
31+
32+ " Coder.Desktop.CoderSdk.dll" ,
33+ " Coder.Desktop.Vpn.dll" ,
34+ " Coder.Desktop.Vpn.Proto.dll"
1935)
2036
37+ function Find-Dependencies ([string []] $dependencies ) {
38+ foreach ($dependency in $dependencies ) {
39+ if (! (Get-Command $dependency - ErrorAction SilentlyContinue)) {
40+ throw " Missing dependency: $dependency "
41+ }
42+ }
43+ }
44+
45+ function Find-EnvironmentVariables ([string []] $variables ) {
46+ foreach ($variable in $variables ) {
47+ if (! (Get-Item env:$variable - ErrorAction SilentlyContinue)) {
48+ throw " Missing environment variable: $variable "
49+ }
50+ }
51+ }
52+
53+ if ($sign ) {
54+ Write-Host " Signing is enabled"
55+ Find-Dependencies java
56+ Find-EnvironmentVariables @ (" JSIGN_PATH" , " EV_KEYSTORE" , " EV_KEY" , " EV_CERTIFICATE_PATH" , " EV_TSA_URL" , " GCLOUD_ACCESS_TOKEN" )
57+ }
58+
59+ function Add-CoderSignature ([string ] $path ) {
60+ if (! $sign ) {
61+ Write-Host " Skipping signing $path "
62+ return
63+ }
64+
65+ Write-Host " Signing $path "
66+ & java.exe - jar $env: JSIGN_PATH `
67+ -- storetype GOOGLECLOUD `
68+ -- storepass $env: GCLOUD_ACCESS_TOKEN `
69+ -- keystore $env: EV_KEYSTORE `
70+ -- alias $env: EV_KEY `
71+ -- certfile $env: EV_CERTIFICATE_PATH `
72+ -- tsmode RFC3161 `
73+ -- tsaurl $env: EV_TSA_URL `
74+ $path
75+ if ($LASTEXITCODE -ne 0 ) { throw " Failed to sign $path " }
76+ }
77+
2178# CD to the root of the repo
22- $repoRoot = Join-Path $PSScriptRoot " .."
79+ $repoRoot = Resolve-Path ( Join-Path $PSScriptRoot " .." )
2380Push-Location $repoRoot
2481
2582if ($msiOutputPath -eq " " ) {
@@ -48,11 +105,21 @@ New-Item -ItemType Directory -Path $buildPath -Force
48105
49106# Build in release mode
50107$servicePublishDir = Join-Path $buildPath " service"
51- dotnet.exe publish .\Vpn.Service\Vpn.Service.csproj - c Release - a $arch - o $servicePublishDir
108+ & dotnet.exe publish .\Vpn.Service\Vpn.Service.csproj - c Release - a $arch - o $servicePublishDir
109+ if ($LASTEXITCODE -ne 0 ) { throw " Failed to build Vpn.Service" }
52110# App needs to be built with msbuild
53111$appPublishDir = Join-Path $buildPath " app"
54112$msbuildBinary = & " ${env: ProgramFiles(x86)} \Microsoft Visual Studio\Installer\vswhere.exe" - latest - requires Microsoft.Component.MSBuild - find MSBuild\** \Bin\MSBuild.exe
113+ if ($LASTEXITCODE -ne 0 ) { throw " Failed to find MSBuild" }
55114& $msbuildBinary .\App\App.csproj / p:Configuration= Release / p:Platform= $arch / p:OutputPath= $appPublishDir
115+ if ($LASTEXITCODE -ne 0 ) { throw " Failed to build App" }
116+
117+ # Find any files in the publish directory recursively that match any of our
118+ # assemblies and sign them.
119+ $toSign = Get-ChildItem - Path $buildPath - Recurse | Where-Object { $ourAssemblies -contains $_.Name }
120+ foreach ($file in $toSign ) {
121+ Add-CoderSignature $file.FullName
122+ }
56123
57124# Copy any additional files into the install directory
58125Copy-Item " scripts\files\License.txt" $buildPath
@@ -63,7 +130,7 @@ $wintunDllPath = Join-Path $vpnFilesPath "wintun.dll"
63130Copy-Item " scripts\files\wintun-*-$ ( $arch ) .dll" $wintunDllPath
64131
65132# Build the MSI installer
66- dotnet.exe run -- project .\Installer\Installer.csproj - c Release -- `
133+ & dotnet.exe run -- project .\Installer\Installer.csproj - c Release -- `
67134 build-msi `
68135 -- arch $arch `
69136 -- version $version `
@@ -77,11 +144,11 @@ dotnet.exe run --project .\Installer\Installer.csproj -c Release -- `
77144 -- vpn- dir " vpn" `
78145 -- banner- bmp " scripts\files\WixUIBannerBmp.bmp" `
79146 -- dialog- bmp " scripts\files\WixUIDialogBmp.bmp"
80-
81- # TODO: sign the installer
147+ if ( $LASTEXITCODE -ne 0 ) { throw " Failed to build MSI " }
148+ Add-CoderSignature $msiOutputPath
82149
83150# Build the bootstrapper
84- dotnet.exe run -- project .\Installer\Installer.csproj - c Release -- `
151+ & dotnet.exe run -- project .\Installer\Installer.csproj - c Release -- `
85152 build-bootstrapper `
86153 -- arch $arch `
87154 -- version $version `
@@ -90,8 +157,8 @@ dotnet.exe run --project .\Installer\Installer.csproj -c Release -- `
90157 -- icon- file " App\coder.ico" `
91158 -- msi- path $msiOutputPath `
92159 -- logo- png " scripts\files\logo.png"
93-
94- # TODO: sign the bootstrapper
160+ if ( $LASTEXITCODE -ne 0 ) { throw " Failed to build bootstrapper " }
161+ Add-CoderSignature $outputPath
95162
96163if (! $keepBuildTemp ) {
97164 Remove-Item - Recurse - Force $buildPath
0 commit comments