This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.ps1
154 lines (119 loc) · 5.07 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
. .\tools\psake\psake_ext.ps1
. .\tools\psake\teamcity.ps1
$framework = '4.0'
function Get-GitVersion {
return (git log -n1 --pretty=%H)
}
properties {
# version advertised. also used as the tag name in git.
$public_version = "0.85.0"
$source_dir = Resolve-Path ./
$build_dir = "$source_dir\@build"
$checkout_dir = [Environment]::GetEnvironmentVariable("teamcity.build.checkoutDir")
$artifact_dir = if ($checkout_dir.length -gt 0) { "$checkout_dir\@artifacts" } else { "$source_dir\@artifacts" }
$configuration = "Release"
$build_number = if ("$env:BUILD_NUMBER".length -gt 0) { "$env:BUILD_NUMBER" } else { "0" }
$build_vcs_number = if ("$env:BUILD_VCS_NUMBER".length -gt 0) { "$env:BUILD_VCS_NUMBER" } else { Get-GitVersion }
$version = "$public_version.$build_number"
$info_version = "$version (rev $build_vcs_number)"
}
task default -depends Compile, RunTests, ZipBinaries, ZipSource, NuGet
task NuGet {
TeamCity-ReportBuildStart "NuGet"
exec { & "$source_dir\.nuget\NuGet.exe" pack ""$source_dir\DotNetMigrations.nuspec"" -Verbose -OutputDirectory ""$artifact_dir"" -Properties version=$public_version }
"@echo off
echo Publish the $public_version package to the NuGet Gallery?
pause
..\.nuget\NuGet.exe push .\DotNetMigrations.$public_version.nupkg
pause" | Out-File $artifact_dir\PublishNuGetPackage.bat -Encoding OEM
}
task ZipBinaries {
TeamCity-ReportBuildStart "ZipBinaries"
$zip_name = "DotNetMigrations-v" + $public_version + "-BIN.zip"
# zip the build output
# exclude unit tests and debug symbols
exec { ./tools/7zip/7za.exe a -tzip `"$artifact_dir\$zip_name`" `"$build_dir\*`" `
`"-x!*.pdb`" `
`"-x!*migrate*`" `
`"-x!*x86*`" `
`"-x!*amd64*`" `
`"-x!*Tests*`" `
`"-x!Moq.*`" `
`"-x!pnunit.*`" `
`"-x!System.Data.SqlServerCe.dll`" `
`"-x!nunit.*`" ` }
TeamCity-PublishArtifact "@artifacts\$zip_name"
TeamCity-ReportBuildFinish "ZipBinaries"
}
task ZipSource {
TeamCity-ReportBuildStart "ZipSource"
$zip_name = "DotNetMigrations-v" + $public_version + "-SRC.zip"
# zip the source code
# exclude the cruft
exec { ./tools/7zip/7za.exe a -tzip `"$artifact_dir\$zip_name`" `"$source_dir\*`" `
`"-x!.git`" `
`"-x!@build`" `
`"-x!@artifacts`" `
`"-x!*resharper*`" `
`"-x!.gitignore`" `
`"-x!TODO.txt`" `
`"-xr!*.cache`" `
`"-xr!*.suo`" `
`"-xr!*.user`" }
TeamCity-PublishArtifact "@artifacts\$zip_name"
TeamCity-ReportBuildFinish "ZipSource"
}
task RunTests {
TeamCity-ReportBuildStart "RunTests"
$nunitLauncher = [Environment]::GetEnvironmentVariable("teamcity.dotnet.nunitlauncher")
# we are excluding tests in the "SqlServer" category
# since those are integration tests that have a dependency
# on SQL Server which may not be available
if ($nunitLauncher -ne $null) {
# run tests using the TeamCity NUnit runner
exec { & $nunitLauncher v2.0 x86 NUnit-2.4.8 $build_dir\DotNetMigrations.UnitTests.dll }
} else {
# run tests using our own copy of NUnit
$nunitExe = (Get-ChildItem $source_dir\packages\NUnit.* -Recurse -Include nunit-console.exe).FullName
exec { & "$nunitExe" $build_dir\DotNetMigrations.UnitTests.dll /labels /xml=$artifact_dir\TestResults.xml } `
"Oops! Build failed due to some failing tests."
}
TeamCity-ReportBuildFinish "RunTests"
}
task Compile -depends Init {
TeamCity-ReportBuildStart "Compile"
"Updating NuGet packages"
if (-not(Test-Path $source_dir\packages)) {
New-Item $source_dir\packages -ItemType directory
}
exec { & "$source_dir\.nuget\NuGet.exe" update ""$source_dir\DotNetMigrations.sln"" -Verbose -RepositoryPath ""$source_dir\packages"" }
"Building version $version for $configuration"
# build the solution
exec { msbuild ""$source_dir\DotNetMigrations.sln"" /m /nologo /t:Rebuild /p:Configuration=$configuration /p:OutDir=""$build_dir\\"" }
TeamCity-ReportBuildFinish "Compile"
}
task Init -depends Clean {
TeamCity-ReportBuildStart "Init"
Assert($version.length -gt 0) "No version number was specified."
TeamCity-SetBuildNumber $version
"Informational Version: $info_version"
$year = [DateTime]::Now.ToString("yyyy")
Generate-Assembly-Info `
-File "$source_dir\src\CommonAssemblyInfo.cs" `
-Title "DotNetMigrations $info_version" `
-Description "" `
-Company "" `
-Product "DotNetMigrations $info_version" `
-Version $version `
-InfoVersion $info_version `
-Copyright "Copyright (c) Joshua Poehls 2007-$year"
New-Item $build_dir -ItemType directory
New-Item $artifact_dir -ItemType directory
TeamCity-ReportBuildFinish "Init"
}
task Clean {
TeamCity-ReportBuildStart "Clean"
if (Test-Path $build_dir) { Remove-Item -Force -Recurse $build_dir }
if (Test-Path $artifact_dir) { Remove-Item -Force -Recurse $artifact_dir }
TeamCity-ReportBuildFinish "Clean"
}