-
Notifications
You must be signed in to change notification settings - Fork 287
/
build.fsx
245 lines (198 loc) · 7.67 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "paket: groupref fake //"
#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__
// --------------------------------------------------------------------------------------
// Information about the project to be used at NuGet and in AssemblyInfo files
// --------------------------------------------------------------------------------------
let project = "FSharp.Data"
let authors = "Tomas Petricek;Gustavo Guerra;Colin Bull;fsprojects contributors"
let summary = "Library of F# type providers and data access tools"
let description =
"""
The FSharp.Data packages contain type providers and utilities to access
common data formats (CSV, HTML, JSON and XML in your F# applications and scripts.
* FSharp.Data -- includes everything
* FSharp.Data.Http -- http types/helpers
* FSharp.Data.Csv.Core -- csv types/helpers
* FSharp.Data.Json.Core -- json types/helpers
* FSharp.Data.Html.Core -- html types/helpers
* FSharp.Data.Xml.Core -- xml types/helpers"""
let tags =
"F# fsharp data typeprovider WorldBank CSV HTML CSS JSON XML HTTP linqpad-samples"
let gitOwner = "fsprojects"
let gitHome = "https://github.com/" + gitOwner
let gitName = "FSharp.Data"
let packageProjectUrl = "https://fsprojects.github.io/FSharp.Data/"
let repositoryType = "git"
let repositoryUrl = "https://github.com/fsprojects/FSharp.Data"
let license = "Apache-2.0"
// Read release notes & version info from RELEASE_NOTES.md
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let isCI = Environment.GetEnvironmentVariable("CI") <> null
// --------------------------------------------------------------------------------------
// Generate assembly info files with the right version & up-to-date 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" "FSharp.Data"
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"
}
|> Shell.cleanDirs)
Target.create "CleanDocs" (fun _ -> Shell.cleanDirs [ "docs/output" ])
let internetCacheFolder =
Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)
Target.create "CleanInternetCaches" (fun _ ->
Shell.cleanDirs
[ internetCacheFolder @@ "DesignTimeURIs"
internetCacheFolder @@ "WorldBankSchema"
internetCacheFolder @@ "WorldBankRuntime" ])
// --------------------------------------------------------------------------------------
// Build library & test projects
Target.create "Build" (fun _ ->
"FSharp.Data.sln"
|> DotNet.build (fun o ->
{ o with
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams = { o.MSBuildParams with DisableInternalBinLog = true } }))
Target.create "RunTests" (fun _ ->
let setParams (o: DotNet.TestOptions) =
{ o with
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams = { o.MSBuildParams with DisableInternalBinLog = true }
Logger =
if isCI then
Some "GitHubActions"
else
None }
"FSharp.Data.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
DisableInternalBinLog = true } })
"FSharp.Data.sln")
// --------------------------------------------------------------------------------------
// Generate the documentation
Target.create "GenerateDocs" (fun _ ->
Shell.cleanDir ".fsdocs"
let result =
DotNet.exec
id
"fsdocs"
("build --properties Configuration=Release --strict --eval --clean --parameters fsdocs-package-version "
+ release.NugetVersion)
if not result.OK then
printfn "Errors while generating docs: %A" result.Messages
failwith "Failed to generate docs")
// --------------------------------------------------------------------------------------
// 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 5)"
printfn ""
printfn " Other targets:"
printfn " * CleanInternetCaches"
printfn " * Format"
printfn " * CheckFormat"
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"