-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
120 lines (100 loc) · 3.6 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "paket: groupref build //"
#load "./.fake/build.fsx/intellisense.fsx"
#r "netstandard"
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
let f projName =
let pattern = sprintf @"**/%s.fsproj" projName
let xs = !! pattern
xs
|> Seq.tryExactlyOne
|> Option.defaultWith (fun () ->
xs
|> List.ofSeq
|> failwithf "'%s' expected exactly one but:\n%A" pattern
)
let testProjName = "tests"
let testProjPath =
Path.combine
"tests"
(sprintf "%s.fsproj" testProjName)
let mainProjName = "MainProj"
let mainProjPath = f mainProjName
let mainProjDir =
Fake.IO.Path.getDirectory mainProjPath
let deployDir = Path.getFullName "./deploy"
let envPath = ".env"
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
open Fake.DotNet
let buildConf = DotNet.BuildConfiguration.Release
// --------------------------------------------------------------------------------------
// Targets
// --------------------------------------------------------------------------------------
let removeSQLiteInteropDll projPath =
let dir = Fake.IO.Path.getDirectory projPath
let localpath = sprintf "bin/%A/netcoreapp3.1/SQLite.Interop.dll" buildConf
let path = Fake.IO.Path.combine dir localpath
Fake.IO.File.delete path
Target.create "Clean" (fun _ -> Shell.cleanDir deployDir)
Target.create "BuildMain" (fun _ ->
mainProjDir
|> DotNet.build (fun x ->
{ x with Configuration = buildConf }
)
// uncommented if you use SQLiteInterop library
// removeSQLiteInteropDll mainProjPath
)
Target.create "BuildTest" (fun _ ->
testProjPath
|> Fake.IO.Path.getDirectory
|> DotNet.build (fun x ->
{ x with Configuration = buildConf }
)
// uncommented if you use SQLiteInterop library
// removeSQLiteInteropDll mainProjPath
// removeSQLiteInteropDll testProjPath
)
let dotnet cmd workingDir =
let result = DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir
Target.create "RunMain" (fun _ ->
mainProjDir
|> dotnet "run -c Release"
)
Target.create "RunMainTest" (fun _ ->
mainProjDir
|> dotnet "run -c TestBot"
)
Target.create "RunTests" (fun _ ->
testProjPath
|> Fake.IO.Path.getDirectory
|> dotnet "run -c Release"
)
let deploy () =
let runtimeOption = if Environment.isUnix then "--runtime linux-x64" else ""
dotnet (sprintf "publish -c Release -o \"%s\" %s" deployDir runtimeOption) mainProjDir
Target.create "Deploy" (fun _ -> deploy())
Target.create "CopyEnvToDeploy" (fun _ ->
if File.exists envPath then
Shell.copyFile (Path.combine deployDir envPath) envPath
)
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
open Fake.Core.TargetOperators
"Clean"
==> "Deploy"
==> "CopyEnvToDeploy"
Target.runOrDefault "CopyEnvToDeploy"