1
+ #r " paket:
2
+ nuget BlackFox.Fake.BuildTask
3
+ nuget Fake.Core.Target
4
+ nuget Fake.Core.Process
5
+ nuget Fake.Core.ReleaseNotes
6
+ nuget Fake.IO.FileSystem
7
+ nuget Fake.DotNet.Cli
8
+ nuget Fake.DotNet.MSBuild
9
+ nuget Fake.DotNet.AssemblyInfoFile
10
+ nuget Fake.DotNet.Paket
11
+ nuget Fake.DotNet.FSFormatting
12
+ nuget Fake.DotNet.Fsi
13
+ nuget Fake.DotNet.NuGet
14
+ nuget Fake.Api.Github
15
+ nuget Fake.DotNet.Testing.Expecto
16
+ nuget Fake.Tools.Git //"
17
+
18
+ #if ! FAKE
19
+ #load " ./.fake/build.fsx/intellisense.fsx"
20
+ #r " netstandard" // Temp fix for https://github.com/dotnet/fsharp/issues/5216
21
+ #endif
22
+
23
+ open BlackFox.Fake
24
+ open System.IO
25
+ open Fake.Core
26
+ open Fake.DotNet
27
+ open Fake.IO
28
+ open Fake.IO .FileSystemOperators
29
+ open Fake.IO .Globbing .Operators
30
+ open Fake.Tools
31
+
32
+ [<AutoOpen>]
33
+ /// user interaction prompts for critical build tasks where you may want to interrupt when you see wrong inputs.
34
+ module MessagePrompts =
35
+
36
+ let prompt ( msg : string ) =
37
+ System.Console.Write( msg)
38
+ System.Console.ReadLine() .Trim()
39
+ |> function | " " -> None | s -> Some s
40
+ |> Option.map ( fun s -> s.Replace ( " \" " , " \\\" " ))
41
+
42
+ let rec promptYesNo msg =
43
+ match prompt ( sprintf " %s [Yn]: " msg) with
44
+ | Some " Y" | Some " y" -> true
45
+ | Some " N" | Some " n" -> false
46
+ | _ -> System.Console.WriteLine( " Sorry, invalid answer" ); promptYesNo msg
47
+
48
+ 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.
49
+ Do you want to continue?"""
50
+
51
+ let releaseDocsMsg = """ This will push the docs to gh-pages. Remember building the docs prior to this. Do you want to continue?"""
52
+
53
+ /// Executes a dotnet command in the given working directory
54
+ let runDotNet cmd workingDir =
55
+ let result =
56
+ DotNet.exec ( DotNet.Options.withWorkingDirectory workingDir) cmd " "
57
+ if result.ExitCode <> 0 then failwithf " 'dotnet %s ' failed in %s " cmd workingDir
58
+
59
+ /// Metadata about the project
60
+ module ProjectInfo =
61
+
62
+ let project = " BioFSharp.Vis"
63
+
64
+ let summary = " Programmatic access to Biological Databases from F#"
65
+
66
+ let configuration = " Release"
67
+
68
+ // Git configuration (used for publishing documentation in gh-pages branch)
69
+ // The profile where the project is posted
70
+ let gitOwner = " CSBiology"
71
+ let gitName = " BioFSharp.Vis"
72
+
73
+ let solutionFile = " BioFSharp.Vis.sln"
74
+
75
+ let gitHome = sprintf " %s /%s " " https://github.com" gitOwner
76
+
77
+ let projectRepo = sprintf " %s /%s /%s " " https://github.com" gitOwner gitName
78
+
79
+ let website = " /BioFSharp.Vis"
80
+
81
+ let testProject = " tests/BioFSharp.Vis.Tests/BioFSharp.Vis.Tests.fsproj"
82
+
83
+ let pkgDir = " pkg"
84
+
85
+ let release = ReleaseNotes.load " RELEASE_NOTES.md"
86
+
87
+ let stableVersion = SemVer.parse release.NugetVersion
88
+
89
+ let stableVersionTag = ( sprintf " %i .%i .%i " stableVersion.Major stableVersion.Minor stableVersion.Patch )
90
+
91
+ let mutable prereleaseSuffix = " "
92
+
93
+ let mutable prereleaseTag = " "
94
+
95
+ let mutable isPrerelease = false
96
+
97
+ /// Barebones, minimal build tasks
98
+ module BasicTasks =
99
+
100
+ open ProjectInfo
101
+
102
+ let setPrereleaseTag = BuildTask.create " SetPrereleaseTag" [] {
103
+ printfn " Please enter pre-release package suffix"
104
+ let suffix = System.Console.ReadLine()
105
+ prereleaseSuffix <- suffix
106
+ prereleaseTag <- ( sprintf " %s -%s " release.NugetVersion suffix)
107
+ isPrerelease <- true
108
+ }
109
+
110
+ let clean = BuildTask.create " Clean" [] {
111
+ !! " src/**/bin"
112
+ ++ " src/**/obj"
113
+ ++ " pkg"
114
+ ++ " bin"
115
+ |> Shell.cleanDirs
116
+ }
117
+
118
+ let restore = BuildTask.create " Restore" [ clean] {
119
+ !! " src/**/*.*proj"
120
+ |> Seq.iter ( DotNet.restore id)
121
+ }
122
+
123
+ let build = BuildTask.create " Build" [ clean; restore] {
124
+ let setParams ( defaults : MSBuildParams ) =
125
+ { defaults with
126
+ Verbosity = Some( Quiet)
127
+ Targets = [ " Build" ]
128
+ Properties =
129
+ [
130
+ " Optimize" , " True"
131
+ " DebugSymbols" , " True"
132
+ " Configuration" , configuration
133
+ " VersionPrefix" , release.NugetVersion
134
+ if isPrerelease then ( " VersionSuffix" , prereleaseSuffix)
135
+ ]
136
+ }
137
+ MSBuild.build setParams solutionFile
138
+ }
139
+
140
+ let copyBinaries = BuildTask.create " CopyBinaries" [ clean; restore; build] {
141
+ let targets =
142
+ !! " src/**/*.??proj"
143
+ -- " src/**/*.shproj"
144
+ |> Seq.map ( fun f -> (( Path.getDirectory f) </> " bin" </> configuration, " bin" </> ( Path.GetFileNameWithoutExtension f)))
145
+ for i in targets do printfn " %A " i
146
+ targets
147
+ |> Seq.iter ( fun ( fromDir , toDir ) -> Shell.copyDir toDir fromDir ( fun _ -> true ))
148
+ }
149
+
150
+ /// Test executing build tasks
151
+ module TestTasks =
152
+
153
+ open ProjectInfo
154
+ open BasicTasks
155
+
156
+ let testAssemblies = " tests/**/bin" </> configuration </> " **" </> " *Tests.exe"
157
+
158
+ let runTests = BuildTask.create " runTests" [ clean; restore; build; copyBinaries] {
159
+ let assemblies = !! testAssemblies
160
+
161
+ assemblies
162
+ |> Seq.iter ( fun f ->
163
+ Command.RawCommand (
164
+ f,
165
+ Arguments.OfArgs []
166
+ )
167
+ |> CreateProcess.fromCommand
168
+ |> CreateProcess.withFramework
169
+ |> CreateProcess.ensureExitCode
170
+ |> Proc.run
171
+ |> ignore
172
+ )
173
+ }
174
+
175
+ /// Package creation
176
+ module PackageTasks =
177
+
178
+ open ProjectInfo
179
+
180
+ open BasicTasks
181
+ open TestTasks
182
+
183
+ let pack = BuildTask.create " Pack" [ clean; restore; build; runTests; copyBinaries] {
184
+ if promptYesNo ( sprintf " creating stable package with version %s OK?" stableVersionTag )
185
+ then
186
+ !! " src/**/*.*proj"
187
+ |> Seq.iter ( Fake.DotNet.DotNet.pack ( fun p ->
188
+ let msBuildParams =
189
+ { p.MSBuildParams with
190
+ Properties = ([
191
+ " Version" , stableVersionTag
192
+ " PackageReleaseNotes" , ( release.Notes |> String.concat " \r\n " )
193
+ " TargetFrameworks" , " net47"
194
+ ] @ p.MSBuildParams.Properties)
195
+ }
196
+ {
197
+ p with
198
+ MSBuildParams = msBuildParams
199
+ OutputPath = Some pkgDir
200
+ }
201
+ ))
202
+ else failwith " aborted"
203
+ }
204
+
205
+ let packPrerelease = BuildTask.create " PackPrerelease" [ setPrereleaseTag; clean; restore; build; runTests; copyBinaries] {
206
+ if promptYesNo ( sprintf " package tag will be %s OK?" prereleaseTag )
207
+ then
208
+ !! " src/**/*.*proj"
209
+ //-- "src/**/Plotly.NET.Interactive.fsproj"
210
+ |> Seq.iter ( Fake.DotNet.DotNet.pack ( fun p ->
211
+ let msBuildParams =
212
+ { p.MSBuildParams with
213
+ Properties = ([
214
+ " Version" , prereleaseTag
215
+ " PackageReleaseNotes" , ( release.Notes |> String.toLines )
216
+ " TargetFrameworks" , " net47"
217
+ ] @ p.MSBuildParams.Properties)
218
+ }
219
+ {
220
+ p with
221
+ VersionSuffix = Some prereleaseSuffix
222
+ OutputPath = Some pkgDir
223
+ MSBuildParams = msBuildParams
224
+ }
225
+ ))
226
+ else
227
+ failwith " aborted"
228
+ }
229
+
230
+ open BasicTasks
231
+ open TestTasks
232
+ open PackageTasks
233
+
234
+ BuildTask.runOrDefault pack
0 commit comments