This repository has been archived by the owner on Apr 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.fsx
105 lines (86 loc) · 3.32 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
#r "paket: groupref Build //"
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.BuildServer
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.JavaScript
BuildServer.install [
TeamFoundation.Installer
]
Target.create "Install.Prerequisites" (fun _ ->
if not BuildServer.isLocalBuild then
let npmPath = ProcessUtils.tryFindFileOnPath "npm"
if npmPath.IsNone then failwith "npm could not be found"
let npmInstallAngularCli =
["install"; "-g"; "@angular/cli"]
|> CreateProcess.fromRawCommand npmPath.Value
|> CreateProcess.withWorkingDirectory "./src/web"
|> Proc.run
if npmInstallAngularCli.ExitCode <> 0 then failwith "could not install angular cli via npm"
)
Target.create "Build.Frontend" (fun _ ->
Npm.install (fun o ->
{ o with
WorkingDirectory = "./src/web"
})
let angular = ProcessUtils.tryFindFileOnPath "ng"
if angular.IsNone then failwith "angular cli could not be found"
let angularResult =
["build"; "--prod"]
|> CreateProcess.fromRawCommand angular.Value
|> CreateProcess.withWorkingDirectory "./src/web"
|> Proc.run
if angularResult.ExitCode <> 0 then failwith "could not build frontend"
)
Target.create "Build.Backend" (fun _ ->
let buildParams (o: DotNet.BuildOptions) =
{ o with
Configuration = DotNet.BuildConfiguration.Release
}
DotNet.build buildParams "./src/web/web.csproj"
)
Target.create "Publish" (fun _ ->
let publishParams (o: DotNet.PublishOptions) =
if BuildServer.isLocalBuild then
{ o with
Configuration = DotNet.BuildConfiguration.Release
}
else
{ o with
Configuration = DotNet.BuildConfiguration.Release
OutputPath = Some(Environment.environVarOrFail("BUILD_ARTIFACTSTAGINGDIRECTORY") + "/server")
}
DotNet.publish publishParams "./src/web/web.csproj"
)
let isEmptyDirectory x = (System.IO.Directory.GetFiles x).Length = 0 && (System.IO.Directory.GetDirectories x).Length = 0
let publishArtifacts path artifactName =
if not (isEmptyDirectory path) then
Trace.publish (ImportData.BuildArtifactWithName artifactName) path
Target.create "DeployArtifacts" (fun _ ->
Trace.log "Uploading server artifacts"
if not BuildServer.isLocalBuild then
publishArtifacts (Environment.environVarOrFail("BUILD_ARTIFACTSTAGINGDIRECTORY") + "/server") "server"
else
Trace.log "Skipping uploading server artifacts, because the build is not executed on the build server"
()
)
Target.create "Test.Frontend" (fun _ ->
let npmPath = ProcessUtils.tryFindFileOnPath "npm"
if npmPath.IsNone then failwith "npm could not be found"
let npmTestCodeCoverage =
["run"; "test-codecoverage"]
|> CreateProcess.fromRawCommand npmPath.Value
|> CreateProcess.withWorkingDirectory "./src/web"
|> Proc.run
if npmTestCodeCoverage.ExitCode <> 0 then failwith "There was at least one failing test, or the tests couldn't be executed at all"
)
Target.create "All" ignore
"Install.Prerequisites"
==> "Build.Frontend"
==> "Test.Frontend"
==> "Build.Backend"
==> "Publish"
==> "DeployArtifacts"
==> "All"
Target.runOrDefault "All"