forked from nfdi4plants/ARCtrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
480 lines (399 loc) · 18.5 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
#if FAKE
#r "paket:
nuget BlackFox.Fake.BuildTask
nuget Fake.Extensions.Release
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
nuget Fake.Tools.Git //"
#endif
#if !FAKE
#r "nuget: BlackFox.Fake.BuildTask"
#r "nuget: Fake.Extensions.Release"
#r "nuget: Fake.Core.Target"
#r "nuget: Fake.Core.Process"
#r "nuget: Fake.Core.ReleaseNotes"
#r "nuget: Fake.IO.FileSystem"
#r "nuget: Fake.DotNet.Cli"
#r "nuget: Fake.DotNet.MSBuild"
#r "nuget: Fake.DotNet.AssemblyInfoFile"
#r "nuget: Fake.DotNet.Paket"
#r "nuget: Fake.DotNet.FSFormatting"
#r "nuget: Fake.DotNet.Fsi"
#r "nuget: Fake.DotNet.NuGet"
#r "nuget: Fake.Api.Github"
#r "nuget: Fake.DotNet.Testing.Expecto"
#r "nuget: Fake.Tools.Git"
#load "./.fake/build.fsx/intellisense.fsx"
#r "netstandard" // Temp fix for https://github.com/dotnet/fsharp/issues/5216
#endif
open BlackFox.Fake
open System.IO
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Tools
[<AutoOpen>]
/// user interaction prompts for critical build tasks where you may want to interrupt when you see wrong inputs.
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?"""
/// Executes a dotnet command in the given working directory
let runDotNet cmd workingDir =
let result =
DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir
/// Metadata about the project
module ProjectInfo =
let project = "ISADotNet"
let summary = "ISA compliant experimental metadata toolkit in F#"
let configuration = "Release"
// Git configuration (used for publishing documentation in gh-pages branch)
// The profile where the project is posted
let gitOwner = "nfdi4plants"
let gitName = "ISADotNet"
let gitHome = sprintf "%s/%s" "https://github.com" gitOwner
let projectRepo = sprintf "%s/%s/%s" "https://github.com" gitOwner gitName
let website = "/nfdi4plants"
let pkgDir = "pkg"
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let stableVersion = SemVer.parse release.NugetVersion
let stableVersionTag = (sprintf "%i.%i.%i" stableVersion.Major stableVersion.Minor stableVersion.Patch )
let mutable prereleaseSuffix = ""
let mutable prereleaseTag = ""
let mutable isPrerelease = false
let testProject = "tests/ISADotNet.Tests/ISADotNet.Tests.fsproj"
/// Barebones, minimal build tasks
module BasicTasks =
open ProjectInfo
let setPrereleaseTag = BuildTask.create "SetPrereleaseTag" [] {
printfn "Please enter pre-release package suffix"
let suffix = System.Console.ReadLine()
prereleaseSuffix <- suffix
prereleaseTag <- (sprintf "%i.%i.%i-%s" release.SemVer.Major release.SemVer.Minor release.SemVer.Patch suffix)
isPrerelease <- true
}
let clean = BuildTask.create "Clean" [] {
!! "src/**/bin"
++ "src/**/obj"
++ "pkg"
++ "bin"
|> Shell.cleanDirs
}
let build = BuildTask.create "Build" [clean] {
!! "src/**/*.*proj"
|> Seq.iter (DotNet.build id)
}
//let buildFable = BuildTask.create "BuildFable" [clean] {
// !! "src/**/*.*proj"
// |> Seq.iter (DotNet.build (fun p ->
// let properties = (("DefineConstants","FABLE") :: p.MSBuildParams.Properties)
// {p with MSBuildParams = {p.MSBuildParams with Properties = properties}
// }))
//}
let copyBinaries = BuildTask.create "CopyBinaries" [clean; build] {
let targets =
!! "src/**/*.??proj"
-- "src/**/*.shproj"
|> Seq.map (fun f -> ((Path.getDirectory f) </> "bin" </> configuration, "bin" </> (Path.GetFileNameWithoutExtension f)))
for i in targets do printfn "%A" i
targets
|> Seq.iter (fun (fromDir, toDir) -> Shell.copyDir toDir fromDir (fun _ -> true))
}
/// Test executing build tasks
module TestTasks =
open ProjectInfo
open BasicTasks
let cleanTestResults =
BuildTask.create "cleanTestResults" [] {
Shell.cleanDirs (!! "tests/**/**/TestResult")
}
let cleanTestBinaries =
BuildTask.create "cleanTestBinaries" [] {
Shell.cleanDirs (!! "tests/**/bin")
}
let runTests = BuildTask.create "RunTests" [clean; cleanTestBinaries; cleanTestResults; build; copyBinaries] {
let standardParams = Fake.DotNet.MSBuild.CliArguments.Create ()
Fake.DotNet.DotNet.test(fun testParams ->
{
testParams with
Logger = Some "console;verbosity=detailed"
}
) testProject
}
/// Package creation
module PackageTasks =
open ProjectInfo
open BasicTasks
open TestTasks
open System.Text.RegularExpressions
let commitLinkPattern = @"\[\[#[a-z0-9]*\]\(.*\)\] "
let replaceCommitLink input= Regex.Replace(input,commitLinkPattern,"")
let pack = BuildTask.create "Pack" [clean; build; runTests; copyBinaries] {
if promptYesNo (sprintf "creating stable package with version %s OK?" stableVersionTag )
then
!! "src/**/*.*proj"
|> Seq.iter (Fake.DotNet.DotNet.pack (fun p ->
let msBuildParams =
{p.MSBuildParams with
Properties = ([
"Version",stableVersionTag
"PackageReleaseNotes", (release.Notes |> List.map replaceCommitLink |> String.concat "\r\n")
] @ p.MSBuildParams.Properties)
}
{
p with
MSBuildParams = msBuildParams
OutputPath = Some pkgDir
}
))
/// This is used to create ISADotNet.Fable with the Fable subfolder as explained here:
/// https://fable.io/docs/your-fable-project/author-a-fable-library.html
"src/ISADotNet/ISADotNet.fsproj"
|> Fake.DotNet.DotNet.pack (fun p ->
let msBuildParams =
{p.MSBuildParams with
Properties = ([
"PackageId", "ISADotNet.Fable"
"Version",stableVersionTag
"Description","Fable compliant release for the ISA compliant experimental metadata toolkit in F#. Additionally to the compiled library, it is shipped with the uncompiled code."
"PackageTags","F# FSharp dotnet .Net bioinformatics biology datascience metadata investigation study assay ISA Json Fable"
"PackageReleaseNotes", (release.Notes |> List.map replaceCommitLink |> String.concat "\r\n")
] @ p.MSBuildParams.Properties)
}
let test = p
{
p with
MSBuildParams = msBuildParams
OutputPath = Some pkgDir
}
)
else failwith "aborted"
}
let packPrerelease = BuildTask.create "PackPrerelease" [setPrereleaseTag; clean; build; runTests; copyBinaries] {
if promptYesNo (sprintf "package tag will be %s OK?" prereleaseTag )
then
!! "src/**/*.*proj"
//-- "src/**/Plotly.NET.Interactive.fsproj"
|> Seq.iter (Fake.DotNet.DotNet.pack (fun p ->
let msBuildParams =
{p.MSBuildParams with
Properties = ([
"Version", prereleaseTag
"PackageReleaseNotes", (release.Notes |> List.map replaceCommitLink |> String.toLines )
] @ p.MSBuildParams.Properties)
}
{
p with
VersionSuffix = Some prereleaseSuffix
OutputPath = Some pkgDir
MSBuildParams = msBuildParams
}
))
"src/ISADotNet/ISADotNet.fsproj"
|> Fake.DotNet.DotNet.pack (fun p ->
let msBuildParams =
{p.MSBuildParams with
Properties = ([
"PackageId", "ISADotNet.Fable"
"Version",prereleaseTag
"Description","Fable compliant release for the ISA compliant experimental metadata toolkit in F#. Additionally to the compiled library, it is shipped with the uncompiled code."
"PackageTags","F# FSharp dotnet .Net bioinformatics biology datascience metadata investigation study assay ISA Json Fable"
"PackageReleaseNotes", (release.Notes |> List.map replaceCommitLink |> String.concat "\r\n")
] @ p.MSBuildParams.Properties)
}
let test = p
{
p with
VersionSuffix = Some prereleaseSuffix
MSBuildParams = msBuildParams
OutputPath = Some pkgDir
}
)
else
failwith "aborted"
}
/// Build tasks for documentation setup and development
module DocumentationTasks =
open ProjectInfo
open BasicTasks
let initDocPage = BuildTask.create "InitDocsPage" [] {
printfn "Please enter filename"
let filename = System.Console.ReadLine()
printfn "Please enter title"
let title = System.Console.ReadLine()
let path = "./docs" </> filename
let lines = """(*** hide ***)
(*** condition: prepare ***)
#r "../bin/ISADotNet/netstandard2.0/ISADotNet.dll"
#r "../bin/ISADotNet.XLSX/netstandard2.0/ISADotNet.XLSX.dll"
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
#endif // IPYNB
(**
# {{TITLE}}
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{FILENAME}}.ipynb)
*)
"""
if (promptYesNo (sprintf "creating file %s with title %s OK?" path title)) then
lines
|> String.replace "{{FILENAME}}" filename
|> String.replace "{{TITLE}}" title
|> fun content -> File.WriteAllText (path,content)
else
failwith "aborted"
}
let buildDocs = BuildTask.create "BuildDocs" [build; copyBinaries] {
printfn "building docs with stable version %s" stableVersionTag
runDotNet
(sprintf "fsdocs build --eval --clean --property Configuration=Release --parameters fsdocs-package-version %s --noapidocs" stableVersionTag)
"./"
}
let buildDocsPrerelease = BuildTask.create "BuildDocsPrerelease" [setPrereleaseTag; build; copyBinaries] {
printfn "building docs with prerelease version %s" prereleaseTag
runDotNet
(sprintf "fsdocs build --eval --clean --property Configuration=Release --parameters fsdocs-package-version %s --noapidocs" prereleaseTag)
"./"
}
let watchDocs = BuildTask.create "WatchDocs" [build; copyBinaries] {
printfn "watching docs with stable version %s" stableVersionTag
runDotNet
(sprintf "fsdocs watch --eval --clean --property Configuration=Release --parameters fsdocs-package-version %s --noapidocs" stableVersionTag)
"./"
}
let watchDocsPrerelease = BuildTask.create "WatchDocsPrerelease" [setPrereleaseTag; build; copyBinaries] {
printfn "watching docs with prerelease version %s" prereleaseTag
runDotNet
(sprintf "fsdocs watch --eval --clean --property Configuration=Release --parameters fsdocs-package-version %s --noapidocs" prereleaseTag)
"./"
}
/// Buildtasks that release stuff, e.g. packages, git tags, documentation, etc.
module ReleaseTasks =
open ProjectInfo
open BasicTasks
open TestTasks
open PackageTasks
open DocumentationTasks
let createTag = BuildTask.create "CreateTag" [clean; build; copyBinaries; runTests; pack] {
if promptYesNo (sprintf "tagging branch with %s OK?" stableVersionTag ) then
Git.Branches.tag "" stableVersionTag
Git.Branches.pushTag "" projectRepo stableVersionTag
else
failwith "aborted"
}
let createPrereleaseTag = BuildTask.create "CreatePrereleaseTag" [setPrereleaseTag; clean; build; copyBinaries; runTests; packPrerelease] {
if promptYesNo (sprintf "tagging branch with %s OK?" prereleaseTag ) then
Git.Branches.tag "" prereleaseTag
Git.Branches.pushTag "" projectRepo prereleaseTag
else
failwith "aborted"
}
let publishNuget = BuildTask.create "PublishNuget" [clean; build; copyBinaries; runTests; pack] {
let targets = (!! (sprintf "%s/*.*pkg" pkgDir ))
for target in targets do printfn "%A" target
let msg = sprintf "release package with version %s?" stableVersionTag
if promptYesNo msg then
let source = "https://api.nuget.org/v3/index.json"
let apikey = Environment.environVar "NUGET_KEY"
for artifact in targets do
let result = DotNet.exec id "nuget" (sprintf "push -s %s -k %s %s --skip-duplicate" source apikey artifact)
if not result.OK then failwith "failed to push packages"
else failwith "aborted"
}
let publishNugetPrerelease = BuildTask.create "PublishNugetPrerelease" [clean; build; copyBinaries; runTests; packPrerelease] {
let targets = (!! (sprintf "%s/*.*pkg" pkgDir ))
for target in targets do printfn "%A" target
let msg = sprintf "release package with version %s?" prereleaseTag
if promptYesNo msg then
let source = "https://api.nuget.org/v3/index.json"
let apikey = Environment.environVar "NUGET_KEY"
for artifact in targets do
let result = DotNet.exec id "nuget" (sprintf "push -s %s -k %s %s --skip-duplicate" source apikey artifact)
if not result.OK then failwith "failed to push packages"
else failwith "aborted"
}
let releaseDocs = BuildTask.create "ReleaseDocs" [buildDocs] {
let msg = sprintf "release docs for version %s?" stableVersionTag
if promptYesNo msg then
Shell.cleanDir "temp"
Git.CommandHelper.runSimpleGitCommand "." (sprintf "clone %s temp/gh-pages --depth 1 -b gh-pages" projectRepo) |> ignore
Shell.copyRecursive "output" "temp/gh-pages" true |> printfn "%A"
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" "add ." |> printfn "%s"
let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" stableVersionTag
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd |> printfn "%s"
Git.Branches.push "temp/gh-pages"
else failwith "aborted"
}
let prereleaseDocs = BuildTask.create "PrereleaseDocs" [buildDocsPrerelease] {
let msg = sprintf "release docs for version %s?" prereleaseTag
if promptYesNo msg then
Shell.cleanDir "temp"
Git.CommandHelper.runSimpleGitCommand "." (sprintf "clone %s temp/gh-pages --depth 1 -b gh-pages" projectRepo) |> ignore
Shell.copyRecursive "output" "temp/gh-pages" true |> printfn "%A"
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" "add ." |> printfn "%s"
let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" prereleaseTag
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd |> printfn "%s"
Git.Branches.push "temp/gh-pages"
else failwith "aborted"
}
module ReleaseNoteTasks =
open Fake.Extensions.Release
let createAssemblyVersion = BuildTask.create "createvfs" [] {
AssemblyVersion.create ProjectInfo.gitName
}
let updateReleaseNotes = BuildTask.createFn "ReleaseNotes" [] (fun config ->
Release.exists()
Release.update(ProjectInfo.gitOwner, ProjectInfo.gitName, config)
)
let githubDraft = BuildTask.createFn "GithubDraft" [] (fun config ->
let body = "We are ready to go for the first release!"
Github.draft(
ProjectInfo.gitOwner,
ProjectInfo.gitName,
(Some body),
None,
config
)
)
open BasicTasks
open TestTasks
open PackageTasks
open DocumentationTasks
open ReleaseTasks
/// Full release of nuget package, git tag, and documentation for the stable version.
let _release =
BuildTask.createEmpty
"Release"
[clean; build; copyBinaries; runTests; pack; buildDocs; createTag; publishNuget; releaseDocs]
/// Full release of nuget package, git tag, and documentation for the prerelease version.
let _preRelease =
BuildTask.createEmpty
"PreRelease"
[setPrereleaseTag; clean; build; copyBinaries; runTests; packPrerelease; buildDocsPrerelease; createPrereleaseTag; publishNugetPrerelease; prereleaseDocs]
// run copyBinaries by default
BuildTask.runOrDefaultWithArguments copyBinaries