-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathbuild.ps1
More file actions
229 lines (183 loc) · 6.86 KB
/
build.ps1
File metadata and controls
229 lines (183 loc) · 6.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$versionShort,
[switch]$beta,
[switch]$debugBuild = $false
)
. ./build_common.ps1
# Get master version number
$version4Part = $versionShort + ".0.0"
if ($debugBuild) {
$buildFlavor = "Debug"
} else {
$buildFlavor = "Release"
}
$branch = &git rev-parse --abbrev-ref HEAD
if ($beta -and ($branch -eq "master")) {
ExitWithError "Current branch is master but build calls for beta"
}
if (!$beta -and ($branch -eq "beta")) {
ExitWithError "Current branch is beta but build calls for stable"
}
if ($beta) {
$configuration = $buildFlavor + "-Beta"
$productName = "VidCoder Beta"
} else {
$configuration = $buildFlavor
$productName = "VidCoder"
}
function GetPublishFolderPath($projectName, $folderNameSuffix) {
".\$projectName\bin\publish-$folderNameSuffix"
}
function PlatformToBuildPlatform(
[ValidateSet('x64', 'arm64')]
[string]$platform) {
if ($platform -ieq "x64") { return "x64" }
elseif ($platform -ieq "arm64") { return "ARM64" }
else { ExitWithError "Unknown platform: $platform" }
}
# Basic clear and publish for a specific project and publish profile
function Publish(
$projectName,
[ValidateSet('x64', 'arm64')]
[string]$platform,
[ValidateSet('installer', 'portable')]
[string]$installerType,
[string]$publishProfileName) {
$folderNameSuffix = "$installerType-$platform"
$buildPlatform = PlatformToBuildPlatform $platform
PublishRaw $projectName $buildPlatform $folderNameSuffix $publishProfileName
}
function PublishRaw(
$projectName,
[ValidateSet('x64', 'ARM64', 'AnyCPU')]
[string]$buildPlatform,
[string]$folderNameSuffix,
[string]$publishProfileName) {
Write-Host "Publishing $folderNameSuffix on project $projectName for $buildPlatform..."
$publishFolderPath = GetPublishFolderPath $projectName $folderNameSuffix
if (Test-Path -Path $publishFolderPath) {
Get-ChildItem -Path $publishFolderPath -Include * -File -Recurse | foreach { $_.Delete()}
}
# We have to explicitly pass in Platform to make sure the conditional hb.dll link resolves correctly
& dotnet publish .\$projectName\$projectName.csproj `
/p:PublishProfile=$publishProfileName `
/p:Platform=$buildPlatform `
/p:Version=$version4part `
"/p:Product=$productName" `
-c $configuration
}
# Publish an installer and copy extra files for it
function PublishInstaller(
[ValidateSet('x64', 'arm64')]
[string]$platform,
[string]$publishProfileName) {
Publish "VidCoder" $platform "installer" $publishProfileName
CopyInstallerExtraFiles $platform
}
function CopyInstallerExtraFiles(
[ValidateSet('x64', 'arm64')]
[string]$platform) {
$extraFiles = @(
".\VidCoder\Icons\File\VidCoderPreset.ico",
".\VidCoder\Icons\File\VidCoderQueue.ico")
$publishFolderPath = GetPublishFolderPath "VidCoder" "installer" $platform
foreach ($extraFile in $extraFiles) {
copy $extraFile $publishFolderPath; ExitIfFailed
}
}
function SignExe($filePath) {
& signtool sign /a /fd SHA256 /tr http://timestamp.digicert.com /td SHA256 $filePath
}
# Publish the files
PublishInstaller "x64" "InstallerX64Profile"
PublishInstaller "arm64" "InstallerArm64Profile"
Publish "VidCoder" "x64" "portable" "PortableX64Profile"
Publish "VidCoder" "arm64" "portable" "PortableArm64Profile"
PublishRaw "VidCoderWorker" "AnyCPU" "portable" "PortableProfile"
# We need to copy some files from the Worker publish over to the main publish output, because the main publish output doesn't properly set the Worker to self-contained mode
copy ".\VidCoderWorker\bin\publish-portable\VidCoderWorker*" ".\VidCoder\bin\publish-portable-x64"
copy ".\VidCoderWorker\bin\publish-portable\VidCoderWorker*" ".\VidCoder\bin\publish-portable-arm64"
# Create portable exes
if ($beta) {
$betaNameSection = "-Beta"
} else {
$betaNameSection = ""
}
$binaryNameBase = "VidCoder-$versionShort$betaNameSection"
if ($debugBuild) {
$builtInstallerFolder = "Installer\BuiltInstallers\Test"
} else {
$builtInstallerFolder = "Installer\BuiltInstallers"
}
$winRarExe = "c:\Program Files\WinRar\WinRAR.exe"
function BuildPortable(
[ValidateSet('x64', 'arm64')]
[string]$platform) {
Write-Host "Creating portable exe for $platform..."
New-Item -ItemType Directory -Force -Path ".\$builtInstallerFolder"
$portableExeWithoutExtension = ".\$builtInstallerFolder\$binaryNameBase-$platform-Portable"
$portableExeWithExtension = $portableExeWithoutExtension + ".exe"
DeleteFileIfExists $portableExeWithExtension
& $winRarExe a -sfx -z".\Installer\VidCoderRar.conf" -iicon".\VidCoder\VidCoder_icon.ico" -r -ep1 $portableExeWithoutExtension .\VidCoder\bin\publish-portable-$platform\** | Out-Null
ExitIfFailed
SignExe $portableExeWithExtension; ExitIfFailed
}
BuildPortable "x64"
BuildPortable "arm64"
function BuildZip(
[ValidateSet('x64', 'arm64')]
[string]$platform) {
# Sign executables in publish-installer, for inclusion in the .zip Release
$publishedExes = Get-ChildItem -Path .\VidCoder\bin\publish-installer-$platform\ -Filter *.exe
foreach ($exeFile in $publishedExes) {
SignExe $exeFile.FullName; ExitIfFailed
}
# Create zip file with binaries
$zipFilePath = ".\Installer\BuiltInstallers\$binaryNameBase-$platform.zip"
DeleteFileIfExists $zipFilePath
& $winRarExe a -afzip -ep1 -r $zipFilePath .\VidCoder\bin\publish-installer-$platform\
ExitIfFailed
}
BuildZip "x64"
BuildZip "arm64"
# Build Velopack installer
if ($beta) {
$packId = "VidCoder.Beta"
$releaseDirSuffix = "Beta"
} else {
$packId = "VidCoder.Stable"
$releaseDirSuffix = "Stable"
}
$releaseDir = ".\Installer\Releases-$releaseDirSuffix"
function Velopack(
[string]$packId,
[ValidateSet('win', 'win-arm64')]
[string]$channel,
[string]$releaseDir,
[ValidateSet('x64', 'arm64')]
[string]$platform) {
Write-Host "Building Velopack for $platform"
vpk pack `
-x `
-y `
--packId $packId `
--packTitle "$productName" `
--packVersion ($versionShort + ".0") `
--packAuthors RandomEngy `
--packDir .\VidCoder\bin\publish-installer-$platform `
--channel $channel `
--mainExe VidCoder.exe `
--icon .\Installer\VidCoder_Setup.ico `
--outputDir $releaseDir `
--splashImage .\Installer\InstallerSplash.png `
--signParams "/a /fd SHA256 /tr http://timestamp.digicert.com /td SHA256" `
--framework net10.0.2-$platform
Copy-Item -Path ("$releaseDir\$packId-$channel-Setup.exe") -Destination ".\Installer\BuiltInstallers\$binaryNameBase-$platform.exe" -Force
ExitIfFailed
}
Velopack $packId "win" $releaseDir "x64"
Velopack $packId "win-arm64" $releaseDir "arm64"
WriteSuccess
Write-Host