-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
326 lines (272 loc) · 13 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#I "packages/FAKE/tools/"
#r "FakeLib.dll"
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.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"]
let summary = "Library of F# type providers and data access tools"
let description = """
The F# Data library (FSharp.Data.dll) implements everything you need to access data
in your F# applications and scripts. It implements F# type providers for working with
structured file formats (CSV, HTML, JSON and XML) and for accessing the WorldBank data.
It also includes helpers for parsing CSV, HTML and JSON files and for sending HTTP requests."""
let tags = "F# fsharp data typeprovider WorldBank CSV HTML CSS JSON XML HTTP linqpad-samples"
let gitOwner = "fsharp"
let gitHome = "https://github.com/" + gitOwner
let gitName = "FSharp.Data"
let desiredSdkVersion = (DotNet.getSDKVersionFromGlobalJson ())
let mutable sdkPath = None
let getSdkPath() = (defaultArg sdkPath "dotnet")
let installed =
try
DotNet.getVersion id <> null
with _ -> false
printfn "Desired .NET SDK version = %s" desiredSdkVersion
printfn "DotNetCli.isInstalled() = %b" installed
let useMsBuildToolchain = Environment.environVar "USE_MSBUILD" <> null
let installDesiredVersion () =
DotNet.install (fun v -> { v with Version = DotNet.Version desiredSdkVersion }) (DotNet.Options.Create ())
|> fun o -> o.DotNetCliPath
if installed then
let installedSdkVersion = DotNet.getVersion id
printfn "The installed default .NET SDK version reported by FAKE's 'DotNetCli.getVersion()' is %s" installedSdkVersion
if installedSdkVersion <> desiredSdkVersion then
match Environment.environVar "CI" with
| null ->
if installedSdkVersion > desiredSdkVersion then
printfn "*** You have .NET SDK version '%s' installed, assuming it is compatible with version '%s'" installedSdkVersion desiredSdkVersion
else
printfn "*** You have .NET SDK version '%s' installed, we expect at least version '%s'" installedSdkVersion desiredSdkVersion
| _ ->
printfn "*** The .NET SDK version '%s' will be installed (despite the fact that version '%s' is already installed) because we want precisely that version in CI" desiredSdkVersion installedSdkVersion
sdkPath <- Some (installDesiredVersion ())
else
printfn "*** The .NET SDK version '%s' will be installed (no other version was found by FAKE helpers)" desiredSdkVersion
sdkPath <- Some (installDesiredVersion ())
// Read release notes & version info from RELEASE_NOTES.md
let release =
let r = ReleaseNotes.load "RELEASE_NOTES.md"
{ r with NugetVersion = r.NugetVersion + ".1" }
let bindir = "./bin"
let isAppVeyorBuild = Environment.environVar "APPVEYOR" <> null
let nugetVersion =
if isAppVeyorBuild then sprintf "%s-a%s" release.NugetVersion (DateTime.UtcNow.ToString "yyMMddHHmm")
else release.NugetVersion
Target.create "AppVeyorBuildVersion" (fun _ ->
Shell.Exec("appveyor", sprintf "UpdateBuild -Version \"%s\"" nugetVersion) |> ignore
)
// --------------------------------------------------------------------------------------
// 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 _ ->
// have to clean netcore output directories because they corrupt the full-framework outputs
seq {
yield bindir
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
let testNames =
[ "FSharp.Data.DesignTime.Tests"
"FSharp.Data.Tests.CSharp"
"FSharp.Data.Tests" ]
let testProjs =
[ "tests/FSharp.Data.DesignTime.Tests/FSharp.Data.DesignTime.Tests.fsproj"
"tests/FSharp.Data.Tests.CSharp/FSharp.Data.Tests.CSharp.csproj"
"tests/FSharp.Data.Tests/FSharp.Data.Tests.fsproj" ]
let buildProjs =
[ "src/FSharp.Data.DesignTime/FSharp.Data.DesignTime.fsproj"
"src/FSharp.Data/FSharp.Data.fsproj" ]
let setSdkPathAndVerbose (c: DotNet.Options) =
{ c with
DotNetCliPath = getSdkPath ()
CustomParams = Some "/v:n" }
let logResults label lines =
lines
|> String.concat "\n\t"
|> Trace.tracefn "%s:\n\t%s" label
Target.create "Build" <| fun _ ->
if useMsBuildToolchain then
buildProjs |> Seq.iter (fun proj ->
DotNet.restore ( fun o -> { o with Common = setSdkPathAndVerbose o.Common }) proj)
buildProjs |> Seq.iter (fun proj ->
let projName = System.IO.Path.GetFileNameWithoutExtension proj
MSBuild.runRelease id null "Build" [projName]
|> logResults (sprintf "%s-Output:" projName))
else
// Both flavours of FSharp.Data.DesignTime.dll (net45 and netstandard2.0) must be built _before_ building FSharp.Data
buildProjs |> Seq.iter (fun proj ->
DotNet.build (fun opts -> { opts with Common = { opts.Common with DotNetCliPath = getSdkPath ()
CustomParams = Some "/v:n" }
Configuration = DotNet.BuildConfiguration.Release }) proj
)
Target.create "BuildTests" <| fun _ ->
for testProj in testProjs do
if useMsBuildToolchain then
DotNet.restore ( fun o -> { o with Common = setSdkPathAndVerbose o.Common }) testProj
MSBuild.runRelease id null "Build" [testProj]
|> logResults "BuildTests.DesignTime-Output"
else
DotNet.build (fun o -> { o with Common = setSdkPathAndVerbose o.Common
Configuration = DotNet.BuildConfiguration.Release }) testProj
Target.create "RunTests" <| fun _ ->
if useMsBuildToolchain then
for testName in testNames do
!! (sprintf "tests/*/bin/Release/net461/%s.dll" testName)
|> NUnit3.run (fun p ->
{ p with
TimeOut = TimeSpan.FromMinutes 20.
TraceLevel = NUnit3.NUnit3TraceLevel.Info })
else
for testProj in testProjs do
DotNet.test (fun p -> { p with Configuration = DotNet.BuildConfiguration.Release
Common = setSdkPathAndVerbose p.Common }) testProj
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target.create "NuGet" <| fun _ ->
// Format the release notes
let releaseNotes = release.Notes |> String.concat "\n"
NuGet.NuGetPack (fun p ->
{ p with
Authors = authors
Project = project
Summary = summary
Description = description
Version = nugetVersion
ReleaseNotes = releaseNotes
Tags = tags
OutputPath = "bin"
AccessKey = Environment.environVarOrDefault "nugetkey" ""
Publish = Environment.hasEnvironVar "nugetkey"
Dependencies = [] })
"nuget/FSharp.Data.nuspec"
// --------------------------------------------------------------------------------------
// Generate the documentation
Target.create "GenerateDocs" <| fun _ ->
Fake.FSIHelper.executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore
// --------------------------------------------------------------------------------------
// Release Scripts
let publishFiles what branch fromFolder toFolder =
let tempFolder = "temp/" + branch
Shell.cleanDir tempFolder
Repository.cloneSingleBranch "" (gitHome + "/" + gitName + ".git") branch tempFolder
Repository.fullclean tempFolder
Shell.copyRecursive fromFolder (tempFolder + "/" + toFolder) true |> Trace.tracefn "%A"
Staging.stageAll tempFolder
Commit.exec tempFolder <| sprintf "Update %s for version %s" what release.NugetVersion
Branches.push tempFolder
#load "paket-files/fsharp/FAKE/modules/Octokit/Octokit.fsx"
open Octokit
let createRelease() =
// Set release date in release notes
let releaseNotes = File.ReadAllText "RELEASE_NOTES.md"
let releaseNotes = releaseNotes.Replace("#### " + release.NugetVersion + " - Unreleased", "#### " + release.NugetVersion + " - " + DateTime.Now.ToString("MMMM d yyyy"))
File.WriteAllText("RELEASE_NOTES.md", releaseNotes)
// Commit assembly info and RELEASE_NOTES.md
Staging.stageAll ""
Commit.exec "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.pushBranch "" "upstream" "master"
// Create tag
Branches.tag "" release.NugetVersion
Branches.pushTag "" "upstream" release.NugetVersion
// Create github release
let token =
match Environment.environVarOrDefault "github_token" "" with
| s when not (System.String.IsNullOrWhiteSpace s) -> s
| _ -> failwith "please set the github_token environment variable to a github personal access token with repro access."
let draft =
createClientWithToken token
|> createDraft gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
draft
|> releaseDraft
|> Async.RunSynchronously
Target.create "ReleaseDocs" <| fun _ ->
publishFiles "generated documentation" "gh-pages" "docs/output" ""
Target.create "ReleaseBinaries" <| fun _ ->
createRelease()
publishFiles "binaries" "release" "bin" "bin"
Target.create "TestSourcelink" <| fun _ ->
let testSourcelink framework proj =
let basePath = Path.GetFileNameWithoutExtension proj
let pdb = sprintf "bin/Release/%s/%s.pdb" framework basePath
DotNet.exec (setSdkPathAndVerbose >> DotNet.Options.withWorkingDirectory(Path.GetDirectoryName proj)) "sourcelink" (sprintf "test %s" pdb)
|> ignore
["net45"; "netstandard2.0"]
|> Seq.collect (fun fw -> buildProjs |> Seq.map (testSourcelink fw))
|> Seq.iter id
Target.create "Release" ignore
open Fake.Core.TargetOperators
"CleanDocs" ==> "GenerateDocs" ==> "ReleaseDocs"
"ReleaseDocs" ==> "Release"
"ReleaseBinaries" ==> "Release"
"NuGet" ==> "Release"
"TestSourcelink" ==> "Release"
// --------------------------------------------------------------------------------------
// Help
Target.create "Help" <| fun _ ->
printfn ""
printfn " Please specify the target by calling 'build <Target>'"
printfn ""
printfn " Targets for building:"
printfn " * Build"
printfn " * BuildTests"
printfn " * RunTests"
printfn " * All (calls previous 3)"
printfn ""
printfn " Targets for releasing (requires write access to the 'https://github.com/fsharp/FSharp.Data.git' repository):"
printfn " * GenerateDocs"
printfn " * ReleaseDocs (calls previous)"
printfn " * ReleaseBinaries"
printfn " * NuGet (creates package only, doesn't publish)"
printfn " * TestSourceLink (validates the SourceLink embedded data)"
printfn " * Release (calls previous 5)"
printfn ""
printfn " Other targets:"
printfn " * CleanInternetCaches"
printfn ""
printfn " Set USE_MSBUILD=1 in environment to use MSBuild toolchain and .NET Framework/Mono compiler."
Target.create "All" ignore
"Clean" ==> "AssemblyInfo" ==> "Build"
"Build" ==> "All"
"Build" ==> "BuildTests" ==> "All"
"BuildTests" ==> "RunTests" ==> "All"
Target.runOrDefaultWithArguments "Help"