-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.fsx
191 lines (153 loc) · 4.31 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
#r "paket:
nuget Fantomas.Extras
nuget Fake.DotNet.Cli
nuget Fake.DotNet.NuGet
nuget Fake.IO.FileSystem
nuget Fake.Core.Target //"
#load ".fake/build.fsx/intellisense.fsx"
open System
open Fantomas
open Fantomas.Extras
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
[<Literal>]
let solution = "Fugit.sln"
[<Literal>]
let NugetSource = "https://api.nuget.org/v3/index.json"
let (|NullOrWhitespaceString|ValueString|) (str: string) =
if String.isNullOrWhiteSpace str then NullOrWhitespaceString else ValueString str
let tryGetEnvironmentVariable name =
let tryString =
function
| NullOrWhitespaceString -> None
| ValueString var -> Some var
[ Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process)
Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.User)
Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Machine) ]
|> List.choose tryString
|> List.tryHead
let getEnvironmentVariable name =
match tryGetEnvironmentVariable name with
| None -> failwith $"Could not find environment variable %s{name}"
| Some var -> var
// Targets
Target.initEnvironment ()
// Linting
Target.create "Check F# formatting"
<| fun _ ->
let result =
!! "**/*.fs"
-- "**/bin/**/*.fs"
-- "**/obj/**/*.fs"
|> FakeHelpers.checkCode
|> Async.RunSynchronously
if result.IsValid then
Trace.log "No files need formatting"
elif result.NeedsFormatting then
Trace.log "The following files need formatting:"
result.Formatted |> List.iter Trace.log
failwith "Some files need formatting, check output for more info"
else
Trace.log $"Errors while formatting: {result.Errors}"
Target.create "Format F# code"
<| fun _ ->
let formattedFiles =
!! "**/*.fs"
-- "**/bin/**/*.fs"
-- "**/obj/**/*.fs"
|> FakeHelpers.formatCode
|> Async.RunSynchronously
if not << Array.isEmpty <| formattedFiles then
Trace.log "Formatted files:"
formattedFiles |> Array.iter (Trace.logfn "%s")
else
Trace.log "No files needed formatting"
// Cleaning
Target.create "Clean"
<| fun _ ->
!! "src/**/bin"
++ "src/**/obj"
++ "tests/**/bin"
++ "tests/**/obj"
++ "NuGet"
|> Shell.cleanDirs
// Restore
Target.create "Restore"
<| fun _ -> solution |> DotNet.restore id
// Build
Target.create "Build"
<| fun _ ->
!! "src/**/*.*proj"
|> Seq.iter (
DotNet.build
(fun o ->
{ o with
Configuration = DotNet.BuildConfiguration.Release
NoLogo = true
NoRestore = true })
)
Target.create "Build tests"
<| fun _ ->
!! "tests/**/*.*proj"
|> Seq.iter (
DotNet.build
(fun o ->
{ o with
NoLogo = true
NoRestore = true })
)
// Running tests
Target.create "Run tests"
<| fun _ ->
!! "tests/**/*.*proj"
|> Seq.iter (
DotNet.test
(fun o ->
{ o with
NoLogo = true
NoRestore = true })
)
// NuGet
Target.create "Create NuGet packages"
<| fun _ ->
!! "src/**/*.*proj"
|> Seq.iter (
DotNet.pack
(fun o ->
{ o with
NoLogo = true
OutputPath = Some "NuGet" })
)
Target.create "Push NuGet packages"
<| fun _ ->
let apiKey = getEnvironmentVariable "NUGET_KEY"
!! "NuGet/Fugit.*.nupkg"
|> Seq.iter (
DotNet.nugetPush
(fun o ->
{ o with
PushParams =
{ o.PushParams with
ApiKey = Some apiKey
Source = Some NugetSource } })
)
// Combinations
Target.create "All" ignore
Target.create "Deploy" ignore
// Dependencies
"Clean" ==> "Restore" ==> "Build"
"Build" ==> "Run tests"
"Clean"
?=> "Format F# code"
?=> "Check F# formatting"
"Check F# formatting" ?=> "Build" ?=> "Run tests"
"All" <== [ "Check F# formatting"; "Run tests" ]
"All"
==> "Create NuGet packages"
==> "Push NuGet packages"
==> "Deploy"
// Run
Target.runOrDefaultWithArguments "All"