-
Notifications
You must be signed in to change notification settings - Fork 2
/
Build.fs
265 lines (220 loc) · 8.8 KB
/
Build.fs
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
255
256
257
258
259
260
261
262
263
264
265
open System
open System.IO
open Fake.Core
open Fake.DotNet
open Fake.Core.TargetOperators
open Fake.IO
open Farmer
open Farmer.Builders
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Tools
open Helpers
initializeContext()
//-----------------------------------------------
// Information about the project to be used at NuGet and in AssemblyInfo files
// --------------------------------------------------------------------------------------
let deployDir = Path.getFullName "./deploy"
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let unitTestsPath = Path.getFullName "./tests/AzureTackle.Tests/"
let buildDir = "./build/"
// Git configuration (used for publishing documentation in gh-pages branch)
// The profile where the project is posted
let gitHome = "https://github.com/tforkmann"
// The name of the project on GitHub
let gitName = "AzureTackle"
// The name of the project
// (used by attributes in AssemblyInfo, name of a NuGet package and directory in 'src')
let project = "AzureTackle"
let projectUrl = sprintf "%s/%s" gitHome gitName
// Short summary of the project
// (used as description in AssemblyInfo and as a short summary for NuGet package)
let summary = "Thin F# API for AzureTackle"
let copyright = "Copyright \169 2024"
let iconUrl = "https://raw.githubusercontent.com/tforkmann/AzureTackle/master/AzureTackle_logo.png"
let licenceUrl = "https://github.com/tforkmann/AzureTackle/blob/master/LICENSE.md"
let configuration = DotNet.BuildConfiguration.Release
// Longer description of the project
// (used as a description for NuGet package; line breaks are automatically cleaned up)
let description = """Thin F# API for AzureTackle for easy data access to AzureTackle database with functional seasoning on top."""
// List of author names (for NuGet package)
let authors = [ "Tim Forkmann"]
let owner = "Tim Forkmann"
// Tags for your project (for NuGet package)
let tags = "Thin F# API for AzureTackle for easy data access to AzureTackle database with functional seasoning on top"
// --------------------------------------------------------------------------------------
// PlatformTools
// --------------------------------------------------------------------------------------
let platformTool tool winTool =
let tool = if Environment.isUnix then tool else winTool
match ProcessUtils.tryFindFileOnPath tool with
| Some t -> t
| _ ->
let errorMsg =
tool + " was not found in path. " +
"Please install it and make sure it's available from your path. " +
"See https://safe-stack.github.io/docs/quickstart/#install-pre-requisites for more info"
failwith errorMsg
let nodeTool = platformTool "node" "node.exe"
let yarnTool = platformTool "yarn" "yarn.cmd"
let npmTool = platformTool "npm" "npm.cmd"
// --------------------------------------------------------------------------------------
// Standard DotNet Build Steps
// --------------------------------------------------------------------------------------
let install = lazy DotNet.install DotNet.Versions.FromGlobalJson
let inline withWorkDir wd =
DotNet.Options.lift install.Value
>> DotNet.Options.withWorkingDirectory wd
let runTool cmd args workingDir =
let arguments = args |> String.split ' ' |> Arguments.OfArgs
RawCommand (cmd, arguments)
|> CreateProcess.fromCommand
|> CreateProcess.withWorkingDirectory workingDir
|> CreateProcess.ensureExitCode
|> Proc.run
|> ignore
let runDotNet cmd workingDir =
let result =
DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir
// --------------------------------------------------------------------------------------
// Clean Build Results
// --------------------------------------------------------------------------------------
Target.create "Clean" (fun _ ->
!!"src/**/bin"
|> Shell.cleanDirs
!! "src/**/obj/*.nuspec"
|> Shell.cleanDirs
Shell.cleanDirs [buildDir; "temp"; "docs/output"; deployDir;]
)
Target.create
"UpdateTools"
(fun _ ->
run dotnet "tool update fantomas-tool" __SOURCE_DIRECTORY__
run dotnet "tool update fake-cli" __SOURCE_DIRECTORY__
run dotnet "tool update paket" __SOURCE_DIRECTORY__
)
open System.Text.RegularExpressions
module Util =
let visitFile (visitor: string->string) (fileName: string) =
File.ReadAllLines(fileName)
|> Array.map (visitor)
|> fun lines -> File.WriteAllLines(fileName, lines)
let replaceLines (replacer: string->Match->string option) (reg: Regex) (fileName: string) =
fileName |> visitFile (fun line ->
let m = reg.Match(line)
if not m.Success
then line
else
match replacer line m with
| None -> line
| Some newLine -> newLine)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target.create "Build" (fun _ ->
!! "src/**/*.fsproj"
|> Seq.filter (fun s ->
let name = Path.GetDirectoryName s
not (name.Contains "docs"))
|> Seq.iter (fun s ->
let dir = Path.GetDirectoryName s
DotNet.build id dir)
)
Target.create "UnitTests" (fun _ ->
runDotNet "run" unitTestsPath
)
Target.create "PrepareRelease" (fun _ ->
Git.Branches.checkout "" false "master"
Git.CommandHelper.directRunGitCommand "" "fetch origin" |> ignore
Git.CommandHelper.directRunGitCommand "" "fetch origin --tags" |> ignore
Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Bumping version to %O" release.NugetVersion)
Git.Branches.pushBranch "" "origin" "master"
let tagName = string release.NugetVersion
Git.Branches.tag "" tagName
Git.Branches.pushTag "" "origin" tagName
)
Target.create "Pack" (fun _ ->
let nugetVersion = release.NugetVersion
let pack project =
let projectPath = sprintf "src/%s/%s.fsproj" project project
let args =
let defaultArgs = MSBuild.CliArguments.Create()
{ defaultArgs with
Properties = [
"Title", project
"PackageVersion", nugetVersion
"Authors", (String.Join(" ", authors))
"Owners", owner
"PackageRequireLicenseAcceptance", "false"
"Description", description
"Summary", summary
"PackageReleaseNotes", ((String.toLines release.Notes).Replace(",",""))
"Copyright", copyright
"PackageTags", tags
"PackageProjectUrl", projectUrl
"PackageIconUrl", iconUrl
"PackageLicenseUrl", licenceUrl
] }
DotNet.pack (fun p ->
{ p with
NoBuild = false
Configuration = configuration
OutputPath = Some "build"
MSBuildParams = args
}) projectPath
pack "AzureTackle"
pack "AzureTackle.Shared"
)
let getBuildParam = Environment.environVar
let isNullOrWhiteSpace = String.IsNullOrWhiteSpace
// Workaround for https://github.com/fsharp/FAKE/issues/2242
let pushPackage _ =
let nugetCmd fileName key = sprintf "nuget push %s -k %s -s nuget.org" fileName key
let key =
//Environment.environVarOrFail "nugetKey"
match getBuildParam "nugetkey" with
| s when not (isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserPassword "NuGet Key: "
IO.Directory.GetFiles(buildDir, "*.nupkg", SearchOption.TopDirectoryOnly)
|> Seq.map Path.GetFileName
|> Seq.iter (fun fileName ->
Trace.tracef "fileName %s" fileName
let cmd = nugetCmd fileName key
runDotNet cmd buildDir)
Target.create "Push" (fun _ -> pushPackage [] )
let docsSrcPath = Path.getFullName "./src/docs"
let docsDeployPath = "docs"
Target.create "InstallDocs" (fun _ ->
runTool npmTool "install --frozen-lockfile" "."
runDotNet "restore" docsSrcPath )
Target.create "PublishDocs" (fun _ -> run npm "run build" ".")
Target.create "RunDocs" (fun _ ->
run npm "run start" ".")
Target.runOrDefault "Build"
let dependencies = [
"Clean"
// ==> "UpdateTools"
==> "UnitTests"
"Clean"
// ==> "UpdateTools"
==> "Build"
// ==> "UnitTests"
==> "PrepareRelease"
==> "Pack"
==> "Push"
"InstallDocs"
==> "RunDocs"
"InstallDocs"
==> "PublishDocs"
]
[<EntryPoint>]
let main args =
try
match args with
| [| target |] -> Target.runOrDefault target
| _ -> Target.runOrDefault "UnitTests"
0
with e ->
printfn "%A" e
1