forked from CSBiology/BioFSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
524 lines (452 loc) · 18.9 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "paket:
nuget BlackFox.Fake.BuildTask
nuget Fake.Core.Target
nuget Fake.Core.Process
nuget Fake.Core.ReleaseNotes
nuget Fake.IO.FileSystem
nuget Fake.DotNet.Cli
nuget Fake.DotNet.MSBuild
nuget Fake.DotNet.AssemblyInfoFile
nuget Fake.DotNet.Paket
nuget Fake.DotNet.FSFormatting
nuget Fake.DotNet.Fsi
nuget Fake.DotNet.NuGet
nuget Fake.Api.Github
nuget Fake.DotNet.Testing.Expecto //"
#load ".fake/build.fsx/intellisense.fsx"
open BlackFox.Fake
open System.IO
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing
open Fake.IO.Globbing.Operators
open Fake.DotNet.Testing
open Fake.Tools
open Fake.Api
open Fake.Tools.Git
Target.initEnvironment ()
[<AutoOpen>]
module MessagePrompts =
let prompt (msg:string) =
System.Console.Write(msg)
System.Console.ReadLine().Trim()
|> function | "" -> None | s -> Some s
|> Option.map (fun s -> s.Replace ("\"","\\\""))
let rec promptYesNo msg =
match prompt (sprintf "%s [Yn]: " msg) with
| Some "Y" | Some "y" -> true
| Some "N" | Some "n" -> false
| _ -> System.Console.WriteLine("Sorry, invalid answer"); promptYesNo msg
let releaseMsg = """This will stage all uncommitted changes, push them to the origin and bump the release version to the latest number in the RELEASE_NOTES.md file.
Do you want to continue?"""
let releaseDocsMsg = """This will push the docs to gh-pages. Remember building the docs prior to this. Do you want to continue?"""
// --------------------------------------------------------------------------------------
// START TODO: Provide project-specific details below
// --------------------------------------------------------------------------------------
let project = "BioFSharp"
let summary = "An open source bioinformatics toolbox written in F#. <https://csbiology.github.io/BioFSharp/>"
let solutionFile = "BioFSharp.sln"
let configuration = "Release"
let testAssemblies = "tests/**/bin" </> configuration </> "**" </> "*Tests.exe"
let gitOwner = "CSBiology"
let gitHome = sprintf "%s/%s" "https://github.com" gitOwner
let gitName = "BioFSharp"
let website = "/BioFSharp"
let pkgDir = "pkg"
//Build configurations
let monoConfiguration = DotNet.Custom "Mono"
let dotnetCoreConfiguration = DotNet.Custom "DotnetCore"
let buildConfiguration = DotNet.Custom <| Environment.environVarOrDefault "configuration" configuration
let buildServerSuffix =
match BuildServer.buildServer with
|BuildServer.AppVeyor -> sprintf "appveyor.%s" BuildServer.appVeyorBuildVersion
|BuildServer.Travis -> sprintf "travis.%s" BuildServer.travisBuildNumber
| _ -> ""
// Read additional information from the release notes document
let release = ReleaseNotes.load "RELEASE_NOTES.md"
//---------------------------------------------------------------------------------------------------------------------------------
// Projects for different buildConfigs
// when building everything on windows (netstandard 2.0 + netfx)
let allProjectPaths =
!! "src/**/*.fsproj"
|> Seq.map
(fun f -> (Path.getDirectory f))
// projects built with the mono configuration (ik cant get bioDB to work here)
let monoProjectPaths =
!! "src/**/*.fsproj"
-- "src/BioFSharp.BioDB/BioFSharp.BioDB.fsproj"
|> Seq.map
(fun f -> (Path.getDirectory f))
// netstandard2.0 projects only
let dotnetProjectPaths =
!! "src/**/*.fsproj"
-- "src/BioFSharp.BioDB/BioFSharp.BioDB.fsproj"
-- "src/BioFSharp.Parallel/BioFSharp.Parallel.fsproj"
-- "src/BioFSharp.ImgP/BioFSharp.ImgP.fsproj"
-- "src/BioFSharp.Vis/BioFSharp.Vis.fsproj"
|> Seq.map
(fun f -> (Path.getDirectory f))
//---------------------------------------------------------------------------------------------------------------------------------
//======================================================= Build Tasks =============================================================
//---------------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------------
// Clean build results
let clean =
BuildTask.create "clean" [] {
Shell.cleanDirs [
"bin"; "temp"; "pkg"
yield! allProjectPaths |> Seq.map (fun x -> x </> "bin")
]
}
let cleanDocs =
BuildTask.create "cleanDocs" [] {
Shell.cleanDirs ["docs"]
}
// --------------------------------------------------------------------------------------------------------------------------------
// Generate assembly info files with the right version & up-to-date information. Clean first.
let assemblyInfo =
BuildTask.create "assemblyInfo" [clean.IfNeeded] {
let getAssemblyInfoAttributes projectName =
[ AssemblyInfo.Title (projectName)
AssemblyInfo.Product project
AssemblyInfo.Description summary
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion
AssemblyInfo.Configuration configuration ]
let getProjectDetails projectPath =
let projectName = Path.GetFileNameWithoutExtension(projectPath)
( projectPath,
projectName,
Path.GetDirectoryName(projectPath),
(getAssemblyInfoAttributes projectName)
)
!! "src/**/*.fsproj"
|> Seq.map getProjectDetails
|> Seq.iter
(fun (projFileName, _, folderName, attributes) ->
AssemblyInfoFile.createFSharp (folderName </> "AssemblyInfo.fs") attributes
)
}
// --------------------------------------------------------------------------------------------------------------------------------
// Build library & test project. build assembly info first
let buildAll =
BuildTask.create "buildAll" [clean.IfNeeded; assemblyInfo] {
let setParams (defaults:MSBuildParams) =
{ defaults with
Verbosity = Some(Quiet)
Targets = ["Build"]
Properties =
[
"Optimize", "True"
"DebugSymbols", "True"
"Configuration", configuration
]
}
MSBuild.build setParams solutionFile
}
let buildMono =
BuildTask.create "buildMono" [clean.IfNeeded; assemblyInfo] {
let setParams (defaults:MSBuildParams) =
{ defaults with
Verbosity = Some(Quiet)
Targets = ["Build"]
Properties =
[
"Optimize", "True"
"DebugSymbols", "True"
"Configuration", "Mono"
]
}
MSBuild.build setParams solutionFile
}
let buildDotnet =
BuildTask.create "buildDotnet" [clean.IfNeeded; assemblyInfo] {
solutionFile
|> DotNet.build (fun p ->
{ p with
Configuration = dotnetCoreConfiguration }
)
}
// --------------------------------------------------------------------------------------------------------------------------------
// Copies binaries from default VS location to expected bin folder
// But keeps a subdirectory structure for each project in the
// src folder to support multiple project outputs
// Build first.
let copyBinaries =
BuildTask.create "copyBinaries" [clean.IfNeeded; assemblyInfo.IfNeeded; buildAll] {
!! "src/**/*.fsproj"
|> Seq.map
(fun f -> (Path.getDirectory f) </> "bin" </> configuration, "bin" </> (Path.GetFileNameWithoutExtension f))
|> Seq.iter
(fun (fromDir, toDir) ->
printfn "copy from %s to %s" fromDir toDir
Shell.copyDir toDir fromDir (fun _ -> true)
)
}
let copyBinariesMono =
BuildTask.create "copyBinariesMono" [clean.IfNeeded; assemblyInfo.IfNeeded; buildMono] {
//only select projects with the mono configuration
!! "src/**/*.fsproj"
-- "src/BioFSharp.BioDB/BioFSharp.BioDB.fsproj"
|> Seq.map (fun f -> (Path.getDirectory f) </> "bin" </> "Mono", "bin" </> (Path.GetFileNameWithoutExtension f))
|> Seq.iter
(fun (fromDir, toDir) ->
printfn "copy from %s to %s" fromDir toDir
Shell.copyDir toDir fromDir (fun _ -> true)
)
}
let copyBinariesDotnet =
BuildTask.create "copyBinariesDotnet" [clean.IfNeeded; assemblyInfo.IfNeeded; buildDotnet] {
//only select projects with the dotnet configuration
!! "src/**/*.fsproj"
-- "src/BioFSharp.BioDB/BioFSharp.BioDB.fsproj"
-- "src/BioFSharp.Parallel/BioFSharp.Parallel.fsproj"
-- "src/BioFSharp.ImgP/BioFSharp.ImgP.fsproj"
-- "src/BioFSharp.Vis/BioFSharp.Vis.fsproj"
|> Seq.map (fun f -> ((Path.getDirectory f) </> "bin" </> "DotnetCore", "bin" </> (Path.GetFileNameWithoutExtension f)))
|> Seq.iter
(fun (fromDir, toDir) ->
printfn "copy from %s to %s" fromDir toDir
Shell.copyDir toDir fromDir (fun _ -> true)
)
}
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner. Of course build the assemblies to test first
let runTestsAll =
BuildTask.create "runTestsAll" [clean.IfNeeded; assemblyInfo.IfNeeded; copyBinaries.IfNeeded; buildAll] {
let assemblies = !! testAssemblies
assemblies
|> Seq.iter (fun f ->
Command.RawCommand (
f,
Arguments.OfArgs []
)
|> CreateProcess.fromCommand
|> CreateProcess.withFramework
|> CreateProcess.ensureExitCode
|> Proc.run
|> ignore
)
}
let runTestsMono =
BuildTask.create "runTestsMono" [clean.IfNeeded; assemblyInfo.IfNeeded; copyBinariesMono.IfNeeded; buildMono] {
let assemblies = !! testAssemblies
assemblies
|> Seq.iter (fun f ->
Command.RawCommand (
f,
Arguments.OfArgs []
)
|> CreateProcess.fromCommand
|> CreateProcess.withFramework
|> CreateProcess.ensureExitCode
|> Proc.run
|> ignore
)
}
// --------------------------------------------------------------------------------------
// Build a NuGet package. Build and test packages first
let buildPrereleasePackages =
BuildTask.create "buildPrereleasePackages" [buildAll; runTestsAll] {
printfn "Please enter pre-release package suffix"
let suffix = System.Console.ReadLine()
Paket.pack(fun p ->
{ p with
ToolType = ToolType.CreateLocalTool()
OutputPath = pkgDir
Version = sprintf "%s-%s" release.NugetVersion suffix
ReleaseNotes = release.Notes |> String.toLines })
}
let BuildReleasePackages =
BuildTask.create "BuildReleasePackages" [buildAll; runTestsAll] {
Paket.pack(fun p ->
{ p with
ToolType = ToolType.CreateLocalTool()
OutputPath = pkgDir
Version = release.NugetVersion
ReleaseNotes = release.Notes |> String.toLines })
}
//dependencies for cI will be resolved in the CI build task.
let buildCIPackages name config projectPaths =
BuildTask.create (sprintf "buildCIPackages%s" name) [
buildAll.IfNeeded; runTestsAll.IfNeeded; copyBinaries.IfNeeded
buildMono.IfNeeded; runTestsMono.IfNeeded; copyBinariesMono.IfNeeded
buildDotnet.IfNeeded; copyBinariesDotnet.IfNeeded
]
{
projectPaths
|> Seq.iter
(fun proj ->
Paket.pack (fun p ->
{ p with
BuildConfig = config
TemplateFile = proj </> "paket.template"
ToolType = ToolType.CreateLocalTool()
OutputPath = pkgDir
Version = sprintf "%s-%s" release.NugetVersion buildServerSuffix
ReleaseNotes = release.Notes |> String.toLines
}
)
)
}
let publishNugetPackages =
BuildTask.create "publishNugetPackages" [buildAll; runTestsAll; BuildReleasePackages] {
Paket.push(fun p ->
{ p with
WorkingDir = pkgDir
ToolType = ToolType.CreateLocalTool()
ApiKey = Environment.environVarOrDefault "NuGet-key" "" })
}
// --------------------------------------------------------------------------------------
// Generate the documentation
// Paths with template/source/output locations
let bin = __SOURCE_DIRECTORY__ @@ "bin"
let content = __SOURCE_DIRECTORY__ @@ "docsrc/content"
let output = __SOURCE_DIRECTORY__ @@ "docs"
let files = __SOURCE_DIRECTORY__ @@ "docsrc/files"
let templates = __SOURCE_DIRECTORY__ @@ "docsrc/tools/templates"
let formatting = __SOURCE_DIRECTORY__ @@ "packages/formatting/FSharp.Formatting"
let docTemplate = "docpage.cshtml"
let github_release_user = Environment.environVarOrDefault "github_release_user" gitOwner
let githubLink = sprintf "https://github.com/%s/%s" github_release_user gitName
// Specify more information about your project
let info =
[ "project-name", "BioFSharp"
"project-author", "Timo Mühlhaus"
"project-summary", "An open source bioinformatics toolbox written in F#. <https://csbiology.github.io/BioFSharp/>"
"project-github", githubLink
"project-nuget", "http://nuget.org/packages/BioFSharp" ]
let generateDocumentation =
BuildTask.create "generateDocumentation" [buildAll] {
let result =
DotNet.exec
(fun p -> { p with WorkingDirectory = __SOURCE_DIRECTORY__ @@ "docsrc" @@ "tools" })
"fsi"
"--define:RELEASE --define:REFERENCE --define:HELP --exec generate.fsx"
if not result.OK then
failwith "error generating docs"
}
// --------------------------------------------------------------------------------------
// Release Scripts
//#load "paket-files/fsharp/FAKE/modules/Octokit/Octokit.fsx"
//open Octokit
let askForDocReleaseConfirmation =
BuildTask.create "askForDocReleaseConfirmation" [] {
match promptYesNo releaseDocsMsg with | true -> () |_ -> failwith "Release canceled"
}
let releaseDocsToGhPages =
BuildTask.create "releaseDocsToGhPages" [askForDocReleaseConfirmation;generateDocumentation] {
let tempDocsDir = "temp/gh-pages"
Shell.cleanDir tempDocsDir |> ignore
Git.Repository.cloneSingleBranch "" (gitHome + "/" + gitName + ".git") "gh-pages" tempDocsDir
Shell.copyRecursive "docs" tempDocsDir true |> printfn "%A"
Git.Staging.stageAll tempDocsDir
Git.Commit.exec tempDocsDir (sprintf "Update generated documentation for version %s" release.NugetVersion)
Git.Branches.push tempDocsDir
}
let buildLocalDocs =
BuildTask.create "buildLocalDocs" [generateDocumentation] {
let tempDocsDir = "temp/localDocs"
Shell.cleanDir tempDocsDir |> ignore
Shell.copyRecursive "docs" tempDocsDir true |> printfn "%A"
Shell.replaceInFiles
(seq {
yield "href=\"/" + project + "/","href=\""
yield "src=\"/" + project + "/","src=\""})
(Directory.EnumerateFiles tempDocsDir |> Seq.filter (fun x -> x.EndsWith(".html")))
}
let askForReleaseConfirmation =
BuildTask.create "askForReleaseConfirmation" [] {
match promptYesNo releaseMsg with | true -> () |_ -> failwith "Release canceled"
}
let releaseOnGithub =
BuildTask.create "releaseOnGithub" [askForReleaseConfirmation; buildAll; runTestsAll;] {
Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Bump version to %s" release.NugetVersion)
Git.Branches.push ""
Git.Branches.tag "" release.NugetVersion
Git.Branches.pushTag "" "upstream" release.NugetVersion
}
let askForGitReleaseNugetConfirmation =
BuildTask.create "askForGitReleaseNugetConfirmation" [] {
match promptYesNo releaseMsg with | true -> () |_ -> failwith "Release canceled"
}
let releaseNugetPackageOnGithub =
BuildTask.create "releaseNugetPackageOnGithub" [askForGitReleaseNugetConfirmation; buildAll; runTestsAll;] {
let tempNugetDir = "temp/nuget"
Shell.cleanDir tempNugetDir |> ignore
Git.Repository.cloneSingleBranch "" (gitHome + "/" + gitName + ".git") "nuget" tempNugetDir
let files = Directory.EnumerateFiles pkgDir
Shell.copy tempNugetDir files
Git.Staging.stageAll tempNugetDir
Git.Commit.exec tempNugetDir (sprintf "Update git nuget packages for version %s" release.NugetVersion)
Git.Branches.push tempNugetDir
Shell.copy tempNugetDir files
}
//Buildchains
//Token Targets for local builds
let fullBuildChainLocal =
BuildTask.createEmpty "fullBuildChainLocal" [
clean
assemblyInfo
buildAll
copyBinaries
runTestsAll
cleanDocs
generateDocumentation
BuildReleasePackages
]
let monoBuildChainLocal =
BuildTask.createEmpty "monoBuildChainLocal" [
clean
assemblyInfo
buildMono
copyBinariesMono
runTestsMono
]
let dotnetBuildChainLocal =
BuildTask.createEmpty "dotnetBuildChainLocal" [
clean
assemblyInfo
buildDotnet
copyBinariesDotnet
]
//Token Targets for CI builds
let fullBuildChainCI =
BuildTask.createEmpty "fullBuildChainCI" [
clean
assemblyInfo
buildAll
copyBinaries
runTestsAll
(buildCIPackages "AppveyorWindows" configuration allProjectPaths)
]
let monoBuildChainCI =
BuildTask.createEmpty "monoBuildChainCI" [
clean
assemblyInfo
buildMono
copyBinariesMono
runTestsMono
//(buildCIPackages "TravisMono" "Mono" monoProjectPaths)
]
let dotnetBuildChainCI =
BuildTask.createEmpty "dotnetBuildChainCI" [
clean
assemblyInfo
buildDotnet
copyBinariesDotnet
//(buildCIPackages "AppveyorDotnet" "DotnetCore" dotnetProjectPaths)
]
Target.create "PrintGraph" (fun _ ->
printfn "What target?"
let t = System.Console.ReadLine()
Target.printDependencyGraph true t
)
BuildTask.runOrDefaultWithArguments fullBuildChainLocal