@@ -15,11 +15,68 @@ param (
15
15
[string ] $outputPath = " " , # defaults to "publish\CoderDesktop-$version-$arch.exe"
16
16
17
17
[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"
19
35
)
20
36
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
+
21
78
# CD to the root of the repo
22
- $repoRoot = Join-Path $PSScriptRoot " .."
79
+ $repoRoot = Resolve-Path ( Join-Path $PSScriptRoot " .." )
23
80
Push-Location $repoRoot
24
81
25
82
if ($msiOutputPath -eq " " ) {
@@ -48,11 +105,21 @@ New-Item -ItemType Directory -Path $buildPath -Force
48
105
49
106
# Build in release mode
50
107
$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" }
52
110
# App needs to be built with msbuild
53
111
$appPublishDir = Join-Path $buildPath " app"
54
112
$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" }
55
114
& $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
+ }
56
123
57
124
# Copy any additional files into the install directory
58
125
Copy-Item " scripts\files\License.txt" $buildPath
@@ -63,7 +130,7 @@ $wintunDllPath = Join-Path $vpnFilesPath "wintun.dll"
63
130
Copy-Item " scripts\files\wintun-*-$ ( $arch ) .dll" $wintunDllPath
64
131
65
132
# Build the MSI installer
66
- dotnet.exe run -- project .\Installer\Installer.csproj - c Release -- `
133
+ & dotnet.exe run -- project .\Installer\Installer.csproj - c Release -- `
67
134
build-msi `
68
135
-- arch $arch `
69
136
-- version $version `
@@ -77,11 +144,11 @@ dotnet.exe run --project .\Installer\Installer.csproj -c Release -- `
77
144
-- vpn- dir " vpn" `
78
145
-- banner- bmp " scripts\files\WixUIBannerBmp.bmp" `
79
146
-- 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
82
149
83
150
# Build the bootstrapper
84
- dotnet.exe run -- project .\Installer\Installer.csproj - c Release -- `
151
+ & dotnet.exe run -- project .\Installer\Installer.csproj - c Release -- `
85
152
build-bootstrapper `
86
153
-- arch $arch `
87
154
-- version $version `
@@ -90,8 +157,8 @@ dotnet.exe run --project .\Installer\Installer.csproj -c Release -- `
90
157
-- icon- file " App\coder.ico" `
91
158
-- msi- path $msiOutputPath `
92
159
-- 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
95
162
96
163
if (! $keepBuildTemp ) {
97
164
Remove-Item - Recurse - Force $buildPath
0 commit comments