-
Notifications
You must be signed in to change notification settings - Fork 11
/
Deploy.ps1
202 lines (165 loc) · 6.02 KB
/
Deploy.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
param ( [switch]$push = $false,
[switch]$fast = $false,
[switch]$skipTests = $false)
$script:scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
pushd $scriptPath
function test-return() {
if ($LASTEXITCODE -ne 0) {
return $false
}
else {
return $true
}
}
function check-return() {
if (-not (test-return)) {
write-error "Command failed with code $LASTEXITCODE"
}
}
function build-clean() {
param ([string]$fileName = $(throw "Need a project file name"))
$name = split-path -leaf $fileName
& $msbuild /nologo /verbosity:m /t:Clean /p:Configuration=Release /p:VisualStudioVersion=10.0 $fileName
check-return
& $msbuild /nologo /verbosity:m /t:Clean /p:Configuration=Debug /p:VisualStudioVersion=10.0 $fileName
check-return
}
function build-release() {
param (
[string]$fileName = $(throw "Need a project file name"),
[string]$editorVersion = $(throw "Need an editor version"))
$name = split-path -leaf $fileName
& $msbuild /nologo /verbosity:q /p:Configuration=Release /p:VisualStudioVersion=10.0 /p:EditorVersion=$editorVersion $fileName
check-return
}
# Check to see if the given version of Visual Studio is installed
function test-vs-install() {
param ([string]$version = $(throw "Need a version"))
if ([IntPtr]::Size -eq 4) {
$path = "hklm:\Software\Microsoft\VisualStudio\{0}" -f $version
}
else {
$path = "hklm:\Software\Wow6432Node\Microsoft\VisualStudio\{0}" -f $version
}
$i = get-itemproperty $path InstallDir -ea SilentlyContinue | %{ $_.InstallDir }
return $i -ne $null
}
# Run all of the unit tests
function test-unittests() {
param ([string]$vsVersion = $(throw "Need a VS version"))
write-host -NoNewLine "`tRunning Unit Tests: "
if ($script:skipTests) {
write-host "skipped"
return
}
if (-not (test-vs-install $vsVersion)) {
write-host "skipped (VS missing)"
return
}
$all = "Test\EditorUtilsTest\bin\Release\EditorUtils.UnitTest.dll"
$xunit = join-path $scriptPath "Tools\xunit.console.clr4.x86.exe"
$resultFilePath = "Deploy\xunit.xml"
foreach ($file in $all) {
$name = split-path -leaf $file
& $xunit $file /silent /xml $resultFilePath | out-null
if (-not (test-return)) {
write-host "FAILED!!!"
& notepad $resultFilePath
}
else {
write-host "passed"
}
}
}
# Get the version number of the package that we are deploying
function get-version() {
$version = $null;
foreach ($line in gc "Src\EditorUtils\Constants.cs") {
if ($line -match 'AssemblyVersion = "([\d.]*)"') {
$version = $matches[1]
}
}
if ($version -eq $null) {
write-error "Couldn't determine the version from Constants.cs"
return
}
if (-not ($version -match "^\d+\.\d+\.\d+.\d+$")) {
write-error "Version number in unexpected format"
}
return $version
}
# Do the NuGet work
function invoke-nuget() {
param (
[string]$version = $(throw "Need a version number"),
[string]$suffix = $(throw "Need a file name suffix"))
write-host "`tCreating NuGet Package"
$scratchPath = "Deploy\Scratch"
$libPath = join-path $scratchPath "lib\net40"
$outputPath = "Deploy"
if (test-path $scratchPath) {
rm -re -fo $scratchPath | out-null
}
mkdir $libPath | out-null
$fileName = "EditorUtils$($suffix)"
copy "Src\EditorUtils\bin\Release\$($fileName).dll" (join-path $libPath "$($fileName).dll")
copy "Src\EditorUtils\bin\Release\$($fileName).pdb" (join-path $libPath "$($fileName).pdb")
$nuspecFilePath = join-path "Data" "EditorUtils$($suffix).nuspec"
& $nuget pack $nuspecFilePath -Version $version -BasePath $scratchPath -OutputDirectory $outputPath | out-null
check-return
if ($script:push) {
write-host "`tPushing Package"
$name = "EditorUtils$($suffix).$version.nupkg"
$packageFile = join-path $outputPath $name
& $nuget push $packageFile | %{ write-host "`t`t$_" }
check-return
}
}
function deploy-version() {
param (
[string]$editorVersion = $(throw "Need a version number"),
[string]$vsVersion = $(throw "Need a VS version"))
$suffix = $editorVersion.Substring(2)
write-host "Deploying $editorVersion"
# First clean the projects
write-host "`tCleaning Projects"
build-clean Src\EditorUtils\EditorUtils.csproj
build-clean Test\EditorUtilsTest\EditorUtilsTest.csproj
# Build all of the relevant projects. Both the deployment binaries and the
# test infrastructure
write-host "`tBuilding Projects"
build-release Src\EditorUtils\EditorUtils.csproj $editorVersion
build-release Test\EditorUtilsTest\EditorUtilsTest.csproj $editorVersion
write-host "`tDetermining Version Number"
$version = get-version
# Next run the tests
test-unittests $vsVersion
# Now do the NuGet work
invoke-nuget $version $suffix
}
$msbuild = join-path ${env:SystemRoot} "microsoft.net\framework\v4.0.30319\msbuild.exe"
if (-not (test-path $msbuild)) {
write-error "Can't find msbuild.exe"
}
# Several of the projects involved use NuGet and the resulting .csproj files
# rely on the SolutionDir MSBuild property being set. Hence we set the appropriate
# environment variable for build
${env:SolutionDir} = $scriptPath
if (-not (test-path "Deploy")) {
mkdir Deploy | out-null
}
$nuget = resolve-path ".nuget\NuGet.exe"
if (-not (test-path $nuget)) {
write-error "Can't find NuGet.exe"
}
if ($fast) {
deploy-version "Vs2010" "10.0"
}
else {
deploy-version "Vs2010" "10.0"
deploy-version "Vs2012" "11.0"
deploy-version "Vs2013" "12.0"
deploy-version "Vs2015" "14.0"
}
rm env:\SolutionDir
popd