-
Notifications
You must be signed in to change notification settings - Fork 44
/
build_release.ps1
224 lines (190 loc) · 8.56 KB
/
build_release.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
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
# That is the location where this script run results will be placed:
$releasesRoot = "../Rollbar.NET-Releases"
$ErrorActionPreference="Stop"
$ProgressPreference="SilentlyContinue"
# $LocalDotnet is the path to the locally-installed SDK to ensure the
# correct version of the tools are executed.
$LocalDotnet=""
# $InstallDir and $CliVersion variables can come from options to the
# script.
$InstallDir = "./cli-tools"
$CliVersion = "latest" # = "1.0.1"
# Test the path provided by $InstallDir to confirm it exists. If it
# does, it's removed. This is not strictly required, but it's a
# good way to reset the environment.
if (Test-Path $InstallDir)
{
Remove-Item -Recurse $InstallDir
}
New-Item -Type "directory" -Path $InstallDir
Write-Host "Downloading the CLI installer..."
# Use the Invoke-WebRequest PowerShell cmdlet to obtain the
# installation script and save it into the installation directory.
Invoke-WebRequest `
-Uri "https://dot.net/v1/dotnet-install.ps1" `
-OutFile "$InstallDir/dotnet-install.ps1"
Write-Host "Installing the CLI requested version ($CliVersion) ..."
# Install the SDK of the version specified in $CliVersion into the
# specified location ($InstallDir).
& $InstallDir/dotnet-install.ps1 -Version $CliVersion `
-InstallDir $InstallDir
Write-Host "Downloading and installation of the SDK is complete."
# $LocalDotnet holds the path to dotnet.exe for future use by the
# script.
$LocalDotnet = "$InstallDir/dotnet"
# Run the build process now. Implement your build script here:
#=============================================================
Write-Host "Harvesting all the SDK module projects..."
$sdkProjects =
Get-ChildItem -Path "." -Directory |
Where-Object {$_.Name -match '^Rollbar*'} |
Where-Object {!($_.Name -match '^Rollbar.Benchmarker')} # we are not interested it this one...
Write-Host " " $sdkProjects
Write-Host "Deleting /obj and /bin folders of the SDK projects/modules..."
foreach($project in $sdkProjects) {
Write-Host " SDK module:" $project.FullName
$path = $project.FullName + '/obj'
if (Test-Path $path) {
Remove-Item -Path $path -Recurse #-WhatIf
}
$path = $project.FullName + '/bin'
if (Test-Path $path) {
Remove-Item -Path $path -Recurse #-WhatIf
}
}
Write-Host "Restoring the SDK dependencies..."
#!!! dotnet restore rollbar.sln
Write-Host "Building all the SDK build configurations..."
$buildConfigurations = @(
"Instrumented",
"Debug",
"Release"
)
foreach($buildConfiguration in $buildConfigurations) {
Write-Host " Building the SDK build configuration:" $buildConfiguration "..."
# clean the configuration:
<#
Write-Host " - cleaning..."
dotnet clean rollbar.sln --configuration $buildConfiguration
#>
# build the configurations:
Write-Host " - building..."
dotnet build rollbar.sln --configuration $buildConfiguration
# unit-test the Release configuration:
#Write-Host " - unit-testing..."
#dotnet test rollbar.sln --configuration $buildConfiguration
}
# unit-test the Release configuration:
#!!! Write-Host " - unit-testing Debug build..."
#!!! dotnet test rollbar.sln --configuration Debug
Write-Host "Consolidating SDK build results..."
# define location for releases:
$releasesPath = $releasesRoot
if(!(Test-Path $releasesPath)) {
New-Item -Path $releasesPath -ItemType Directory #-WhatIf
}
Write-Host "Releases folder: "$releasesPath
# define location for old releases archive:
$releasesArchivePath = Join-Path -Path $releasesPath -ChildPath "ARCHIVE"
if(!(Test-Path $releasesArchivePath)) {
New-Item -Path $releasesArchivePath -ItemType Directory #-WhatIf
}
Write-Host "Releases Archive folder: "$releasesArchivePath
# archive last release:
$releasesToArchive = @(
Get-ChildItem -Path $releasesPath -Directory |
Where-Object {$_.Name -match '^v*'} |
Where-Object {!($_.Name -match '^ARCHIVE')} # we are not interested it this one...
)
Write-Host "Archiving: "$releasesToArchive
foreach($release in $releasesToArchive) {
Write-Host " Moving "$release.FullName"..."
Move-Item -Path ($release.FullName) -Destination $releasesArchivePath -Force #-WhatIf
}
# collect current release:
Add-Type -assembly "system.io.compression.filesystem"
foreach($project in $sdkProjects) {
# project source path:
$projectBin = $project.FullName + '/bin'
# release bin name based on the NuGet package name prefix:
$nugetPackage = (Get-ChildItem -Path $projectBin/Release -Filter *.nupkg | Select-Object -First 1).FullName
$nugetPackage = [System.IO.Path]::GetFileNameWithoutExtension($nugetPackage)
Write-Host "Package:" $nugetPackage
$nugetPackageNameComponents = $nugetPackage.Split('.')
$releaseBinName = ""
for($i=0; $i -lt ($nugetPackageNameComponents.Count - 3); $i++) {
$releaseBinName = $releaseBinName + $nugetPackageNameComponents[$i]
if ($i -lt ($nugetPackageNameComponents.Count - 3 - 1)) {
$releaseBinName = $releaseBinName + "."
}
}
Write-Host "New release bin name:" $releaseBinName
# release bin version based on the NuGet package version suffix:
[array]::Reverse($nugetPackageNameComponents)
Write-Host "Package components:" $nugetPackageNameComponents
if($nugetPackageNameComponents[$nugetPackageNameComponents.Count - 1] -eq "LTS") {
Write-Host "Dealing with an LTS realease..."
$patchAndSuffix = $nugetPackageNameComponents[0]
$patchAndSuffixComponents = $patchAndSuffix.Split('-')
Write-Host " Patch and Suffix components:" $patchAndSuffixComponents
if ($patchAndSuffixComponents.Count -gt 1) {
$releaseBinVersion =
'v' + $nugetPackageNameComponents[2] + '.' + $nugetPackageNameComponents[1] + '.' + $patchAndSuffixComponents[0] + '-LTS'
Write-Host " Release bin version (in progress):" $releaseBinVersion
for($i=1; $i -lt $patchAndSuffixComponents.Count; $i++) {
$releaseBinVersion = $releaseBinVersion + '-' + $patchAndSuffixComponents[$i]
Write-Host " Release bin version (in progress):" $releaseBinVersion
}
}
else {
Write-Host "Dealing with a non-LTS realease..."
$releaseBinVersion =
'v' + $nugetPackageNameComponents[2] + '.' + $nugetPackageNameComponents[1] + '.' + $nugetPackageNameComponents[0] + "-LTS"
}
}
else {
$releaseBinVersion =
'v' + $nugetPackageNameComponents[2] + '.' + $nugetPackageNameComponents[1] + '.' + $nugetPackageNameComponents[0]
}
Write-Host "Release bin version:" $releaseBinVersion
# release folder path:
$releaseFolder = Join-Path -Path $releasesPath -ChildPath $releaseBinVersion
if(!(Test-Path $releaseFolder)) {
New-Item -Path $releaseFolder -ItemType Directory #-WhatIf
}
# release bin folder path:
$releaseBin = Join-Path -Path $releaseFolder -ChildPath ('bin-' + $releaseBinVersion + '-' + $releaseBinName)
if(!(Test-Path $releaseBin)) {
New-Item -Path $releaseBin -ItemType Directory #-WhatIf
}
# copy release bin content from the project source path:
Copy-Item -Path ($projectBin+'/*') -Destination $releaseBin -recurse -Force #-Verbose
# stash away NuGet packages of interest:
$nugetBuilds = @("Release", "Debug")
foreach($nugetBuild in $nugetBuilds) {
$releaseNuGetPackagesPath = Join-Path -Path $releaseFolder -ChildPath ("NuGet-"+$nugetBuild)
if(!(Test-Path $releaseNuGetPackagesPath)) {
New-Item -Path $releaseNuGetPackagesPath -ItemType Directory #-WhatIf
}
Copy-Item -Path ($releaseBin+'/'+$nugetBuild+'/*.nupkg') -Destination $releaseNuGetPackagesPath -Recurse -Force #-Verbose
}
# zip release bins folders
# https://devblogs.microsoft.com/scripting/use-powershell-to-create-zip-archive-of-folder/
$zipPath = Join-Path -Path $releaseFolder -ChildPath ((Split-Path $releaseBin -Leaf) + '.zip')
[io.compression.zipfile]::CreateFromDirectory($releaseBin, $zipPath)
# delete release bins folders
Remove-Item -Path $releaseBin -Recurse -Force #-Verbose
}
# make sure all the samples are buildable:
<#
Get-ChildItem "./Samples" -Filter *.sln |
Foreach-Object {
# clear all the ground:
dotnet clean $_.FullName --configuration Debug
dotnet clean $_.FullName --configuration Release
# restore all the dependencies:
dotnet restore $_.FullName | Where-Object {$_.FullName -match 'Xamarin'}
# build the Release configurations:
dotnet build $_.FullName --configuration Release | Where-Object {$_.FullName -match 'Xamarin'}
}
#>