-
Notifications
You must be signed in to change notification settings - Fork 153
/
build.fsx
285 lines (237 loc) · 10.6 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#I @"packages/FAKE/tools"
#r @"packages/FAKE/tools/FakeLib.dll"
open System
open System.IO
open Fake
open Fake.AssemblyInfoFile
open Fake.Git
open Fake.ReleaseNotesHelper
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
// Information about the project to be used at NuGet and in AssemblyInfo files
let project = "FSharp.Formatting"
let projectTool = "FSharp.Formatting.CommandTool"
let authors = ["Tomas Petricek"; "Oleg Pestov"; "Anh-Dung Phan"; "Xiang Zhang"; "Matthias Dittrich"]
let authorsTool = ["Friedrich Boeckh"; "Tomas Petricek"]
let summary = "A package of libraries for building great F# documentation, samples and blogs"
let summaryTool = "A command line tool for building great F# documentation, samples and blogs"
let description = """
The package is a collection of libraries that can be used for literate programming
with F# (great for building documentation) and for generating library documentation
from inline code comments. The key componments are Markdown parser, tools for formatting
F# code snippets, including tool tip type information and a tool for generating
documentation from library metadata."""
let descriptionTool = """
The package contains a command line version of F# Formatting libraries, which
can be used for literate programming with F# (great for building documentation)
and for generating library documentation from inline code comments. The key componments
are Markdown parser, tools for formatting F# code snippets, including tool tip
type information and a tool for generating documentation from library metadata."""
let license = "Apache 2.0 License"
let tags = "F# fsharp formatting markdown code fssnip literate programming"
// Read release notes document
let release = ReleaseNotesHelper.parseReleaseNotes (File.ReadLines "RELEASE_NOTES.md")
// --------------------------------------------------------------------------------------
// Generate assembly info files with the right version & up-to-date information
Target "AssemblyInfo" (fun _ ->
let info =
[ Attribute.Title project
Attribute.Product project
Attribute.Description summary
Attribute.Version release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion
Attribute.InformationalVersion release.NugetVersion
Attribute.Copyright license ]
CreateFSharpAssemblyInfo "src/Common/AssemblyInfo.fs" info
CreateCSharpAssemblyInfo "src/Common/AssemblyInfo.cs" info
)
// --------------------------------------------------------------------------------------
// Clean build results
Target "Clean" (fun _ ->
CleanDirs ["bin"; "temp" ]
CleanDirs ["docs/output"]
CleanDirs ["tests/FSharp.MetadataFormat.Tests/files/FsLib/bin"]
CleanDirs ["tests/FSharp.MetadataFormat.Tests/files/FsLib/obj"]
CleanDirs ["tests/FSharp.MetadataFormat.Tests/files/crefLib/bin"]
CleanDirs ["tests/FSharp.MetadataFormat.Tests/files/crefLib/obj"]
CleanDirs ["tests/FSharp.MetadataFormat.Tests/files/csharpSupport/bin"]
CleanDirs ["tests/FSharp.MetadataFormat.Tests/files/csharpSupport/obj"]
CleanDirs ["tests/FSharp.MetadataFormat.Tests/files/TestLib/bin"]
CleanDirs ["tests/FSharp.MetadataFormat.Tests/files/TestLib/obj"]
)
// --------------------------------------------------------------------------------------
// Update the assembly version numbers in the script file.
open System.IO
Target "UpdateFsxVersions" (fun _ ->
let packages = [ "FSharp.Compiler.Service"; "FSharpVSPowerTools.Core" ]
let replacements =
packages |> Seq.map (fun packageName ->
sprintf "/%s.(.*)/lib" packageName,
sprintf "/%s.%s/lib" packageName (GetPackageVersion "packages" packageName))
let path = "./packages/FSharp.Formatting/FSharp.Formatting.fsx"
let text = File.ReadAllText(path)
let text = (text, replacements) ||> Seq.fold (fun text (pattern, replacement) ->
Text.RegularExpressions.Regex.Replace(text, pattern, replacement) )
File.WriteAllText(path, text)
)
// --------------------------------------------------------------------------------------
// Build library
Target "Build" (fun _ ->
{ BaseDirectory = __SOURCE_DIRECTORY__
Includes = ["FSharp.Formatting.sln"]
Excludes = [] }
|> MSBuildRelease "" "Rebuild"
|> ignore
)
Target "MergeVSPowerTools" (fun _ ->
() (*
let binDir = __SOURCE_DIRECTORY__ @@ "bin"
CreateDir (binDir @@ "merged")
let toPack =
(binDir @@ "FSharp.CodeFormat.dll") + " " +
(binDir @@ "FSharpVSPowerTools.Core.dll")
let result =
ExecProcess (fun info ->
info.FileName <- currentDirectory @@ "packages/ILRepack/tools/ILRepack.exe"
info.Arguments <-
sprintf
"/internalize /verbose /lib:bin /ver:%s /out:%s %s"
release.AssemblyVersion (binDir @@ "merged" @@ "FSharp.CodeFormat.dll") toPack
) (TimeSpan.FromMinutes 5.)
if result <> 0 then failwithf "Error during ILRepack execution."
!! (binDir @@ "merged" @@ "*.*")
|> CopyFiles binDir
DeleteDir (binDir @@ "merged")
*)
)
// --------------------------------------------------------------------------------------
// Build tests and generate tasks to run the tests in sequence
Target "BuildTests" (fun _ ->
{ BaseDirectory = __SOURCE_DIRECTORY__
Includes = ["FSharp.Formatting.sln"]
Excludes = [] }
|> MSBuildRelease "" "Rebuild"
|> ignore
{ BaseDirectory = __SOURCE_DIRECTORY__
Includes = ["tests/*/files/FsLib/FsLib.sln"]
Excludes = [] }
|> MSBuildDebug "" "Rebuild"
|> ignore
{ BaseDirectory = __SOURCE_DIRECTORY__
Includes = ["tests/*/files/crefLib/crefLib.sln"]
Excludes = [] }
|> MSBuildDebug "" "Rebuild"
|> ignore
{ BaseDirectory = __SOURCE_DIRECTORY__
Includes = ["tests/*/files/csharpSupport/csharpSupport.sln"]
Excludes = [] }
|> MSBuildDebug "" "Rebuild"
|> ignore
{ BaseDirectory = __SOURCE_DIRECTORY__
Includes = ["tests/*/files/TestLib/TestLib.sln"]
Excludes = [] }
|> MSBuildDebug "" "Rebuild"
|> ignore
)
let testProjects =
[ "FSharp.CodeFormat.Tests"; "FSharp.Literate.Tests";
"FSharp.Markdown.Tests"; "FSharp.MetadataFormat.Tests" ]
Target "RunTests" <| ignore
// For each test project file, generate a new "RunTest_Xyz" which
// runs the test (to process them sequentially which is needed in Travis)
for name in testProjects do
let taskName = sprintf "RunTest_%s" name
Target taskName <| fun () ->
!! (sprintf "tests/*/bin/Release/%s.dll" name)
|> NUnit (fun p ->
{ p with
DisableShadowCopy = true
TimeOut = TimeSpan.FromMinutes 20.
Framework = "4.0"
OutputFile = "TestResults.xml" })
taskName ==> "RunTests" |> ignore
"BuildTests" ==> taskName |> ignore
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target "NuGet" (fun _ ->
NuGet (fun p ->
{ p with
Authors = authors
Project = project
Summary = summary
Description = description
Version = release.NugetVersion
ReleaseNotes = toLines release.Notes
Tags = tags
OutputPath = "bin"
AccessKey = getBuildParamOrDefault "nugetkey" ""
Publish = hasBuildParam "nugetkey"
Dependencies =
[ "FSharpVSPowerTools.Core", GetPackageVersion "packages" "FSharpVSPowerTools.Core" |> RequireExactly
"FSharp.Compiler.Service", GetPackageVersion "packages" "FSharp.Compiler.Service" |> sprintf "[%s,1.3]" ] })
"nuget/FSharp.Formatting.nuspec"
NuGet (fun p ->
{ p with
Authors = authorsTool
Project = projectTool
Summary = summaryTool
Description = descriptionTool
Version = release.NugetVersion
ReleaseNotes = toLines release.Notes
Tags = tags
OutputPath = "bin"
AccessKey = getBuildParamOrDefault "nugetkey" ""
Publish = hasBuildParam "nugetkey"
Dependencies = [] })
"nuget/FSharp.Formatting.CommandTool.nuspec"
)
// --------------------------------------------------------------------------------------
// Generate the documentation
Target "GenerateDocs" (fun _ ->
if not <| executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"; "--define:REFERENCE"; "--define:HELP"] [] then
failwith "generating reference documentation failed")
Target "WatchDocs" (fun _ ->
if not <| executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:WATCH"] [] then
failwith "generating reference documentation failed")
// --------------------------------------------------------------------------------------
// Release Scripts
let gitHome = "git@github.com:tpetricek"
Target "ReleaseDocs" (fun _ ->
Repository.clone "" (gitHome + "/FSharp.Formatting.git") "temp/gh-pages"
Branches.checkoutBranch "temp/gh-pages" "gh-pages"
CopyRecursive "docs/output" "temp/gh-pages" true |> printfn "%A"
CommandHelper.runSimpleGitCommand "temp/gh-pages" "add ." |> printfn "%s"
let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" release.NugetVersion
CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd |> printfn "%s"
Branches.push "temp/gh-pages"
)
Target "ReleaseBinaries" (fun _ ->
Repository.clone "" (gitHome + "/FSharp.Formatting.git") "temp/release"
Branches.checkoutBranch "temp/release" "release"
CopyRecursive "bin" "temp/release" true |> printfn "%A"
let cmd = sprintf """commit -a -m "Update binaries for version %s""" release.NugetVersion
CommandHelper.runSimpleGitCommand "temp/release" cmd |> printfn "%s"
Branches.push "temp/release"
)
Target "CreateTag" (fun _ ->
Branches.tag "" release.NugetVersion
Branches.pushTag "" "origin" release.NugetVersion
)
Target "Release" DoNothing
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target "All" DoNothing
"Clean" ==> "AssemblyInfo" ==> "Build" ==> "BuildTests"
"Build" ==> "MergeVSPowerTools" ==> "All"
"RunTests" ==> "All"
"GenerateDocs" ==> "All"
"UpdateFsxVersions" ==> "All"
"All"
==> "NuGet"
==> "ReleaseDocs"
// ==> "ReleaseBinaries"
==> "CreateTag"
==> "Release"
RunTargetOrDefault "All"