-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
266 lines (205 loc) · 8.86 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
// --------------------------------------------------------------------------------------
// FAKE Build Script.
// --------------------------------------------------------------------------------------
#r "paket: groupref build //"
#if !FAKE
#load ".fake/build.fsx/intellisense.fsx"
#r "netstandard"
#endif
open System
open System.IO
open Fake.Core
open Fake.DotNet
open Fake.DotNet.NuGet
open Fake.DotNet.Testing
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open Fake.Tools.Git
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let (!!) includes =
(!!includes).SetBaseDirectory __SOURCE_DIRECTORY__
// --------------------------------------------------------------------------------------
// Project Information.
// --------------------------------------------------------------------------------------
let project = "BioProviders"
let authors = "Alex Kenna;Samuel Smith;fsprojects contributors"
let summary = "F# library for accessing and manipulating bioinformatic datasets."
let description =
"""
The BioProviders library provides tools and functionality to simplify accessing and
manipulating bioinformatic data. This library includes:
* GenBankProvider — Type Provider for type-safe access to the genomic sequences and
their metadata for over 500,000 species in the GenBank database.
* RefSeqProvider — Type Provider for type-safe access to the genomic sequences and
their metadata for over 140,000 species in the RefSeq database.
"""
let tags = "F# fsharp data typeprovider bioinformatics genbank refseq"
let gitOwner = "fsprojects"
let gitHome = "https://github.com/" + gitOwner
let gitName = "BioProviders"
let packageProjectUrl = "https://fsprojects.github.io/BioProviders/"
let repositoryType = "git"
let repositoryUrl = "https://github.com/fsprojects/BioProviders"
let license = "MIT"
// Read release notes & version info from RELEASE_NOTES.md
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let isCI = Environment.GetEnvironmentVariable("CI") <> null
// --------------------------------------------------------------------------------------
// Generate Assembly Information.
// --------------------------------------------------------------------------------------
Target.create "AssemblyInfo" (fun _ ->
for file in !! "src/AssemblyInfo*.fs" do
let replace (oldValue: string) newValue (str: string) = str.Replace(oldValue, newValue)
let title =
Path.GetFileNameWithoutExtension file |> replace "AssemblyInfo" "BioProviders"
let versionSuffix = ".0"
let version = release.AssemblyVersion + versionSuffix
AssemblyInfoFile.createFSharp
file
[ AssemblyInfo.Title title
AssemblyInfo.Product project
AssemblyInfo.Description summary
AssemblyInfo.Version version
AssemblyInfo.FileVersion version ])
// --------------------------------------------------------------------------------------
// Clean Build Results.
// --------------------------------------------------------------------------------------
Target.create "Clean" (fun _ ->
seq {
yield! !! "**/bin"
yield! !! "**/obj"
yield! !! "**/temp"
}
|> Shell.cleanDirs)
Target.create "CleanDocs" (fun _ -> Shell.cleanDirs [ "output" ])
// --------------------------------------------------------------------------------------
// Build Library & Test Projects
// --------------------------------------------------------------------------------------
Target.create "Build" (fun _ ->
"BioProviders.sln"
|> DotNet.build (fun o ->
{ o with
Configuration = DotNet.BuildConfiguration.Release })
"BioProviders.TestsAndDocs.sln"
|> DotNet.build (fun o ->
{ o with
Configuration = DotNet.BuildConfiguration.Release }))
Target.create "RunTests" (fun _ ->
let setParams (o: DotNet.TestOptions) =
{ o with
Configuration = DotNet.BuildConfiguration.Release
Logger = if isCI then Some "GitHubActions" else None }
"BioProviders.sln" |> DotNet.test setParams
"BioProviders.TestsAndDocs.sln" |> DotNet.test setParams)
// --------------------------------------------------------------------------------------
// Build Packages.
// --------------------------------------------------------------------------------------
Target.create "Pack" (fun _ ->
// Format the release notes
let releaseNotes = release.Notes |> String.concat "\n"
let properties =
[ ("Version", release.NugetVersion)
("Authors", authors)
("PackageProjectUrl", packageProjectUrl)
("PackageTags", tags)
("RepositoryType", repositoryType)
("RepositoryUrl", repositoryUrl)
("PackageLicenseExpression", license)
("PackageReleaseNotes", releaseNotes)
("Summary", summary)
("PackageDescription", description) ]
DotNet.pack
(fun p ->
{ p with
Configuration = DotNet.BuildConfiguration.Release
OutputPath = Some "bin"
MSBuildParams =
{ p.MSBuildParams with
Properties = properties } })
"BioProviders.sln")
// --------------------------------------------------------------------------------------
// Generate Documentation.
// --------------------------------------------------------------------------------------
Target.create "GenerateDocs" (fun _ ->
printfn "First run of generating documentation (to get API pages)"
Shell.cleanDir ".fsdocs"
let result1 =
DotNet.exec
id
"fsdocs"
("build --properties Configuration=Release --eval --clean --parameters fsdocs-package-version "
+ release.NugetVersion)
if not result1.OK then
printfn "Errors while generating docs: %A" result1.Messages
failwith "Failed to generate docs"
printfn "Moving API pages before cleaning previous output"
if (Directory.Exists("temp")) then
Shell.cleanDir ("temp")
else
Directory.create ("temp")
Directory.Move("output/reference", "temp/reference")
printfn "Second run of generating documentation (to get script output)"
Shell.cleanDir ".fsdocs"
Shell.cleanDirs [ "output" ]
let result2 =
DotNet.exec
id
"fsdocs"
("build --properties Configuration=Release --eval --noapidocs --clean --parameters fsdocs-package-version "
+ release.NugetVersion)
if not result2.OK then
printfn "Errors while generating docs: %A" result2.Messages
failwith "Failed to generate docs"
printfn "Moving previous API pages to output"
Directory.Move("temp/reference", "output/reference")
printfn "Deleting temp folder"
Directory.Delete("temp"))
// --------------------------------------------------------------------------------------
// Help.
// --------------------------------------------------------------------------------------
Target.create "Help" (fun _ ->
printfn ""
printfn " Please specify the target by calling 'build -t <Target>'"
printfn ""
printfn " Targets for building:"
printfn " * Build"
printfn " * RunTests"
printfn " * GenerateDocs"
printfn " * Pack (creates package only, doesn't publish)"
printfn " * All (calls previous 4)"
printfn "")
let sourceFiles =
!! "src/**/*.fs" ++ "src/**/*.fsi" ++ "build.fsx"
-- "src/**/obj/**/*.fs"
-- "src/AssemblyInfo*.fs"
Target.create "Format" (fun _ ->
let result =
sourceFiles
|> Seq.map (sprintf "\"%s\"")
|> String.concat " "
|> DotNet.exec id "fantomas"
if not result.OK then
printfn "Errors while formatting all files: %A" result.Messages)
Target.create "CheckFormat" (fun _ ->
let result =
sourceFiles
|> Seq.map (sprintf "\"%s\"")
|> String.concat " "
|> sprintf "%s --check"
|> DotNet.exec id "fantomas"
if result.ExitCode = 0 then
Trace.log "No files need formatting"
elif result.ExitCode = 99 then
failwith "Some files need formatting, run `dotnet fake build -t Format` to format them"
else
Trace.logf "Errors while formatting: %A" result.Errors
failwith "Unknown errors while formatting")
Target.create "All" ignore
"Clean" ==> "AssemblyInfo" ==> "CheckFormat" ==> "Build"
"Build" ==> "CleanDocs" ==> "GenerateDocs" ==> "All"
"Build" ==> "Pack" ==> "All"
"Build" ==> "All"
"Build" ==> "RunTests" ==> "All"
Target.runOrDefaultWithArguments "Help"