forked from fslaborg/RProvider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
215 lines (177 loc) · 7.94 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#I "packages/FAKE/tools"
#r "packages/FAKE/tools/FakeLib.dll"
open System
open Fake
open Fake.Git
open Fake.AssemblyInfoFile
open Fake.ReleaseNotesHelper
open Fake.Testing
// --------------------------------------------------------------------------------------
// Information about the project to be used at NuGet and in AssemblyInfo files
// --------------------------------------------------------------------------------------
let projectName = "RProvider"
let projectSummary = "An F# Type Provider providing strongly typed access to the R statistical package."
let projectDescription = """
An F# Type Provider providing strongly typed access to the R statistical package.
The type provider automatically discovers available R packages and makes them
easily accessible from F#, so you can easily call powerful packages and
visualization libraries from code running on the .NET platform."""
let authors = ["BlueMountain Capital"]
let companyName = "BlueMountain Capital"
let tags = "F# fsharp R TypeProvider visualization statistics"
let gitHome = "https://github.com/BlueMountainCapital"
let gitName = "FSharpRProvider"
// --------------------------------------------------------------------------------------
// The rest of the code is standard F# build script
// --------------------------------------------------------------------------------------
// Read release notes & version info from RELEASE_NOTES.md
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let binDir = __SOURCE_DIRECTORY__ @@ "bin"
let release = IO.File.ReadLines "RELEASE_NOTES.md" |> parseReleaseNotes
// Generate assembly info files with the right version & up-to-date information
Target "AssemblyInfo" (fun _ ->
let fileName = "src/Common/AssemblyInfo.fs"
CreateFSharpAssemblyInfoWithConfig fileName
[ Attribute.Title projectName
Attribute.Company companyName
Attribute.Product projectName
Attribute.Description projectSummary
Attribute.Version release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion ]
(AssemblyInfoFileConfig(false))
)
// --------------------------------------------------------------------------------------
// Update the assembly version numbers in the script file.
open System.IO
Target "UpdateFsxVersions" (fun _ ->
let path = "./src/RProvider/RProvider.fsx"
let mutable text = File.ReadAllText(path)
for package in [ "DynamicInterop"; "R.NET.Community"; "R.NET.Community.FSharp" ] do
let version = GetPackageVersion "packages" package
let pattern = "\\.\\./" + package + ".([0-9\\.]*)/lib"
let replacement = sprintf "../%s.%s/lib" package version
text <- Text.RegularExpressions.Regex.Replace(text, pattern, replacement)
File.WriteAllText(path, text)
)
// --------------------------------------------------------------------------------------
// Clean build results & restore NuGet packages
Target "Clean" (fun _ ->
CleanDirs ["bin"; "temp" ]
CleanDirs ["tests/Test.RProvider/bin"; "tests/Test.RProvider/obj" ]
)
Target "CleanDocs" (fun _ ->
CleanDirs ["docs/output"]
)
// --------------------------------------------------------------------------------------
// Build library & test project
Target "Build" (fun _ ->
!! (projectName + ".sln")
|> MSBuildRelease "" "Rebuild"
|> Log "AppBuild-Output: "
)
Target "BuildTests" (fun _ ->
!! (projectName + ".Tests.sln")
|> MSBuildRelease "" "Rebuild"
|> Log "AppBuild-Output: "
)
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner & kill test runner when complete
Target "RunTests" (fun _ ->
let xunitPath = "packages/xunit.runners/tools/xunit.console.clr4.exe"
ActivateFinalTarget "CloseTestRunner"
!! "tests/Test.RProvider/bin/**/Test*.dll"
|> xUnit (fun p ->
{p with
ToolPath = xunitPath
ShadowCopy = false
HtmlOutputPath = Some "."
XmlOutputPath = Some "." })
)
FinalTarget "CloseTestRunner" (fun _ ->
ProcessHelper.killProcess "xunit.console.clr4.exe"
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target "NuGet" (fun _ ->
// Format the description to fit on a single line (remove \r\n and double-spaces)
let specificVersion (name, version) = name, sprintf "[%s]" version
let projectDescription = projectDescription.Replace("\r", "").Replace("\n", "").Replace(" ", " ")
NuGet (fun p ->
{ p with
Authors = authors
Project = projectName
Summary = projectSummary
Description = projectDescription
Version = release.NugetVersion
ReleaseNotes = String.concat " " release.Notes
Tags = tags
OutputPath = "bin"
Dependencies =
[ "R.NET.Community", GetPackageVersion "packages" "R.NET.Community"
"DynamicInterop", GetPackageVersion "packages" "DynamicInterop"
"R.NET.Community.FSharp", GetPackageVersion "packages" "R.NET.Community.FSharp" ]
|> List.map specificVersion
AccessKey = getBuildParamOrDefault "nugetkey" ""
Publish = hasBuildParam "nugetkey" })
"nuget/RProvider.nuspec"
)
// --------------------------------------------------------------------------------------
// Generate the documentation
Target "GenerateDocs" (fun _ ->
executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore
)
// --------------------------------------------------------------------------------------
// Release Scripts
Target "ReleaseDocs" (fun _ ->
Repository.clone "" (gitHome + "/" + gitName + ".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 + "/" + gitName + ".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 "TagRelease" (fun _ ->
// Concatenate notes & create a tag in the local repository
let notes = (String.concat " " release.Notes).Replace("\n", ";").Replace("\r", "")
let tagName = "v" + release.NugetVersion
let cmd = sprintf """tag -a %s -m "%s" """ tagName notes
CommandHelper.runSimpleGitCommand "." cmd |> printfn "%s"
// Find the main remote (BlueMountain GitHub)
let _, remotes, _ = CommandHelper.runGitCommand "." "remote -v"
let main = remotes |> Seq.find (fun s -> s.Contains("(push)") && s.Contains("BlueMountainCapital/FSharpRProvider"))
let remoteName = main.Split('\t').[0]
Fake.Git.Branches.pushTag "." remoteName tagName
)
Target "Release" DoNothing
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target "All" DoNothing
Target "AllCore" DoNothing
"Clean"
==> "UpdateFsxVersions"
==> "AssemblyInfo"
==> "Build"
==> "BuildTests"
==> "RunTests"
==> "All"
"All"
==> "CleanDocs"
==> "GenerateDocs"
==> "ReleaseDocs"
==> "ReleaseBinaries"
==> "Release"
"All" ==> "NuGet" ==> "Release"
"All" ==> "TagRelease" ==> "Release"
RunTargetOrDefault "All"