forked from fsprojects/FSharp.Control.Reactive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
254 lines (212 loc) · 8.46 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#load ".fake/build.fsx/intellisense.fsx"
#if !FAKE
#r "netstandard"
#endif
open Fake.Tools
open Fake.Core
open Fake.DotNet
open Fake.BuildServer
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open System.IO
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open System.Threading
// --------------------------------------------------------------------------------------
// Provide project-specific details below
// --------------------------------------------------------------------------------------
let projects = [ "src/FSharp.Control.Reactive/FSharp.Control.Reactive.fsproj"
"src/FSharp.Control.Reactive.Testing/FSharp.Control.Reactive.Testing.fsproj" ]
// Git configuration (used for publishing documentation in gh-pages branch)
// The profile where the project is posted
let gitHome = "git@github.com:fsprojects"
// The name of the project on GitHub
let gitName = "FSharp.Control.Reactive"
let buildDir = Path.GetFullPath "bin"
let docsDir = Path.GetFullPath "docs"
// --------------------------------------------------------------------------------------
// The rest of the file includes standard build steps
// --------------------------------------------------------------------------------------
// Read additional information from the release notes document
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let isAppVeyorBuild = Environment.environVar "APPVEYOR" |> isNull |> not
let isTaggedBuild = Environment.environVarAsBoolOrDefault "APPVEYOR_REPO_TAG" false
let versionSuffix =
let buildVersion = BuildServer.buildVersion
if isTaggedBuild then ""
elif buildVersion = "LocalBuild" then "-LocalBuild"
else "-beta" + buildVersion
let nugetVersion = release.NugetVersion + versionSuffix
BuildServer.install [
AppVeyor.Installer
]
// Generate assembly info files with the right version & up-to-date information
Target.create "BuildVersion" (fun _ ->
Shell.Exec("appveyor", sprintf "UpdateBuild -Version \"%s\"" nugetVersion) |> ignore
)
// --------------------------------------------------------------------------------------
// Clean build results & restore NuGet packages
Target.create "Clean" (fun _ ->
!! "src/**/bin"
++ "src/**/obj"
++ "bin"
++ "temp"
|> Shell.cleanDirs
)
Target.create "CleanDocs" (fun _ ->
Shell.cleanDir "docs/output"
)
// --------------------------------------------------------------------------------------
// Build library & test project
Target.create "Build" (fun _ ->
Environment.setEnvironVar "GenerateDocumentationFile" "true"
projects
|> List.iter (DotNet.build id)
)
Target.create "CopyLicense" (fun _ ->
[ "LICENSE.txt" ] |> Shell.copyTo "bin"
)
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner
Target.create "RunTests" (fun _ ->
DotNet.test (fun p -> { p with Configuration = DotNet.BuildConfiguration.Release}) "tests"
Trace.publish (ImportData.Nunit NunitDataVersion.Nunit3) buildDir
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target.create "Pack" (fun _ ->
Environment.setEnvironVar "PackageVersion" nugetVersion
Environment.setEnvironVar "Version" nugetVersion
Environment.setEnvironVar "PackageReleaseNotes" (release.Notes |> String.toLines)
projects
|> List.iter (DotNet.pack (fun p ->
{ p with
OutputPath = Some buildDir
NoBuild = true
}) )
)
Target.create "Push" (fun _ ->
Paket.push (fun p ->
{ p with
WorkingDir = buildDir })
)
// --------------------------------------------------------------------------------------
// Generate the documentation
Target.create "GenerateDocs" (fun _ ->
let githubLink = "https://github.com/fsprojects/FSharp.Control.Reactive"
let root = "/FSharp.Control.Reactive"
// Paths with template/source/output locations
let content = docsDir @@ "content"
let output = docsDir @@ "output"
let outputContent = output @@ "content"
let outputReference = output @@ "reference"
let files = docsDir @@ "files"
let templates = docsDir @@ "tools/templates"
let formatting = Path.GetFullPath "packages/build/FSharp.Formatting.CommandTool"
let docTemplate = formatting @@ "templates/docpage.cshtml"
// Where to look for *.csproj templates (in this order)
let layoutRoots = [ templates; formatting @@ "templates"
formatting @@ "templates/reference" ]
let info =
[ "root", root
"project-name", "FSharp.Control.Reactive"
"project-author", "Ryan Riley, Steffen Forkmann, and Jared Heseter"
"project-summary", "A F#-friendly wrapper for the Reactive Extensions."
"project-github", "http://github.com/fsprojects/FSharp.Reactive"
"project-nuget", "https://www.nuget.org/packages/FSharp.Control.Reactive" ]
Shell.copyDir output files FileFilter.allFiles
Directory.ensure outputContent
Shell.copyDir outputContent (formatting @@ "styles") FileFilter.allFiles
FSFormatting.createDocs (fun s ->
{ s with
Source = content
OutputDirectory = output
Template = docTemplate
ProjectParameters = info
LayoutRoots = layoutRoots })
Directory.ensure outputReference
let dlls =
!! "src/FSharp.Control.*/bin/Release/**/FSharp.Control.Reactive*.dll"
|> Seq.distinctBy Path.GetFileName
|> List.ofSeq
let libDirs =
dlls
|> Seq.map Path.GetDirectoryName
|> Seq.distinct
|> List.ofSeq
dlls
|> FSFormatting.createDocsForDlls (fun s ->
{ s with
OutputDirectory = outputReference
LayoutRoots = layoutRoots
LibDirs = libDirs
ProjectParameters = info
SourceRepository = githubLink @@ "tree/master" })
)
Target.create "HostDocs" (fun _ ->
let configureApp (app:IApplicationBuilder) =
app.UseFileServer(FileServerOptions(EnableDefaultFiles = true))
|> ignore
let port = 8081
let directory = docsDir @@ "output"
let host =
WebHostBuilder()
.UseWebRoot(directory)
.UseContentRoot(directory)
.PreferHostingUrls(false)
.UseKestrel(fun o -> o.ListenLocalhost(port))
.Configure(System.Action<IApplicationBuilder> configureApp)
.Build()
use cts = new CancellationTokenSource()
host.RunAsync(cts.Token) |> ignore
let psi = System.Diagnostics.ProcessStartInfo(sprintf "http://localhost:%d/index.html" port)
psi.UseShellExecute <- true
System.Diagnostics.Process.Start (psi) |> ignore
Trace.traceImportant "Press any key to stop."
System.Console.ReadKey() |> ignore
cts.Cancel()
)
// --------------------------------------------------------------------------------------
// Release Scripts
Target.create "ReleaseDocs" (fun _ ->
let tempDocsDir = "temp/gh-pages"
Shell.cleanDir tempDocsDir
Git.Repository.cloneSingleBranch "" (gitHome + "/" + gitName + ".git") "gh-pages" tempDocsDir
Shell.copyRecursive "docs/output" tempDocsDir true |> Trace.tracefn "%A"
Git.Staging.stageAll tempDocsDir
Git.Commit.exec tempDocsDir (sprintf "Update generated documentation for version %s" release.NugetVersion)
Git.Branches.push tempDocsDir
)
Target.create "Release" (fun _ ->
Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Bump version to %s" release.NugetVersion)
Git.Branches.push ""
Git.Branches.tag "" release.NugetVersion
Git.Branches.pushTag "" "origin" release.NugetVersion
)
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target.create "All" ignore
open Fake.Core.TargetOperators
"Clean"
=?> ("BuildVersion", isAppVeyorBuild)
==> "CopyLicense"
==> "Build"
==> "RunTests"
==> "All"
=?> ("GenerateDocs", BuildServer.isLocalBuild && not Environment.isMono)
=?> ("ReleaseDocs", BuildServer.isLocalBuild && not Environment.isMono)
"All"
==> "Pack"
==> "Push"
"CleanDocs"
==> "GenerateDocs"
"ReleaseDocs"
==> "Release"
"Push"
==> "Release"
Target.runOrDefault "All"