forked from fsprojects/FSharp.Data.SqlClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
231 lines (187 loc) · 7.54 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
// --------------------------------------------------------------------------------------
// 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
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let files includes =
{ BaseDirectory = __SOURCE_DIRECTORY__
Includes = includes
Excludes = [] }
// Information about the project to be used at NuGet and in AssemblyInfo files
let project = "FSharp.Data.SqlClient"
let authors = ["Dmitry Morozov, Dmitry Sevastianov"]
let summary = "SqlClient F# type providers"
let description = "SqlCommandProvider provides statically typed access to input parameters and result set of T-SQL command in idiomatic F# way.\nSqlProgrammabilityProvider exposes Stored Procedures, User-Defined Types and User-Defined Functions in F# code."
let tags = "F# fsharp data typeprovider sql"
let gitHome = "https://github.com/fsprojects"
let gitName = "FSharp.Data.SqlClient"
// Read release notes & version info from RELEASE_NOTES.md
let release =
File.ReadLines "RELEASE_NOTES.md"
|> ReleaseNotesHelper.parseReleaseNotes
let version = release.AssemblyVersion
let releaseNotes = release.Notes |> String.concat "\n"
let testDir = "bin"
// --------------------------------------------------------------------------------------
// Generate assembly info files with the right version & up-to-date information
Target "AssemblyInfo" (fun _ ->
[ "src/SqlClient/AssemblyInfo.fs", "SqlClient", project, summary ]
|> Seq.iter (fun (fileName, title, project, summary) ->
CreateFSharpAssemblyInfo fileName
[ Attribute.Title title
Attribute.Product project
Attribute.Description summary
Attribute.Version version
Attribute.FileVersion version] )
)
// --------------------------------------------------------------------------------------
// Clean build results & restore NuGet packages
Target "RestorePackages" (fun _ ->
!! "./**/packages.config"
|> Seq.iter (RestorePackage (fun p -> { p with ToolPath = "./.nuget/NuGet.exe" }))
)
Target "Clean" (fun _ ->
CleanDirs ["bin"; "temp"]
)
Target "CleanDocs" (fun _ ->
CleanDirs ["docs/output"]
)
// --------------------------------------------------------------------------------------
// Build library (builds Visual Studio solution, which builds multiple versions
// of the runtime library & desktop + Silverlight version of design time library)
Target "Build" (fun _ ->
files (["SqlClient.sln"])
|> MSBuildRelease "" "Rebuild"
|> ignore
)
#r "System.Data"
#r "System.Transactions"
#r "System.Configuration"
#r "System.IO.Compression"
#r "System.IO.Compression.FileSystem"
open System.Data.SqlClient
open System.Configuration
open System.IO.Compression
Target "DeployTestDB" (fun() ->
let testsSourceRoot = Path.GetFullPath(@"src\SqlClient.Tests")
let map = ExeConfigurationFileMap()
map.ExeConfigFilename <- testsSourceRoot @@ "app.config"
let connStr =
let x =
ConfigurationManager
.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None)
.ConnectionStrings
.ConnectionStrings.["AdventureWorks"]
.ConnectionString
SqlConnectionStringBuilder(x)
let database = connStr.InitialCatalog
use conn =
connStr.InitialCatalog <- ""
new SqlConnection(string connStr)
conn.Open()
do //attach
let dbIsMissing =
let query = sprintf "SELECT COUNT(*) FROM sys.databases WHERE name = '%s'" database
use cmd = new SqlCommand(query, conn)
cmd.ExecuteScalar() = box 0
if dbIsMissing
then
let dataFileName = "AdventureWorks2012_Data"
//unzip
let sourceMdf = testsSourceRoot @@ (dataFileName + ".mdf")
if File.Exists(sourceMdf) then File.Delete(sourceMdf)
ZipFile.ExtractToDirectory(testsSourceRoot @@ (dataFileName + ".zip"), testsSourceRoot)
let dataPath =
use cmd = new SqlCommand("SELECT SERVERPROPERTY('InstanceDefaultDataPath')", conn)
cmd.ExecuteScalar() |> string
do
let destFileName = dataPath @@ Path.GetFileName(sourceMdf)
File.Copy(sourceMdf, destFileName, overwrite = true)
File.Delete( sourceMdf)
use cmd = new SqlCommand(Connection = conn)
cmd.CommandText <- sprintf "CREATE DATABASE [%s] ON ( FILENAME = N'%s' ) FOR ATTACH" database destFileName
cmd.ExecuteNonQuery() |> ignore
do //create extra object to test corner case
let script = File.ReadAllText(testsSourceRoot @@ "extensions.sql")
for batch in script.Split([|"GO"|], StringSplitOptions.RemoveEmptyEntries) do
use cmd = new SqlCommand(batch, conn)
cmd.ExecuteNonQuery() |> ignore
)
Target "BuildTests" (fun _ ->
files ["Tests.sln"]
|> MSBuildReleaseExt "" ([]) "Rebuild"
|> ignore
)
// --------------------------------------------------------------------------------------
// Run the unit tests
Target "RunTests" (fun _ ->
!! (testDir + "/*.Tests.dll")
|> xUnit (fun p ->
{p with
ShadowCopy = false;
HtmlOutput = true;
XmlOutput = true;
OutputDir = testDir})
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target "NuGet" (fun _ ->
// Format the description to fit on a single line (remove \r\n and double-spaces)
let description = description.Replace("\r", "").Replace("\n", "").Replace(" ", " ")
let nugetPath = ".nuget/nuget.exe"
NuGet (fun p ->
{ p with
Authors = authors
Project = project
Summary = summary
Description = description
Version = version
ReleaseNotes = releaseNotes
Tags = tags
OutputPath = "nuget"
ToolPath = nugetPath
AccessKey = getBuildParamOrDefault "nugetkey" ""
Publish = hasBuildParam "nugetkey"
Dependencies = [] })
"nuget/SqlClient.nuspec"
)
// --------------------------------------------------------------------------------------
// Generate the documentation
Target "GenerateDocs" (fun _ ->
executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore
)
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 "Release" DoNothing
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target "All" DoNothing
"Clean"
==> "RestorePackages"
==> "AssemblyInfo"
==> "Build"
==> "DeployTestDB"
==> "BuildTests"
==> "RunTests"
==> "All"
"All"
==> "NuGet"
==> "Release"
"All"
==> "CleanDocs"
==> "GenerateDocs"
==> "ReleaseDocs"
RunTargetOrDefault "All"