forked from haf/Http.fs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
executable file
·182 lines (156 loc) · 6.06 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
#!/usr/bin/env fsharpi
#I @"packages/FAKE/tools"
#r @"FakeLib.dll"
open Fake
open System.IO
open Fake.AssemblyInfoFile
// Paths
let httpClientDir = "./HttpFs/"
let unitTestsDir = "HttpFs.UnitTests/"
let integrationTestsDir = "./HttpFs.IntegrationTests/"
let sampleApplicationDir = "./HttpFs.SampleApplication/"
let releaseDir = "Release/"
let nuGetDir = releaseDir + "NuGet/"
let nuGetProjectDll = nuGetDir + "lib/net45/HttpFs.dll"
let nUnitToolPath = "packages/NUnit.Runners/tools/"
// Helper Functions
let outputFolder baseDir =
baseDir + "bin/Debug/"
let projectFolder baseDir =
baseDir + "*.fsproj"
let binFolder baseDir =
baseDir + "bin/"
let assemblyInfo baseDir =
baseDir + "AssemblyInfo.fs"
let BuildTarget targetName baseDirectory =
Target targetName (fun _ ->
!! (baseDirectory |> projectFolder)
|> MSBuildReleaseExt (baseDirectory |> outputFolder) ["TreatWarningsAsErrors","true"] "Build"
|> Log (targetName + "-Output: ")
)
// Targets
Target "Clean" (fun _ ->
CleanDirs [
httpClientDir |> binFolder
unitTestsDir |> binFolder
integrationTestsDir |> binFolder
sampleApplicationDir |> binFolder
]
)
Target "Update Assembly Version" (fun _ ->
CreateFSharpAssemblyInfo (httpClientDir |> assemblyInfo) [
Attribute.Title "HttpFs"
Attribute.Description "An HTTP client for F#"
Attribute.Guid "4ead3524-8220-4f0b-b77d-edd088597fcf"
Attribute.Product "Http.fs"
Attribute.Version (getBuildParamOrDefault "nuget-version" "2.0.0")
Attribute.FileVersion (getBuildParamOrDefault "nuget-version" "2.0.0")
]
)
BuildTarget "BuildClient" httpClientDir
BuildTarget "BuildUnitTests" unitTestsDir
BuildTarget "BuildIntegrationTests" integrationTestsDir
BuildTarget "BuildSampleApplication" sampleApplicationDir
Target "Run Unit Tests" (fun _ ->
let result =
ExecProcess (fun info ->
info.FileName <- (unitTestsDir |> outputFolder) @@ "HttpFs.UnitTests.exe"
) (System.TimeSpan.FromSeconds(30.))
match result with
| 0 -> ()
| _ -> failwith "Unit-tests failed."
)
// If these fail, it might be because the test server URL isn't registered - see RegisterURL.bat
Target "Run Integration Tests" (fun _ ->
let integrationTestOutputFolder = integrationTestsDir |> outputFolder
!! (integrationTestOutputFolder + "/*.IntegrationTests.dll")
|> NUnit (fun p ->
{p with
ToolPath = nUnitToolPath;
DisableShadowCopy = true;
OutputFile = integrationTestOutputFolder + "TestResults.xml"})
)
// copy the distributable source files & dll into the Release folder
Target "Copy Release Files" (fun _ ->
CopyFiles
releaseDir
[
httpClientDir + "Prelude.fs"
httpClientDir + "AsyncStreamReader.fs"
httpClientDir + "Client.fs"
(httpClientDir |> outputFolder) + "HttpFs.dll"
]
)
// note to self - call like this:
// packages/FAKE/tools/fake.exe build.fsx nuget-version=1.1.0 nuget-api-key=(my api key) nuget-release-notes="latest release"
Target "Upload to NuGet" (fun _ ->
// Copy the dll into the right place
CopyFiles
(releaseDir + "NuGet/lib/net45")
[(httpClientDir |> outputFolder) + "HttpFs.dll"]
trace <| "buildParam nuget-version: " + getBuildParam "nuget-version"
trace <| "buildParam nuget-api-key: " + getBuildParam "nuget-api-key"
let version = getBuildParam "nuget-version"
let nuspec = Path.Combine(nuGetDir, "Http.fs.nuspec")
File.WriteAllText(nuspec,
"""<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>@project@</id>
<version>@build.number@</version>
<authors>@authors@</authors>
<owners>@authors@</owners>
<summary>@summary@</summary>
<licenseUrl>https://raw.githubusercontent.com/relentless/Http.fs/master/Licence/License.md</licenseUrl>
<projectUrl>https://github.com/relentless/Http.fs</projectUrl>
<iconUrl>https://raw.githubusercontent.com/relentless/http.fs/master/docs/files/img/logo.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>@description@</description>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>Copyright G Crofton 2014</copyright>
<tags>http client fsharp f# request response</tags>
@dependencies@
@references@
</metadata>
@files@
</package>""")
// Create and upload package
NuGet (fun n ->
{n with
Authors = ["Grant Crofton"]
Summary = "A gloriously functional HTTP client library for F#!"
OutputPath = nuGetDir
WorkingDir = nuGetDir
Project = "Http.fs"
Version = version
AccessKey = getBuildParam "nuget-api-key"
ReleaseNotes = getBuildParam "nuget-release-notes"
PublishTrials = 3
Publish = bool.Parse(getBuildParamOrDefault "nuget-publish" "true")
ToolPath = FullName "./packages/NuGet.CommandLine/tools/NuGet.exe"
Files =
[ "lib\\net45\\*.dll", Some "lib\\net45", None
"lib\\net45\\*.mdb", Some "lib\\net45", None
"lib\\net45\\*.xml", Some "lib\\net45", None ]
Dependencies =
[ "FSharp.Core", GetPackageVersion "./packages" "FSharp.Core" ] })
nuspec
)
Target "All" (fun _ ->
// A dummy target so I can build everything easily
()
)
// Dependencies
"Clean"
==> "Update Assembly Version"
==> "BuildClient"
==> "BuildUnitTests" <=> "BuildIntegrationTests" <=> "BuildSampleApplication"
==> "Run Unit Tests" <=> "Run Integration Tests"
==> "Copy Release Files"
=?> ("Upload to NuGet", // run this if all params secified
hasBuildParam "nuget-version" &&
hasBuildParam "nuget-api-key" &&
hasBuildParam "nuget-release-notes")
==> "All"
// start build
RunTargetOrDefault "All"