-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.ps1
184 lines (150 loc) · 5.15 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
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
param(
$NuGetPackageUrl = '',
$NuGetApiKey = '',
$ReleaseVersion = '0.0.0',
[switch] $DisableXUnitParallelization = $false,
[switch] $NoSync = $false
)
#Assumes
# git in path
#
#
# TeamCity variables that may be set
#
$BuildVersion = $ReleaseVersion
if ($env:BUILD_NUMBER -ne $null) {
$BuildVersion = $env:BUILD_NUMBER
}
$BuildBranch = 'DevLocal'
if ($env:BUILD_BRANCH -ne $null) {
$BuildBranch = $env:BUILD_BRANCH
if ($BuildBranch -eq '<default>') {
$BuildBranch = 'master'
}
}
$BuildIsPrivate = ($BuildBranch -ne 'master')
if ($NuGetPackageUrl -eq '' -and $env:NUGET_PACKAGE_URL -ne $null) {
$NuGetPackageUrl = $env:NUGET_PACKAGE_URL
}
if ($NuGetApikey -eq '' -and $env:NUGET_API_KEY -ne $null) {
$NuGetApiKey = $env:NUGET_API_KEY
}
if ($BuildIsPrivate -eq $true) {
$NuGetVersion = "$BuildVersion-$BuildBranch"
}
else {
$NuGetVersion = $BuildVersion
}
#
# Base directories
#
$IFSourceDirectory = Convert-Path $PWD
$BuildRootDir = "$IFSourceDirectory\Build"
$ToolsDir = "$IFSourceDirectory\tools"
# Nuget properties
$NuGetExe = "$BuildRootDir\nuget\nuget.exe"
$NuGetNuSpec = "$BuildRootDir\Default.Deploy.nuspec"
# Staging Properties
$StagingRootDir = "$IFSourceDirectory\staging"
$StagingDir = "$StagingRootDir\$BuildVersion"
$StagingIFDataRoot = "$StagingDir\if_data"
$StagingDeaPackageRoot = "$StagingDir\dea_ng"
$StagingWardenPackageRoot = "$StagingDir\if_warden"
$StagingIFPreReqs = "$StagingDir\if_prereqs"
$ReleaseDir = "$IFSourceDirectory\release"
$ZipCmd = "$ToolsDir\7zip\7za.exe"
$LogFile = "$IFSourceDirectory\$BuildVersion-build.log"
function UpdateSubmodules
{
if ($NoSync) {
Write-Host "NOT Updating submodules"
return
}
Write-Host "Updating submodules"
git submodule sync --recursive
git submodule update --init --recursive
}
function BuildWarden()
{
Write-Host "Building Warden: $BuildVersion"
$parallelizeXUnit = !$DisableXUnitParallelization;
.\if_warden\build.bat Default /verbosity:minimal /p:BuildNumber="$BuildVersion" /p:XUnitParallelizeAssemblies="$parallelizeXUnit" /p:XUnitParallelizeTestCollections="$parallelizeXUnit"
if ($LASTEXITCODE -ne 0)
{
throw 'The warden build failed!'
}
}
function BuildDirectoryServer()
{
Write-Host "Building GO WinRunner"
Push-Location $IFSourceDirectory\dea_ng\go\
try
{
$env:GOPATH="$IFSourceDirectory\dea_ng\go"
go build winrunner
if ($LASTEXITCODE -ne 0)
{
throw 'The build for the Directory Service failed!'
}
}
finally
{
Pop-Location
}
}
function StageRelease()
{
Write-Host "Staging the release"
Remove-Item $StagingRootDir -force -recurse -erroraction silentlycontinue | Out-Null
New-Item $StagingDir -itemtype directory -Force | Out-Null
Copy-Item -Recurse $IFSourceDirectory\if_data $StagingIFDataRoot -Container -Force
Copy-Item -Recurse $IFSourceDirectory\dea_ng $StagingDeaPackageRoot -Container -Force
Copy-Item -Recurse $IFSourceDirectory\if_warden\output\$BuildVersion\binaries $StagingWardenPackageRoot -Container -Force
Copy-Item -Recurse $IFSourceDirectory\if_prereqs $StagingIFPreReqs -Container -Force
Copy-Item -Recurse $IFSourceDirectory\tools $StagingDir\tools -Container -Force
$additionalFiles = @(
'ironfoundry-install.ps1',
'start-if-services.ps1',
'stop-if-services.ps1',
'install-prerequisites.ps1',
'README.md')
ForEach($file in $additionalFiles)
{
Copy-Item $file $StagingRootDir -Container -Force
}
}
function CleanRelease {
Remove-Item $ReleaseDir -recurse -force -erroraction silentlycontinue | Out-Null
New-Item $ReleaseDir -itemtype directory -force | Out-Null
}
function ZipRelease()
{
Write-Host "Creating the release"
. $ZipCmd a -sfx "$ReleaseDir\ironfoundry-$BuildVersion-$BuildBranch.exe" -r -y $StagingRootDir\* | Out-Null
}
function CreateNuSpecs()
{
Write-Host "Creating nuspec packages"
& $NuGetExe pack "$NuGetNuspec" -Version $NuGetVersion -Prop "Id=ironfoundry.pre-reqs" -BasePath "$StagingIFPreReqs" -NoPackageAnalysis -NoDefaultExcludes -OutputDirectory "$ReleaseDir"
& $NuGetExe pack "$NuGetNuSpec" -Version $NuGetVersion -Prop "Id=ironfoundry.data" -BasePath "$StagingIFDataRoot" -NoPackageAnalysis -NoDefaultExcludes -OutputDirectory "$ReleaseDir"
& $NuGetExe pack "$NuGetNuSpec" -Version $NuGetVersion -Prop "Id=ironfoundry.dea_ng" -BasePath "$StagingDeaPackageRoot" -NoPackageAnalysis -NoDefaultExcludes -OutputDirectory "$ReleaseDir"
& $NuGetExe pack "$NuGetNuSpec" -Version $NuGetVersion -Prop "Id=ironfoundry.warden.service" -BasePath "$StagingWardenPackageRoot" -NoPackageAnalysis -NoDefaultExcludes -OutputDirectory "$ReleaseDir"
}
function NuGetPush {
Write-Host "Pushing to nuget url: $NuGetPackageUrl"
Get-ChildItem "$ReleaseDir\*.$NuGetVersion.nupkg" | ForEach-Object {
. $NuGetExe push -Source $NuGetPackageUrl -ApiKey "$NuGetApiKey" "$($_.FullName)"
}
}
UpdateSubmodules
BuildWarden
BuildDirectoryServer
StageRelease
CleanRelease
ZipRelease
if ($NuGetPackageUrl -ne '')
{
CreateNuSpecs
NuGetPush
}
Set-Location $IFSourceDirectory