forked from fsprojects/FSharp.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
275 lines (230 loc) · 11.3 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
// --------------------------------------------------------------------------------------
// 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 getPathForSdkVersion (sdkVersion) =
DotNet.install (fun v -> { v with Version = DotNet.Version sdkVersion }) (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 (getPathForSdkVersion desiredSdkVersion)
else
sdkPath <- Some (getPathForSdkVersion installedSdkVersion)
else
printfn "*** The .NET SDK version '%s' will be installed (no other version was found by FAKE helpers)" desiredSdkVersion
sdkPath <- Some (getPathForSdkVersion desiredSdkVersion)
// Read release notes & version info from RELEASE_NOTES.md
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let bindir = "./bin"
let isAppVeyorBuild = Environment.environVar "APPVEYOR" <> null
let isAppVeyorBuildTag = Environment.environVar "APPVEYOR_REPO_TAG" <> null
let appVeyorTagName = Environment.environVar "APPVEYOR_REPO_TAG_NAME"
let nugetVersion =
if isAppVeyorBuild then
if not isAppVeyorBuildTag then
sprintf "%s-a%s" release.NugetVersion (DateTime.UtcNow.ToString "yyMMddHHmm")
else
if appVeyorTagName <> release.NugetVersion then
printfn "mismatch between tag '%s' and RELEASE_NOTES.md version '%s" appVeyorTagName release.NugetVersion
release.NugetVersion
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"
"FSharp.Data.Reference.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"
"tests/FSharp.Data.Reference.Tests/FSharp.Data.Reference.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 _ ->
// 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 /p:SourceLinkCreate=true" }
Configuration = DotNet.BuildConfiguration.Release }) proj
)
Target.create "BuildTests" <| fun _ ->
for testProj in testProjs do
DotNet.build (fun o -> { o with Common = setSdkPathAndVerbose o.Common
Configuration = DotNet.BuildConfiguration.Release }) testProj
Target.create "RunTests" <| fun _ ->
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
Target.create "ReleaseDocs" <| fun _ ->
publishFiles "generated documentation" "gh-pages" "docs/output" ""
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
// --------------------------------------------------------------------------------------
// 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 and publishes to gh-pages)"
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
"Build" ==> "CleanDocs" ==> "GenerateDocs" ==> "ReleaseDocs" ==> "Release"
"NuGet" ==> "Release"
"Build" ==> "TestSourcelink" ==> "Release"
"Clean" ==> "AssemblyInfo" ==> "Build" ==> "NuGet" ==> "All"
"Build" ==> "BuildTests" ==> "All"
"BuildTests" ==> "RunTests" ==> "All"
Target.runOrDefaultWithArguments "Help"