-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.ps1
More file actions
207 lines (168 loc) · 7.02 KB
/
default.ps1
File metadata and controls
207 lines (168 loc) · 7.02 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
properties {
$revision = if ("$env:BUILD_NUMBER".length -gt 0) { "$env:BUILD_NUMBER" } else { "0" }
$inTeamCity = if ("$env:BUILD_NUMBER".length -gt 0) { $true } else { $false }
$version = "0.26.0"
$configuration = "Debug"
$platform = "Any CPU"
$buildOutputDir = "./BuildOutput"
$nugetOutputDir = Join-Path $buildOutputDir "nuget"
$testAssemblies = @()
$dllOutputsToPublish = @("SouthsideUtility.Core","SouthsideUtility.RavenDB", "SouthsideUtility.Testing")
$nugetPackagesToPublish = @("SouthsideUtility.Core","SouthsideUtility.RavenDB", "SouthsideUtility.Testing")
$nugetPublishUrl = "https://www.myget.org/F/southside/"
}
task default -depends build
task build -Description "Build application. Runs tests" -depends version, cleanBuildOutput, compile, test {
}
task test -Description "Runs tests" {
if ($testAssemblies.Count -gt 0) {
[string]$nunitVersion = Get-NunitVersion
if ($inTeamCity) {
Write-Host "Running Tests In TeamCity"
[string] $nunit = "NUnit-" + $nunitVersion
Write-Host "Running " $env:NUNIT_LAUNCHER v4.0 x64 $nunit $testAssemblies
& $env:NUNIT_LAUNCHER v4.0 x64 $nunit $testAssemblies
} else {
Write-Host "Running Tests Outside TeamCity"
[string] $nunitPath = Get-NunitPath
& $nunitPath $testAssemblies /noshadow "/framework:net-4.0"
}
if ($LastExitCode -ne 0) { throw "Tests failed"}
} else {
Write-Host "No test assemblies..."
}
}
Task compile -Description "Build application only" {
exec {.nuget\nuget restore}
exec { msbuild $sln_file /t:rebuild /m:4 /p:VisualStudioVersion=12.0 "/p:Configuration=$configuration" "/p:Platform=$platform" }
}
task pullCurrentAndBuild -Description "Does a git pull of the current branch followed by build" -depends pullCurrent, build
task pullCurrent -Description "Does a git pull" {
git pull
}
task buildDist -Description "Update version. Build appication. Runs tests. Builds Nuget packages" -depends build, createArtifacts {
}
task buildDistAndPublish -Description "Update version. Build appication. Runs tests. Builds Nuget packages. Deploys to MyGet." -depends buildDist, publish {
}
task cleanBuildOutput -Description "Cleans the BuildOutput folder" {
if (Test-Path $buildOutputDir) {
Remove-Item -Recurse -Force $buildOutputDir
}
New-Item -ItemType directory -Path $buildOutputDir
New-Item -ItemType directory -Path $nugetOutputDir
}
task startRaven -Description "Starts RavenDB." {
Start-Raven
}
Task version -Description "Version the assemblies" {
Update-CommonAssemblyInfoFile $version $revision
}
Task versionReset -Description "Returns the version of the assemblies to 0.1.0.0" {
Reset-CommonAssemblyInfoFile
}
Task createArtifacts -Description "Create artifacts" {
$dllOutputsToPublish | % { Copy-DllOutputs $_ }
$nugetPackagesToPublish | % {Create-NugetPackage $_ }
}
Task publish -Description "Publish NuGet Packages" {
$nugetPackagesToPublish | % { Publish-ToMyGet $_ }
}
task ? -Description "Helper to display task info" {
WriteDocumentation
}
function Update-CommonAssemblyInfoFile ([string] $version, [string]$revision) {
if ($version -notmatch "[0-9]+(\.([0-9]+|\*)){1,3}") {
Write-Error "Version number incorrect format: $version"
}
$versionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,2}"\)'
$versionAssembly = 'AssemblyVersion("' + $version + '")';
$versionFilePattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$versionAssemblyFile = 'AssemblyFileVersion("' + $version + "." + $revision + '")';
Get-ChildItem -filter .\Common\CommonAssemblyInfo.cs | % {
$filename = $_.fullname
if ($make_writable) { Writeable-File($filename) }
$tmp = ($file + ".tmp")
if (test-path ($tmp)) { remove-item $tmp }
(get-content $filename) | % {$_ -replace $versionFilePattern, $versionAssemblyFile } | % {$_ -replace $versionPattern, $versionAssembly } > $tmp
write-host Updating file AssemblyInfo and AssemblyFileInfo: $filename --> $versionAssembly / $versionAssemblyFile
if (test-path ($filename)) { remove-item $filename }
move-item $tmp $filename -force
if ($make_writable) { ReadOnly-File($filename) }
}
}
function Version-Nuspec ([string]$project) {
[string] $nuspecFilePath = Join-Path -Path ".\nuspec" -ChildPath ($project + ".nuspec") -Resolve
Write-Host $nuspecFilePath
[xml]$nuspecFile = Get-Content $nuspecFilePath
$ns = New-Object System.Xml.XmlNamespaceManager($nuspecFile.NameTable)
$ns.AddNamespace("ns", "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd")
$versionNode = $nuspecFile.SelectSingleNode("//ns:version", $ns)
if ($versionNode -eq $null) {
throw "Cannot find version node in nuspec package for $nuspecFile"
}
$versionNode.innerText = $version + "." + $revision
$nuspecFile.Save($nuspecFilePath)
}
function Copy-DllOutputs ([string] $projectName) {
[string] $path = Join-Path (Join-Path "app/$projectName" "bin") $configuration
[string] $destPath = Join-Path $buildOutputDir $projectName
Copy-Item $path $destPath -recurse
}
function Publish-ToMyGet ([string] $package) {
[string] $nugetFilePath = Join-Path -Path $nugetOutputDir -ChildPath ($package + "." + $version + "." + $revision + ".nupkg") -Resolve
& .nuget\nuget push $nugetFilePath -s $nugetPublishUrl
}
function Create-NugetPackage ([string] $projectName) {
Version-Nuspec $projectName
[string] $source = Join-Path -Path "nuspec" -ChildPath ($projectName + ".nuspec")
& .nuget\nuget pack $source -OutputDirectory $nugetOutputDir
if ($LastExitCode -ne 0) { throw "Failed to create nuget package for $projectName"}
}
function Reset-CommonAssemblyInfoFile(){
Update-CommonAssemblyInfoFile "0.1.0" "0"
}
function Writeable-File($filename){
sp $filename IsReadOnly $false
}
function ReadOnly-File($filename){
sp $filename IsReadOnly $true
}
function Start-Raven {
$processActive = Get-Process Raven.Server -ErrorAction SilentlyContinue
if (!$processActive)
{
#Find the correct version of RavenDB by looking at the referenced
#package in the packages.config file of the solution
[xml]$packages = Get-Content ".\.nuget\Packages.config"
$server = $packages.SelectSingleNode("//package[@id='RavenDB.Server']")
$version = $server.GetAttribute("version")
[string] $path = ".\packages\RavenDB.Server.$version\tools\Raven.Server.exe"
#Start it up
Write-Host "Starting Raven at: " $path
if (test-path env:ConEmuDir) {
& ConEmu -reuse -cmd "$path"
} else {
Start-Process -FilePath $path
}
Start-Sleep 5
Exit 0
}
else
{
Write-Host "RavenDB already running"
Exit 0
}
}
function Get-NunitVersion {
#Find the correct version of NUnit by looking at the referenced
#package in the packages.config file of the solution
[xml]$packages = Get-Content ".\.nuget\Packages.config"
$server = $packages.SelectSingleNode("//package[@id='NUnit.Console']")
$version = $server.GetAttribute("version")
return $version
}
function Get-NunitPath {
[string] $version = Get-NunitVersion
[string] $path = ".\packages\Nunit.Runners.$version\tools\nunit-console.exe"
return $path
}