-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathTargets.fs
127 lines (88 loc) · 5.57 KB
/
Targets.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
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
namespace Scripts
open System
open System.IO
open Bullseye
open ProcNet
open Fake.Core
open Fake.IO.Globbing.Operators
module Main =
let private target name action = Targets.Target(name, Action(action))
let private skip name = printfn "SKIPPED target '%s' evaluated not to run" name |> ignore
let private conditional name optional action = target name (if optional then action else (fun _ -> skip name))
let private command name dependencies action = Targets.Target(name, dependencies, Action(action))
let private conditionalCommand name dependencies optional action = command name dependencies (if optional then action else (fun _ -> skip name))
/// <summary>Sets command line environments indicating we are building from the command line</summary>
let setCommandLineEnvVars () =
Environment.setEnvironVar"NEST_COMMAND_LINE_BUILD" "1"
let sourceDir = Paths.TestsSource("Tests.Configuration");
let defaultYaml = Path.Combine(sourceDir, "tests.default.yaml");
let userYaml = Path.Combine(sourceDir, "tests.yaml");
let e f = File.Exists f;
match ((e userYaml), (e defaultYaml)) with
| (true, _) -> Environment.setEnvironVar "NEST_YAML_FILE" (Path.GetFullPath(userYaml))
| (_, true) -> Environment.setEnvironVar "NEST_YAML_FILE" (Path.GetFullPath(defaultYaml))
| _ -> failwithf "Expected to find a tests.default.yaml or tests.yaml in %s" sourceDir
let [<EntryPoint>] main args =
setCommandLineEnvVars ()
let parsed = Commandline.parse (args |> Array.toList)
let buildVersions = Versioning.BuildVersioning parsed
let artifactsVersion = Versioning.ArtifactsVersion buildVersions
Versioning.Validate parsed.Target buildVersions
let isCanary = parsed.Target = "canary";
Tests.SetTestEnvironmentVariables parsed
let testChain = ["clean"; "version"; "restore"; "full-build"; ]
let buildChain = ["test"; "inherit-doc"; ]
let releaseChain =
[
"build";
"nuget-pack";
//"nuget-pack-versioned";
// "validate-artifacts";
"generate-release-notes"
]
let canaryChain = [ "version"; "release"; "test-nuget-package";]
// the following are expected to be called as targets directly
conditional "clean" (parsed.ReleaseBuild || parsed.Target = "clean") <| fun _ -> Build.Clean parsed
target "version" <| fun _ -> printfn "Artifacts Version: %O" artifactsVersion
target "restore" Build.Restore
target "full-build" <| fun _ -> Build.Compile parsed artifactsVersion
//TEST
conditionalCommand "test" testChain (not parsed.SkipTests && not isCanary) <| fun _ -> Tests.RunUnitTests parsed
target "inherit-doc" <| InheritDoc.PatchInheritDocs
conditionalCommand "documentation" testChain (parsed.GenDocs) <| fun _ -> Documentation.Generate parsed
//BUILD
command "build" buildChain <| fun _ -> printfn "STARTING BUILD"
target "nuget-pack" <| fun _ -> Build.Pack artifactsVersion
conditional "nuget-pack-versioned" (isCanary) <| fun _ -> Build.VersionedPack artifactsVersion
conditional "generate-release-notes" (not isCanary && not parsed.SkipReleaseNotes) <| fun _ ->
ReleaseNotes.GenerateNotes buildVersions
target "validate-artifacts" <| fun _ -> Versioning.ValidateArtifacts artifactsVersion
//RELEASE
command "release" releaseChain <| fun _ ->
let outputPath = match parsed.CommandArguments with | Commandline.SetVersion c -> c.OutputLocation | _ -> None
match outputPath with
| None ->
printfn "Finished Release Build %O, artifacts available at: %s" artifactsVersion Paths.BuildOutput
| Some path ->
Fake.IO.Shell.cp_r Paths.BuildOutput path
let zipName = sprintf "elasticsearch-net-%O.zip" artifactsVersion.Full
let outputZip = Path.Combine(path, zipName)
let files = !! (sprintf "%s/*.*" path) -- outputZip
Fake.IO.Zip.createZip "." outputZip "elastic/elasticsearch-net artifact" 9 true files
printfn "Finished Release Build %O, output copied to: %s" artifactsVersion path
conditional "test-nuget-package" (not parsed.SkipTests) <| fun _ -> Tests.RunReleaseUnitTests artifactsVersion parsed
//CANARY
command "canary" canaryChain <| fun _ -> printfn "Finished Release Build %O" artifactsVersion
// ADDITIONAL COMMANDS
command "cluster" [ "restore"; "full-build" ] <| fun _ ->
ReposTooling.LaunchCluster parsed
command "codegen" [ ] <| fun _ -> ReposTooling.GenerateApi parsed
target "set-version" <| fun _ -> Versioning.WriteVersion buildVersions
command "rest-spec-tests" [ ] <| fun _ -> ()
command "benchmark" [ "clean"; "full-build"; ] <| fun _ -> Benchmarker.Run parsed
command "integrate" [ "clean"; "restore"; "full-build";] <| fun _ -> Tests.RunIntegrationTests parsed
Targets.RunTargetsAndExit([parsed.Target], (fun e -> e.GetType() = typeof<ProcExecException>), ":")
0