-
Notifications
You must be signed in to change notification settings - Fork 21
/
Build.ps1
158 lines (111 loc) · 4.52 KB
/
Build.ps1
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
Set-StrictMode -version Latest
$ErrorActionPreference = "Stop"
Write-Host "Building Go To Window..." -ForegroundColor Green
# ==================================== Functions
Function GetMSBuildExe {
Return "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
}
Function ZipFiles($Filename, $Source)
{
Add-Type -Assembly System.IO.Compression.FileSystem
$CompressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory($Source, $Filename, $CompressionLevel, $false)
}
# ==================================== Variables
$NuGet = "$PSScriptRoot\.nuget\NuGet.exe"
$Squirrel = Join-Path (ls .\packages\squirrel.windows.*)[0] "tools\Squirrel.com"
$BuildPath = "$PSScriptRoot\GoToWindow\bin\Release"
$NuSpecPath = "$PSScriptRoot\GoToWindow.nuspec"
$ReleasesFolder = "$PSScriptRoot\Releases"
$SetupLoadingGif = "$PSScriptRoot\GoToWindow.Setup\Loading.gif"
$SetupIcon = "$PSScriptRoot\GoToWindow\Resources\AppIcon.ico"
# ==================================== NuSpec Metadata
$NuSpecXml = [xml](Get-Content $NuSpecPath)
$Version = $NuSpecXml.package.metadata.version
# ==================================== Synchronize RELEASES
Write-Host "Synchronizing releases..." -ForegroundColor White
git checkout Releases\RELEASES
$ReleasesToDownload = (Get-Content "$ReleasesFolder\RELEASES") | % { ($_ -split ' ')[1] }
$ReleaseFilenames = @()
$WebClient = New-Object System.Net.WebClient
$ReleasesToDownload | % {
$ReleaseFilename = $_.Split("/")[-1]
$ReleaseFilenames += $ReleaseFilename
$ReleasePath = "$ReleasesFolder\$ReleaseFilename"
If(Test-Path -Path $ReleasePath) {
Write-Host "$ReleaseFilename already present" -ForegroundColor Gray
} Else {
Write-Host "Downloading $ReleaseFilename..."
$WebClient.DownloadFile($_, $ReleasePath)
Write-Host "$ReleaseFilename downloaded"
}
}
Write-Host "Deleting unreferenced nupkg files"
dir "$ReleasesFolder\*.nupkg" | ? { $ReleaseFilenames -NotContains $_.Name } | Remove-Item
# ==================================== Build
Write-Host "Building..." -ForegroundColor White
If(Test-Path -Path $BuildPath) {
Remove-Item -Confirm:$false "$BuildPath\*.*"
}
&(GetMSBuildExe) GoToWindow.sln `
/t:Clean`;Rebuild `
/p:Configuration=Release `
/p:AllowedReferenceRelatedFileExtensions=- `
/p:DebugSymbols=false `
/p:DebugType=None `
/clp:ErrorsOnly `
/v:m
# ==================================== Zip
Write-Host "Zipping..." -ForegroundColor White
$ReleaseZip = "$ReleasesFolder\GoToWindow.$Version.zip"
If(!(Test-Path -Path $ReleasesFolder )){
New-Item -ItemType directory -Path $ReleasesFolder
}
If(Test-Path -Path $ReleaseZip) {
Remove-Item -Confirm:$false $ReleaseZip
}
ZipFiles $ReleaseZip $BuildPath
# ==================================== Squirrel
Write-Host "Squirrel..." -ForegroundColor White
$NuPkgPath = "$PSScriptRoot\GoToWindow.$Version.nupkg"
&($NuGet) pack $NuSpecPath
$SquirrelFullNuPkgOutputPath = "$PSScriptRoot\Releases\GoToWindow-$Version-full.nupkg"
If(Test-Path -Path $SquirrelFullNuPkgOutputPath) {
Remove-Item -Confirm:$false $SquirrelFullNuPkgOutputPath
}
$SquirrelDeltaNuPkgOutputPath = "$PSScriptRoot\Releases\GoToWindow-$Version-delta.nupkg"
If(Test-Path -Path $SquirrelDeltaNuPkgOutputPath) {
Remove-Item -Confirm:$false $SquirrelDeltaNuPkgOutputPath
}
$OutputSetupMsi = "$ReleasesFolder\GoToWindow.Setup.$Version.msi"
If(Test-Path -Path $OutputSetupMsi) {
Remove-Item -Confirm:$false $OutputSetupMsi
}
$OutputSetupExe = "$ReleasesFolder\GoToWindow.Setup.$Version.exe"
If(Test-Path -Path $OutputSetupExe) {
Remove-Item -Confirm:$false $OutputSetupExe
}
&($Squirrel) -g $SetupLoadingGif --releasify $NuPkgPath -i $SetupIcon -baseUrl https://github.com/christianrondeau/GoToWindow/releases/download/v$Version/
$SquirrelSetupMsi = "$ReleasesFolder\Setup.msi"
If(Test-Path -Path $SquirrelSetupMsi) {
Rename-Item $SquirrelSetupMsi $OutputSetupMsi
}
$SquirrelSetupExe = "$ReleasesFolder\Setup.exe"
If(Test-Path -Path $SquirrelSetupExe) {
Rename-Item $SquirrelSetupExe $OutputSetupExe
}
# ==================================== Chocolatey
$ChocolateyNuPkg = "chocolatey\gotowindow.$Version.nupkg"
If(Test-Path -Path $ChocolateyNuPkg) {
Remove-Item -Confirm:$false $ChocolateyNuPkg
}
pushd chocolatey
choco pack
popd
# ==================================== Cleanup
Write-Host "Cleanup..." -ForegroundColor White
If(Test-Path -Path $NuPkgPath) {
Remove-Item -Confirm:$false $NuPkgPath
}
# ==================================== Complete
Write-Host "Build $Version complete: $ReleasesFolder" -ForegroundColor Green