forked from fscheck/FsCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
259 lines (210 loc) · 8.24 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r @"./packages/FAKE/tools/FakeLib.dll"
#load "./packages/SourceLink.Fake/tools/SourceLink.fsx"
open Fake
open Fake.Git
open Fake.AssemblyInfoFile
open Fake.ReleaseNotesHelper
open Fake.Testing
open SourceLink
open System
open System.IO
open Fake.AppVeyor
// Information about each project is used
// - for version and project name in generated AssemblyInfo file
// - by the generated NuGet package
// - to run tests and to publish documentation on GitHub gh-pages
// - for documentation, you also need to edit info in "docs/tools/generate.fsx"
type ProjectInfo =
{ /// The name of the project
/// (used by attributes in AssemblyInfo, name of a NuGet package and directory in 'src')
Name : string
/// Short summary of the project
/// (used as description in AssemblyInfo and as a short summary for NuGet package)
Summary : string
}
//File that contains the release notes.
let releaseNotes = "FsCheck Release Notes.md"
/// Solution or project files to be built during the building process
let solution = if isMono then "FsCheck-mono.sln" else "FsCheck.sln"
/// Pattern specifying assemblies to be tested
let testAssemblies = "tests/**/bin/Release/*.Test.dll"
// Git configuration (used for publishing documentation in gh-pages branch)
// The profile where the project is posted
let gitHome = "ssh://github.com/fscheck"
// gitraw location - used for source linking
let gitRaw = environVarOrDefault "gitRaw" "https://raw.github.com/fscheck"
// The name of the project on GitHub
let gitName = "FsCheck"
// Read additional information from the release notes document
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let release = LoadReleaseNotes releaseNotes
let isAppVeyorBuild = buildServer = BuildServer.AppVeyor
let buildDate = DateTime.UtcNow
let buildVersion =
let isVersionTag tag = Version.TryParse tag |> fst
let hasRepoVersionTag = isAppVeyorBuild && AppVeyorEnvironment.RepoTag && isVersionTag AppVeyorEnvironment.RepoTagName
let assemblyVersion = if hasRepoVersionTag then AppVeyorEnvironment.RepoTagName else release.NugetVersion
if isAppVeyorBuild then sprintf "%s-b%s" assemblyVersion AppVeyorEnvironment.BuildNumber
else assemblyVersion
let packages =
[
{ Name = "FsCheck"
Summary = "FsCheck is a tool for testing .NET programs automatically using randomly generated test cases."
}
{ Name = "FsCheck.NUnit"
Summary = "Integrates FsCheck with NUnit"
}
{ Name = "FsCheck.Xunit"
Summary = "Integrates FsCheck with xUnit.NET"
}
]
Target "BuildVersion" (fun _ ->
Shell.Exec("appveyor", sprintf "UpdateBuild -Version \"%s\"" buildVersion) |> ignore
)
// Generate assembly info files with the right version & up-to-date information
Target "AssemblyInfo" (fun _ ->
packages |> Seq.iter (fun package ->
let fileName = "src/" + package.Name + "/AssemblyInfo.fs"
CreateFSharpAssemblyInfo fileName
([Attribute.Title package.Name
Attribute.Product package.Name
Attribute.Description package.Summary
Attribute.Version release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion
] @ (if package.Name = "FsCheck" then [Attribute.InternalsVisibleTo("FsCheck.Test")] else []))
)
)
// --------------------------------------------------------------------------------------
// Clean build results
Target "Clean" (fun _ ->
CleanDirs ["bin"; "temp"]
)
Target "CleanDocs" (fun _ ->
CleanDirs ["docs/output"]
)
// --------------------------------------------------------------------------------------
// Build library & test project
Target "Build" (fun _ ->
!! solution
|> MSBuildRelease "" "Rebuild"
|> ignore
)
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner
Target "RunTests" (fun _ ->
!! testAssemblies
|> xUnit2 (fun p ->
{p with
ToolPath = "packages/xunit.runner.console/tools/xunit.console.exe"
//The NoAppDomain setting requires care.
//On mono, it needs to be true otherwise xunit won't work due to a Mono bug.
//On .NET, it needs to be false otherwise Unquote won't work because it won't be able to load the FsCheck assembly.
NoAppDomain = isMono
ShadowCopy = false })
)
// --------------------------------------------------------------------------------------
// Source linking
Target "SourceLink" (fun _ ->
let baseUrl = sprintf "%s/%s/{0}/%%var2%%" gitRaw packages.[0].Name
!! "src/**/*.??proj"
|> Seq.iter (fun projFile ->
let proj = VsProj.LoadRelease projFile
SourceLink.Index proj.CompilesNotLinked proj.OutputFilePdb __SOURCE_DIRECTORY__ baseUrl
)
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target "PaketPack" (fun _ ->
Paket.Pack (fun p ->
{ p with
OutputPath = "bin"
Version = buildVersion
ReleaseNotes = toLines release.Notes
})
)
Target "PaketPush" (fun _ ->
Paket.Push (fun p ->
{ p with
WorkingDir = "bin"
})
)
// --------------------------------------------------------------------------------------
// Generate the documentation
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"
let generateHelp fail =
generateHelp' fail true
Target "KeepRunning" (fun _ ->
use watcher = new FileSystemWatcher(DirectoryInfo("docs/content").FullName,"*.fsx")
watcher.EnableRaisingEvents <- true
watcher.Changed.Add(fun e -> trace (sprintf "%A %A" e.Name e.ChangeType); generateHelp false)
watcher.Created.Add(fun e -> trace (sprintf "%A %A" e.Name e.ChangeType); generateHelp false)
watcher.Renamed.Add(fun e -> trace (sprintf "%A %A" e.Name e.ChangeType); generateHelp false)
//watcher.Deleted.Add(fun e -> trace (sprintf "%A %A" e.Name e.ChangeType); generateHelp false)
traceImportant "Waiting for help edits. Press any key to stop."
System.Console.ReadKey() |> ignore
watcher.EnableRaisingEvents <- false
watcher.Dispose()
)
Target "GenerateDocs" (fun _ ->
executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"; "--define:HELP"; "--define:REFERENCE"] [] |> ignore
)
Target "GenerateDocsJa" (fun _ ->
executeFSIWithArgs "docs/tools" "generate.ja.fsx" ["--define:RELEASE"] [] |> ignore
)
// --------------------------------------------------------------------------------------
// Release Scripts
Target "ReleaseDocs" (fun _ ->
let tempDocsDir = "temp/gh-pages"
CleanDir tempDocsDir
Repository.cloneSingleBranch "" ("[email protected]:fscheck/FsCheck.git") "gh-pages" tempDocsDir
fullclean tempDocsDir
CopyRecursive "docs/output" tempDocsDir true |> tracefn "%A"
StageAll tempDocsDir
Commit tempDocsDir (sprintf "Update generated documentation for version %s" buildVersion)
Branches.push tempDocsDir
)
Target "Release" (fun _ ->
StageAll ""
Commit "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.push ""
Branches.tag "" release.NugetVersion
Branches.pushTag "" "origin" release.NugetVersion
)
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target "CI" DoNothing
"Clean"
=?> ("BuildVersion", isAppVeyorBuild)
==> "AssemblyInfo"
==> "Build"
==> "RunTests"
"RunTests"
==> "CleanDocs"
==> "GenerateDocsJa"
==> "GenerateDocs"
=?> ("ReleaseDocs", isLocalBuild)
==> "Release"
"RunTests"
=?> ("SourceLink", isLocalBuild && not isLinux)
==> "PaketPack"
==> "PaketPush"
==> "Release"
"GenerateDocs"
==> "CI"
"RunTests"
==> "PaketPack"
==> "CI"
RunTargetOrDefault "RunTests"