-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.fsx
270 lines (221 loc) · 10.4 KB
/
build.fsx
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.DotNet.NuGet
open Fake.DotNet.NuGet.NuGet
open Fake.DotNet.Testing
open Fake.DotNet.Testing.OpenCover
open Fake.IO.Globbing.Operators
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.Tools
Environment.setEnvironVar "VisualStudioVersion" "15.0"
let authors = ["Aaron Powell"]
let chauffeurDir = "./Chauffeur/bin/"
let chauffeurRunnerDir = "./Chauffeur.Runner/bin/"
let chauffeurTestingToolsDir = "./Chauffeur.TestingTools/bin/"
let packagingRoot = "./.packaging/"
let packagingDir = packagingRoot @@ "chauffeur"
let packagingRunnerDir = packagingRoot @@ "chauffeur.runner"
let packagingTestingToolsDir = packagingRoot @@ "chauffeur.testingtools"
let testDir = "./.testresults"
let buildMode = Environment.environVarOrDefault "buildMode" "Release"
let isCIBuild = not (isNull (Environment.environVar "AGENT_ID"))
let projectName = "Chauffeur"
let chauffeurSummary = "Chauffeur is a tool for helping with delivering changes to an Umbraco instance."
let chauffeurDescription = chauffeurSummary
let chauffeurRunnerSummary = "Chauffeur Runner is a CLI for executing Chauffeur deliverables against an Umbraco instance."
let chauffeurRunnerDescription = chauffeurRunnerSummary
let chauffeurTestingToolsSummary = "Chauffeur Testing Tools is a series of helpers for using Chauffeur to setup Umbraco for integration testing with Umbraco's API"
let chauffeurTestingToolsDescription = chauffeurRunnerSummary
let releaseNotes =
File.read "ReleaseNotes.md"
|> ReleaseNotes.parse
let trimBranchName (branch: string) =
let trimmed = match branch.Length > 10 with
| true -> branch.Substring(0, 10)
| _ -> branch
trimmed.Replace(".", "")
let prv = match Environment.environVar "BUILD_SOURCEBRANCHNAME" with
| null -> ""
| "master" -> ""
| branch -> sprintf "-%s%s" (trimBranchName branch) (
match Environment.environVar "BUILD_BUILDNUMBER" with
| null -> ""
| _ -> sprintf "-%s" (Environment.environVar "BUILD_BUILDNUMBER")
)
let nugetVersion = sprintf "%d.%d.%d%s" releaseNotes.SemVer.Major releaseNotes.SemVer.Minor releaseNotes.SemVer.Patch prv
Target.create "Default" ignore
Target.create "AssemblyInfo" (fun _ ->
let commitHash = Git.Information.getCurrentHash()
let attributes =
[ Fake.DotNet.AssemblyInfo.Version releaseNotes.AssemblyVersion
Fake.DotNet.AssemblyInfo.FileVersion releaseNotes.AssemblyVersion
Fake.DotNet.AssemblyInfo.InformationalVersion releaseNotes.AssemblyVersion
Fake.DotNet.AssemblyInfo.ComVisible false
Fake.DotNet.AssemblyInfo.Metadata("githash", commitHash) ]
AssemblyInfoFile.createCSharp "SolutionInfo.cs" attributes
let fsAttributes =
[ Fake.DotNet.AssemblyInfo.Product projectName
Fake.DotNet.AssemblyInfo.Title "Chauffeur.TestingTools"
Fake.DotNet.AssemblyInfo.Version releaseNotes.AssemblyVersion
Fake.DotNet.AssemblyInfo.FileVersion releaseNotes.AssemblyVersion
Fake.DotNet.AssemblyInfo.InformationalVersion releaseNotes.AssemblyVersion
Fake.DotNet.AssemblyInfo.ComVisible false
Fake.DotNet.AssemblyInfo.Metadata("githash", commitHash) ]
AssemblyInfoFile.createFSharp "./Chauffeur.TestingTools/AssemblyInfo.fs" fsAttributes
)
Target.create "Clean" (fun _ ->
Shell.cleanDirs [chauffeurDir; chauffeurRunnerDir; testDir]
)
Target.create "RestoreChauffeurPackages" (fun _ ->
Restore.RestorePackage id "./Chauffeur/packages.config"
)
Target.create "RestoreChauffeurTestingToolsPackages" (fun _ ->
Restore.RestorePackage id "./Chauffeur.TestingTools/packages.config"
)
Target.create "RestoreChauffeurDemoPackages" (fun _ ->
Restore.RestorePackage id "./Chauffeur.Demo/packages.config"
)
Target.create "RestoreChauffeurTestsPackages" (fun _ ->
Restore.RestorePackage id "./Chauffeur.Tests/packages.config"
Restore.RestorePackage id "./Chauffeur.Tests.Integration/packages.config"
)
Target.create "Build" (fun _ ->
let setParams (defaults: MSBuildParams) =
let p = { defaults with
Verbosity = Some(Quiet)
Targets = ["Build"]
Properties =
[
"Configuration", buildMode
"Optimize", "True"
"DebugSymbols", "True"
] }
if isCIBuild then p
else { p with ToolPath = "C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\15.0\Bin\msbuild.exe" }
MSBuild.build setParams "./Chauffeur.sln"
)
Target.create "UnitTests" (fun _ ->
OpenCover.getVersion (Some (fun p -> { p with ExePath = "./tools/OpenCover/tools/OpenCover.Console.exe" }))
let assemblies = !! (sprintf "./Chauffeur.Tests/bin/%s/Chauffeur.Tests.dll" buildMode)
let filename = "coverage-unit-tests.xml"
OpenCover.run (fun p ->
{ p with
ExePath = "./tools/OpenCover/tools/OpenCover.Console.exe"
TestRunnerExePath = "./tools/xunit.runner.console/tools/xunit.console.exe"
Output = testDir @@ filename
Register = RegisterUser
Filter = "+[Chauffeur*]* -[Chauffeur.Tests*]*"
})
(sprintf "%s -noshadow" (assemblies.Includes |> String.concat " " ))
assemblies
|> XUnit2.run (fun p -> { p with XmlOutputPath = Some(testDir @@ "results-unit-tests.xml") })
)
Target.create "EnsureSqlExpressAssemblies" (fun _ ->
Shell.copyDir (sprintf "./Chauffeur.Tests.Integration/bin/%s" buildMode) "packages/UmbracoCms.7.8.0/UmbracoFiles/bin" (fun _ -> true)
)
Target.create "CleanXUnitVSRunner" (fun _ ->
Fake.IO.File.delete (sprintf "./Chauffeur.Tests.Integration/bin/%s/xunit.runner.visualstudio.testadapter.dll" buildMode)
)
Target.create "IntegrationTests" (fun _ ->
OpenCover.getVersion (Some (fun p -> { p with ExePath = "./tools/OpenCover/tools/OpenCover.Console.exe" }))
let filename = "coverage-integration-tests.xml"
let assemblies = !! (sprintf "./Chauffeur.Tests.Integration/bin/%s/Chauffeur.Tests.Integration.dll" buildMode)
OpenCover.run (fun p ->
{ p with
ExePath = "./tools/OpenCover/tools/OpenCover.Console.exe"
TestRunnerExePath = "./tools/xunit.runner.console/tools/xunit.console.exe"
Output = testDir @@ filename
Register = RegisterUser
Filter = "+[Chauffeur*]* -[Chauffeur.Tests*]*"
})
(sprintf "%s -noshadow" (assemblies.Includes |> String.concat " " ))
assemblies
|> XUnit2.run (fun p -> { p with XmlOutputPath = Some(testDir @@ "results-integration-tests.xml") })
)
Target.create "CreateChauffeurPackage" (fun _ ->
let libDir = packagingDir @@ "lib/net45/"
Shell.cleanDirs [libDir]
Shell.copyFile libDir (chauffeurDir @@ "Release/Chauffeur.dll")
Shell.copyFiles packagingDir [".github/License.md"; ".github/readme.md"]
NuGet (fun p ->
{p with
Authors = authors
Project = projectName
Description = chauffeurDescription
OutputPath = packagingRoot
Summary = chauffeurSummary
WorkingDir = packagingDir
Version = nugetVersion
ReleaseNotes = String.toLines releaseNotes.Notes
SymbolPackage = NugetSymbolPackage.Nuspec
AccessKey = Environment.environVarOrDefault "nugetkey" ""
Dependencies =
["System.IO.Abstractions", "1.4.0.93"]
Publish = Environment.hasEnvironVar "nugetkey" }) "Chauffeur/Chauffeur.nuspec"
)
Target.create "CreateRunnerPackage" (fun _ ->
let libDir = packagingRunnerDir @@ "lib/net45/"
Shell.cleanDirs [libDir]
Shell.copyFile libDir (chauffeurRunnerDir @@ "Release/Chauffeur.Runner.exe")
Shell.copyFiles packagingDir [".github/License.md"; ".github/readme.md"]
NuGet (fun p ->
{p with
Authors = authors
Project = (sprintf "%s.Runner" projectName)
Description = chauffeurRunnerDescription
OutputPath = packagingRoot
Summary = chauffeurRunnerSummary
WorkingDir = packagingRunnerDir
Version = nugetVersion
ReleaseNotes = String.toLines releaseNotes.Notes
SymbolPackage = NugetSymbolPackage.Nuspec
Dependencies =
["Chauffeur", nugetVersion]
AccessKey = Environment.environVarOrDefault "nugetkey" ""
Publish = Environment.hasEnvironVar "nugetkey" }) "Chauffeur.Runner/Chauffeur.Runner.nuspec"
)
Target.create "CreateTestingToolsPackage" (fun _ ->
let libDir = packagingTestingToolsDir @@ "lib/net45/"
Shell.cleanDirs [libDir]
Shell.copyFile libDir (chauffeurTestingToolsDir @@ "Release/Chauffeur.TestingTools.dll")
Shell.copyFiles packagingDir [".github/License.md"; ".github/readme.md"]
NuGet (fun p ->
{p with
Authors = authors
Project = (sprintf "%s.TestingTools" projectName)
Description = chauffeurTestingToolsDescription
OutputPath = packagingRoot
Summary = chauffeurTestingToolsSummary
WorkingDir = packagingTestingToolsDir
Version = nugetVersion
ReleaseNotes = String.toLines releaseNotes.Notes
SymbolPackage = NugetSymbolPackage.Nuspec
Dependencies =
[ "Chauffeur", nugetVersion
"FSharp.Core", "4.3.4" ]
AccessKey = Environment.environVarOrDefault "nugetkey" ""
Publish = Environment.hasEnvironVar "nugetkey" }) "Chauffeur.TestingTools/Chauffeur.TestingTools.nuspec"
)
Target.create "Package" ignore
"AssemblyInfo"
==> "Build"
"Clean"
==> "Build"
"RestoreChauffeurPackages"
==> "RestoreChauffeurTestingToolsPackages"
==> "RestoreChauffeurDemoPackages"
==> "RestoreChauffeurTestsPackages"
==> "Build"
"Build"
==> "Default"
"EnsureSqlExpressAssemblies"
==> "CleanXUnitVSRunner"
==> "IntegrationTests"
"CreateChauffeurPackage"
==> "CreateRunnerPackage"
==> "CreateTestingToolsPackage"
==> "Package"
Target.runOrDefault "Default"