forked from fscheck/FsCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
325 lines (272 loc) · 12.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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r @"./packages/FAKE/tools/NuGet.Core.dll"
#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
// 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
/// Longer description of the project
/// (used as a description for NuGet package; line breaks are automatically cleaned up)
Description : string
/// List of author names (for NuGet package)
Authors : string list
/// Tags for your project (for NuGet package)
Tags : string
///The projectfile (csproj or fsproj)
ProjectFile : list<string>
Dependencies : list<string * Lazy<string>>
Files: list<string>
//For extra files like tools and content string*string is for path target, if an excludes becomes necesary a third tuple element string option can be added
FilesExtra: list<string * 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 = parseReleaseNotes (IO.File.ReadAllLines releaseNotes)
let packages =
[
{
Name = "FsCheck"
Files = ["FsCheck"]
FilesExtra = []
Summary = "FsCheck is a tool for testing .NET programs automatically using randomly generated test cases."
Description = """
FsCheck is a tool for testing .NET programs automatically. The programmer provides
a specification of the program, in the form of properties which functions, methods
or objects should satisfy, and FsCheck then tests that the properties hold in a
large number of randomly generated cases.
While writing the properties, you are actually writing a testable specification of your program.
Specifications are expressed in F#, C# or VB, using combinators defined
in the FsCheck library. FsCheck provides combinators to define properties,
observe the distribution of test data, and define test data generators.
When a property fails, FsCheck automatically displays a minimal counter example."""
Authors = [ "Kurt Schelfthout and contributors" ]
Tags = "test testing random fscheck quickcheck"
ProjectFile = ["src/FsCheck/FsCheck.fsproj" ]
Dependencies = ["FSharp.Core", lazy "3.1.2.1" ]
}
{
Name = "FsCheck.NUnit"
Files = ["FsCheck.NUnit"; "FsCheck.NUnit.Addin"]
FilesExtra = [("FsCheck.NUnit.nuspec.tools\install.ps1", "tools\install.ps1");(@"FsCheck.NUnit.nuspec.tools\FsCheckAddin.fs","content\FsCheckAddin.fs")]
Summary = "Integrates FsCheck with NUnit"
Description = """FsCheck.NUnit integrates FsCheck with NUnit by adding a PropertyAttribute that runs FsCheck tests, similar to NUnit TestAttribute.
All the options normally available in vanilla FsCheck via configuration can be controlled via the PropertyAttribute."""
Authors = [ "Kurt Schelfthout and contributors" ]
Tags = "test testing random fscheck quickcheck nunit"
ProjectFile = ["src/FsCheck.NUnit/FsCheck.NUnit.fsproj";"src/FsCheck.NUnit.Addin/FsCheck.NUnit.Addin.fsproj"]
Dependencies = [
"NUnit", lazy GetPackageVersion "./packages/" "NUnit" //delayed so only runs after package restore step
"NUnit.Runners", lazy GetPackageVersion "./packages/" "NUnit.Runners"
"FsCheck", lazy release.NugetVersion
]
}
{
Name = "FsCheck.Xunit"
Files = ["FsCheck.Xunit"]
FilesExtra = []
Summary = "Integrates FsCheck with xUnit.NET"
Description = """
FsCheck.Xunit integrates FsCheck with xUnit.NET by adding a PropertyAttribute that runs FsCheck tests, similar to xUnit.NET's FactAttribute.
All the options normally available in vanilla FsCheck via configuration can be controlled via the PropertyAttribute."""
Authors = [ "Kurt Schelfthout and contributors" ]
Tags = "test testing random fscheck quickcheck xunit xunit.net"
ProjectFile = ["src/FsCheck.Xunit/FsCheck.Xunit.fsproj"]
Dependencies = [
"xunit", lazy GetPackageVersion "./packages/" "xunit" //delayed so only runs after package restore step
"FsCheck", lazy release.NugetVersion
]
}
]
// 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 & restore NuGet packages
Target "RestorePackages" RestorePackages
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
|> xUnit (fun p ->
{p with
ToolPath = "packages/xunit.runners/tools/xunit.console.clr4.exe"
ShadowCopy = false })
)
// --------------------------------------------------------------------------------------
// Source linking
Target "SourceLink" (fun _ ->
use repo = new GitRepo(__SOURCE_DIRECTORY__)
let LogAndVerify (proj: Microsoft.Build.Evaluation.Project) =
logfn "source linking %s" proj.OutputFilePdb
let files = proj.Compiles -- "**/AssemblyInfo.fs"
repo.VerifyChecksums files
proj.VerifyPdbChecksums files
proj.CreateSrcSrv (sprintf "%s/%s/{0}/%%var2%%" gitRaw gitName) repo.Commit (repo.Paths files)
Pdbstr.exec proj.OutputFilePdb proj.OutputFilePdbSrcSrv
packages
|> Seq.iter (fun f ->
let proj = List.map VsProj.LoadRelease f.ProjectFile
List.iter (fun p-> LogAndVerify p) proj
)
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
type OptionalString = string option
open System
open System.IO
Target "NuGet" (fun _ ->
let createFilesList (fileNames: string list) (extra: list<string*string> ) =
let createBinariesFiles fileNames =
let extensions = [ "dll";"pdb";"XML"]
[for filename in fileNames do
for ext in extensions do
yield (sprintf @"..\src\%s\bin\Release\%s.%s" filename filename ext, Some @"lib\net45", OptionalString.None)]
let addExtras (extraFiles:list<string*string>) =
extraFiles
|> List.map (fun f -> (fst f, Some (snd f), OptionalString.None))
createBinariesFiles fileNames@addExtras extra
packages |> Seq.iter (fun package ->
NuGet (fun p ->
{ p with
Authors = package.Authors
Project = package.Name
Summary = package.Summary
Description = package.Description
Version = release.NugetVersion
ReleaseNotes = String.Join(Environment.NewLine, release.Notes)
Tags = package.Tags
OutputPath = "bin"
AccessKey = getBuildParamOrDefault "nugetkey" ""
Publish = hasBuildParam "nugetkey"
//ProjectFile = package.ProjectFile //if we add this, it produces a symbols package
Dependencies = package.Dependencies |> List.map (fun (name,dep) -> (name,dep.Force()))
Files = createFilesList package.Files package.FilesExtra
})
("nuget/" + package.Name + ".nuspec")
)
)
// --------------------------------------------------------------------------------------
// 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" release.NugetVersion)
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 "All" DoNothing
Target "CI" DoNothing
"Clean"
==> "RestorePackages"
==> "AssemblyInfo"
==> "Build"
==> "RunTests"
==> "All"
==> "CleanDocs"
==> "GenerateDocsJa"
==> "GenerateDocs"
==> "CI"
==> "ReleaseDocs"
=?> ("SourceLink", isLocalBuild && not isLinux)
==> "NuGet"
==> "Release"
RunTargetOrDefault "All"