forked from fslaborg/flips
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.fsx
More file actions
254 lines (202 loc) · 7.73 KB
/
build.fsx
File metadata and controls
254 lines (202 loc) · 7.73 KB
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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#nowarn "0213"
#r "paket: groupref FakeBuild //"
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Tools
open System
open System.IO
// File system information
let solutionFile = "Flips.sln"
// Github repo
let repo = "https://github.com/matthewcrews/flips"
// Read additional information from the release notes document
let release = ReleaseNotes.load (__SOURCE_DIRECTORY__ @@ "RELEASE_NOTES.md")
// Helper active pattern for project types
let (|Fsproj|Csproj|Vbproj|Shproj|) (projFileName:string) =
match projFileName with
| f when f.EndsWith("fsproj") -> Fsproj
| f when f.EndsWith("csproj") -> Csproj
| f when f.EndsWith("vbproj") -> Vbproj
| f when f.EndsWith("shproj") -> Shproj
| _ -> failwith (sprintf "Project file %s not supported. Unknown project type." projFileName)
let srcGlob = __SOURCE_DIRECTORY__ @@ "Flips/*.??proj"
let fsSrcGlob = __SOURCE_DIRECTORY__ @@ "Flips/*.fs"
let fsTestGlob = __SOURCE_DIRECTORY__ @@ "Flips.Tests/*.fs"
let fsExpGlob = __SOURCE_DIRECTORY__ @@ "Flips.Examples/*.fs"
let bin = __SOURCE_DIRECTORY__ @@ "bin"
let docs = __SOURCE_DIRECTORY__ @@ "docs"
let libGlob = __SOURCE_DIRECTORY__ @@ "Flips/*.fsproj"
let examplesDir = __SOURCE_DIRECTORY__ @@ "Flips.Examples"
let fsSrcAndTest =
!! fsSrcGlob
++ fsTestGlob
++ fsExpGlob
-- (__SOURCE_DIRECTORY__ @@ "Flips/obj/**")
-- (__SOURCE_DIRECTORY__ @@ "Flips.Tests/obj/**")
-- (__SOURCE_DIRECTORY__ @@ "Flips.Examples/obj/**")
let configuration() =
FakeVar.getOrDefault "configuration" "Release"
let getEnvFromAllOrNone (s: string) =
let envOpt (envVar: string) =
if String.isNullOrEmpty envVar then None
else Some(envVar)
let procVar = Environment.GetEnvironmentVariable(s) |> envOpt
let userVar = Environment.GetEnvironmentVariable(s, EnvironmentVariableTarget.User) |> envOpt
let machVar = Environment.GetEnvironmentVariable(s, EnvironmentVariableTarget.Machine) |> envOpt
match procVar,userVar,machVar with
| Some(v), _, _
| _, Some(v), _
| _, _, Some(v)
-> Some(v)
| _ -> None
// Set default
FakeVar.set "configuration" "Release"
// --------------------------------------------------------------------------------------
// Set configuration mode based on target
Target.create "ConfigDebug" <| fun _ ->
FakeVar.set "configuration" "Debug"
Target.create "ConfigRelease" <| fun _ ->
FakeVar.set "configuration" "Release"
// --------------------------------------------------------------------------------------
// Clean tasks
Target.create "Clean" <| fun _ ->
let clean() =
!! (__SOURCE_DIRECTORY__ @@ "tests/**/bin")
++ (__SOURCE_DIRECTORY__ @@ "tests/**/obj")
++ (__SOURCE_DIRECTORY__ @@ "tools/bin")
++ (__SOURCE_DIRECTORY__ @@ "tools/obj")
++ (__SOURCE_DIRECTORY__ @@ "src/**/bin")
++ (__SOURCE_DIRECTORY__ @@ "src/**/obj")
|> Seq.toList
|> List.append [ bin ]
|> Shell.cleanDirs
TaskRunner.runWithRetries clean 10
Target.create "CleanDocs" <| fun _ ->
let clean() =
!! (docs @@ "RELEASE_NOTES.md")
|> List.ofSeq
|> List.iter Shell.rm
TaskRunner.runWithRetries clean 10
Target.create "CopyDocFiles" <| fun _ ->
[ docs @@ "RELEASE_NOTES.md", __SOURCE_DIRECTORY__ @@ "RELEASE_NOTES.md" ]
|> List.iter (fun (target, source) -> Shell.copyFile target source)
Target.create "PrepDocs" ignore
// --------------------------------------------------------------------------------------
// Restore tasks
let restoreSolution () =
solutionFile
|> DotNet.restore id
Target.create "Restore" <| fun _ ->
TaskRunner.runWithRetries restoreSolution 5
// --------------------------------------------------------------------------------------
// Build tasks
Target.create "Build" <| fun _ ->
let setParams (defaults: DotNet.BuildOptions) =
{ defaults with
NoRestore = true
MSBuildParams =
{ defaults.MSBuildParams with
Verbosity = Some(Quiet)
Targets = ["Build"]
Properties =
[
"Optimize", "True"
"DebugSymbols", "True"
"Configuration", configuration()
"Version", release.AssemblyVersion
"DependsOnNETStandard", "true"
]
}
}
restoreSolution()
!! libGlob
++ (examplesDir @@ "Flips.Examples.fsproj")
|> List.ofSeq
|> List.iter (DotNet.build setParams)
// --------------------------------------------------------------------------------------
// Lint source code
// Target.create "Lint" <| fun _ ->
// fsSrcAndTest
// -- (__SOURCE_DIRECTORY__ @@ "src/**/AssemblyInfo.*")
// |> (fun fGlob -> [(false, fGlob)])
// |> Seq.map (fun (b,glob) -> (b,glob |> List.ofSeq))
// |> List.ofSeq
// |> FSharpLinter.lintFiles
// --------------------------------------------------------------------------------------
// Run the unit tests
Target.create "RunTests" <| fun _ ->
DotNet.test id (__SOURCE_DIRECTORY__ @@ "Flips.Tests/Flips.Tests.fsproj")
// --------------------------------------------------------------------------------------
// Build and release NuGet targets
Target.create "NuGet" <| fun _ ->
Paket.pack(fun p ->
{ p with
OutputPath = "bin"
Version = release.NugetVersion
ReleaseNotes = Fake.Core.String.toLines release.Notes
ProjectUrl = repo
MinimumFromLockFile = true
IncludeReferencedProjects = true })
Target.create "NuGetPublish" <| fun _ ->
Paket.push(fun p ->
{ p with
ApiKey =
match getEnvFromAllOrNone "NUGET_KEY" with
| Some key -> key
| None -> failwith "The NuGet API key must be set in a NUGET_KEY environment variable"
WorkingDir = bin })
// --------------------------------------------------------------------------------------
// Release Scripts
let gitPush msg =
Git.Staging.stageAll ""
Git.Commit.exec "" msg
Git.Branches.push ""
Target.create "GitPush" <| fun p ->
p.Context.Arguments
|> List.choose (fun s ->
match s.StartsWith("--Msg=") with
| true -> Some(s.Substring 6)
| false -> None)
|> List.tryHead
|> function
| Some(s) -> s
| None -> (sprintf "Bump version to %s" release.NugetVersion)
|> gitPush
Target.create "GitTag" <| fun _ ->
Git.Branches.tag "" release.NugetVersion
Git.Branches.pushTag "" "origin" release.NugetVersion
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build -t <Target>' to override
Target.create "All" ignore
Target.create "Dev" ignore
Target.create "Release" ignore
Target.create "Publish" ignore
"Clean"
==> "Restore"
==> "Build"
"Build" ==> "RunTests"
"All"
==> "GitPush"
?=> "GitTag"
"All" <== [ "RunTests" ]
"CleanDocs"
==> "CopyDocFiles"
==> "PrepDocs"
"All"
==> "NuGet"
?=> "NuGetPublish"
"All" ==> "PrepDocs"
"ConfigDebug" ?=> "Clean"
"ConfigRelease" ?=> "Clean"
"Dev" <== ["All"; "ConfigDebug"; "PrepDocs"]
"Release" <== ["All"; "NuGet"; "ConfigRelease"]
"Publish" <== ["Release"; "ConfigRelease"; "NuGetPublish"; "Build"; "GitTag"; "GitPush" ]
Target.runOrDefaultWithArguments "Dev"