forked from FsStorm/FsShelter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.fsx
300 lines (241 loc) · 9.63 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
open Fake.FileSystem
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r @"packages/build/FAKE/tools/FakeLib.dll"
#r "System.Web.dll"
open Fake
open Fake.Git
open Fake.AssemblyInfoFile
open Fake.ReleaseNotesHelper
open System
open System.IO
#if MONO
#else
#load "packages/build/SourceLink.Fake/tools/Fake.fsx"
open SourceLink
#endif
let projects =
!! "src/**/*.??proj"
++ "ext/**/*.??proj"
++ "samples/**/*.??proj"
// Git configuration (used for publishing documentation in gh-pages branch)
// The profile where the project is posted
let gitOwner = "FsStorm"
let gitHome = "https://github.com/" + gitOwner
// The name of the project on GitHub
let gitName = "FsShelter"
// The url for the raw files hosted
let gitRaw = environVarOrDefault "gitRaw" "https://raw.github.com/"+gitOwner+"/"+gitName
// Read additional information from the release notes document
let release = LoadReleaseNotes "RELEASE_NOTES.md"
let runDotnet workingDir args =
let result =
ExecProcess (fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- workingDir
info.Arguments <- args) TimeSpan.MaxValue
if result <> 0 then failwithf "dotnet %s failed" args
Target "Clean" (fun _ ->
let dirs = { BaseDirectory = Path.GetFullPath "."
Includes = projects
|> Seq.map Path.GetDirectoryName
|> Seq.collect (fun n -> [Path.Combine(n,"bin"); Path.Combine(n,"obj")] )
|> List.ofSeq
Excludes = [] }
dirs
++ "docs/output"
|> Seq.iter (CleanDir)
)
Target "Meta" (fun _ ->
[ "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"
"<PropertyGroup>"
"<PackageProjectUrl>https://github.com/FsStorm/FsShelter</PackageProjectUrl>"
"<PackageLicenseUrl>https://raw.githubusercontent.com/FsStorm/FsShelter/master/LICENSE.md</PackageLicenseUrl>"
"<PackageIconUrl>https://raw.githubusercontent.com/FsStorm/FsShelter/master/docs/files/img/logo.png</PackageIconUrl>"
"<RepositoryUrl>https://github.com/FsStorm/FsShelter.git</RepositoryUrl>"
"<PackageTags>storm;cep;event-driven;fsharp;distributed</PackageTags>"
"<PackageDescription>F# DSL and runtime for Apache Storm topologies</PackageDescription>"
"<Authors>FsStorm</Authors>"
sprintf "<PackageReleaseNotes>%s</PackageReleaseNotes>" (List.head release.Notes |> System.Web.HttpUtility.HtmlEncode)
sprintf "<Version>%s</Version>" (string release.SemVer)
"</PropertyGroup>"
"</Project>"]
|> WriteToFile false "Directory.Build.props"
)
Target "Restore" (fun _ ->
projects
|> Seq.iter ((sprintf "restore %s") >> runDotnet ".")
)
Target "Build" (fun _ ->
projects
|> Seq.iter ((sprintf "build -c Release %s") >> runDotnet ".")
)
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner
Target "Tests" (fun _ ->
runDotnet "src/FsShelter.Tests" "test --no-restore --filter \"TestCategory!=interactive\""
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target "Package" (fun _ ->
runDotnet
"src/FsShelter"
"pack -c Release"
)
Target "PublishNuget" (fun _ ->
runDotnet "src/FsShelter" (sprintf "nuget push bin/Release/FsShelter.%s.nupkg -s nuget.org -k %s" release.NugetVersion (environVar "nugetkey"))
)
// --------------------------------------------------------------------------------------
// Generate the documentation
Target "GenerateReferenceDocs" (fun _ ->
if not <| executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"; "--define:REFERENCE"] [] then
failwith "generating reference documentation failed"
)
let generateHelp fail debug =
let args =
if debug then ["--define:HELP"]
else ["--define:RELEASE"; "--define:HELP"]
if executeFSIWithArgs "docs/tools" "generate.fsx" args [] then
traceImportant "Help generated"
else
if fail then
failwith "generating help documentation failed"
else
traceImportant "generating help documentation failed"
Target "GenerateHelp" (fun _ ->
DeleteFile "docs/content/release-notes.md"
CopyFile "docs/content/" "RELEASE_NOTES.md"
DeleteFile "docs/content/license.md"
CopyFile "docs/content/" "LICENSE.md"
generateHelp true false
)
Target "WatchDocs" (fun _ ->
use watcher = new FileSystemWatcher(DirectoryInfo("docs/content").FullName,"*.*")
watcher.EnableRaisingEvents <- true
watcher.Changed.Add(fun e -> generateHelp true false)
watcher.Created.Add(fun e -> generateHelp true false)
watcher.Renamed.Add(fun e -> generateHelp true false)
watcher.Deleted.Add(fun e -> generateHelp true false)
traceImportant "Waiting for help edits. Press any key to stop."
System.Console.ReadKey() |> ignore
watcher.EnableRaisingEvents <- false
watcher.Dispose()
)
Target "GenerateDocs" DoNothing
let createIndexFsx lang =
let content = """(*** hide ***)
#I build_out
(**
FsShelter ({0})
=========================
*)
"""
let targetDir = "docs/content" @@ lang
let targetFile = targetDir @@ "index.fsx"
ensureDirectory targetDir
System.IO.File.WriteAllText(targetFile, System.String.Format(content, lang))
// --------------------------------------------------------------------------------------
// Release Scripts
Target "ReleaseDocs" (fun _ ->
let tempDocsDir = "temp/gh-pages"
CleanDir tempDocsDir
Repository.cloneSingleBranch "" (sprintf "git@github.com:%s/%s.git" gitOwner gitName) "gh-pages" tempDocsDir
CopyRecursive "docs/output" tempDocsDir true |> tracefn "%A"
StageAll tempDocsDir
Git.Commit.Commit tempDocsDir (sprintf "Update generated documentation for version %s" release.NugetVersion)
Branches.push tempDocsDir
)
#load "paket-files/build/fsharp/FAKE/modules/Octokit/Octokit.fsx"
open Octokit
Target "Release" (fun _ ->
StageAll ""
Git.Commit.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.push ""
Branches.tag "" release.NugetVersion
Branches.pushTag "" "origin" release.NugetVersion
// release on github
createClient (getBuildParamOrDefault "github-user" "") (getBuildParamOrDefault "github-pw" "")
|> createDraft gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
// TODO: |> uploadFile "PATH_TO_FILE"
|> releaseDraft
|> Async.RunSynchronously
)
// --------------------------------------------------------------------------------------
// code-gen tasks
Target "ProtoShell" (fun _ ->
let generated = "ext" @@ "ProtoShell" @@ "generated"
let cli =
"packages" @@ "build" @@ "Google.Protobuf.Tools" @@ "tools"
@@ if isWindows then "windows_x64" @@ "protoc.exe"
else if isLinux then "linux_x64" @@ "protoc"
else "macosx_x64" @@ "protoc"
CleanDir generated
Shell.Exec(
cli,
"--csharp_out=" + generated
+ " --proto_path=" + "packages" @@ "build" @@ "Google.Protobuf.Tools" @@ "tools"
+ " --proto_path=" + "paket-files" @@ "FsStorm" @@ "protoshell" @@ "src" @@ "main" @@ "proto"
+ " paket-files" @@ "FsStorm" @@ "protoshell" @@ "src" @@ "main" @@ "proto" @@ "multilang.proto")
|> ignore
)
Target "StormThriftNamespace" (fun _ ->
"paket-files" @@ "et1975" @@ "storm" @@ "storm-core" @@ "src" @@ "storm.thrift"
|> RegexReplaceInFileWithEncoding "namespace java org.apache.storm.generated" "namespace csharp StormThrift" Text.Encoding.ASCII
)
Target "StormThrift" (fun _ ->
let generated = "ext" @@ "StormThrift" @@ "StormThrift"
CleanDir generated
Shell.Exec(
"packages" @@ "build" @@ "Thrift" @@ "tools" @@ "thrift-0.9.1.exe",
"-out " + generated @@ ".."
+ " --gen csharp"
+ " paket-files" @@ "et1975" @@ "storm" @@ "storm-core" @@ "src" @@ "storm.thrift")
|> ignore
)
Target "GenerateSources" DoNothing
"ProtoShell"
==> "GenerateSources"
"StormThriftNamespace"
==> "StormThrift"
==> "GenerateSources"
// --------------------------------------------------------------------------------------
// graph gen tasks
// GraphViz has to be installed and "dot" be in the path
let exportGraph (app:string) (arg:string) fileName =
Shell.Exec(
"dotnet",
("samples" @@ app @@ "bin" @@ "Release" @@ "netcoreapp2.1" @@ (sprintf "%s.dll" app)) +
(sprintf " %s | dot -Tsvg -o samples/%s/obj/%s.svg" arg app fileName))
|> ignore
Target "WordCountSvg" (fun _ ->
exportGraph "WordCount" "graph" "WordCount"
)
Target "WordCountColourSvg" (fun _ ->
exportGraph "WordCount" "colour-graph" "WordCount_colourized"
)
Target "WordCountCustomColourSvg" (fun _ ->
exportGraph "WordCount" "custom-colour-graph" "WordCount_custom_colourized"
)
Target "GuaranteedSvg" (fun _ ->
exportGraph "Guaranteed" "graph" "Guaranteed"
)
Target "ExportGraphs" DoNothing
"ExportGraphs"
<== ["Build"; "WordCountSvg"; "WordCountColourSvg"; "WordCountCustomColourSvg"; "GuaranteedSvg"]
Target "All" DoNothing
"All"
<== ["Clean"; "Restore"; "Meta"; "Build"; "Tests"; "Package"; "GenerateReferenceDocs"; "GenerateDocs"]
"Build"
==> "Tests"
"Build"
==> "GenerateHelp"
==> "GenerateReferenceDocs"
==> "GenerateDocs"
"Build"
==> "GenerateHelp"
"GenerateHelp"
==> "WatchDocs"
"Release"
<== ["All"; "PublishNuget"; "ReleaseDocs"]
RunTargetOrDefault "All"