-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathbuild.fsx
118 lines (96 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
106
107
108
109
110
111
112
113
114
115
116
117
118
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
#r "nuget: Fake.Core.Process"
#r "nuget: Fake.IO.FileSystem"
open System
open Fake.Core
open Fake.IO
open Fake.IO.Globbing.Operators
Trace.trace $"Starting script..."
module Properties =
let nugetServer = "https://api.nuget.org/v3/index.json"
let nugetPushEnvVarName = "nuget_fshttp"
[<AutoOpen>]
module Helper =
let private runTarget (x: string * _) =
let name,f = x
Trace.trace $"Running task: {name}"
f ()
let run targets =
for t in targets do
runTarget t
type Args() =
let strippedArgs =
fsi.CommandLineArgs
|> Array.skipWhile (fun x -> x <> __SOURCE_FILE__ )
|> Array.skip 1
|> Array.toList
let taskName,taskArgs =
match strippedArgs with
| taskName :: taskArgs -> taskName, taskArgs
| _ ->
let msg = $"Wrong args. Expected: fsi :: taskName :: taskArgs"
printfn "%s" msg
Environment.Exit -1
failwith msg
do
printfn $"Task name: {taskName}"
printfn $"Task args: {taskArgs}"
member _.IsTask(arg) =
let res = taskName = arg
printfn $"Checking task '{arg}'... {res} (taskName: '{taskName}')"
res
member _.TaskArgs = taskArgs
let args = Args()
type Shell with
static member ExecSuccess (cmd: string, ?arg: string) =
let args = arg |> Option.defaultValue "" |> fun x -> [| x; yield! args.TaskArgs |] |> String.concat " "
printfn $"Executing command '{cmd}' with args: {args}"
let res = Shell.Exec(cmd, ?args = Some args)
if res <> 0 then failwith $"Shell execute was not successful: {res}" else ()
let shallBuild = args.IsTask("build")
let shallTest = args.IsTask("test")
let shallPublish = args.IsTask("publish")
let shallPack = args.IsTask("pack")
let toolRestore = "toolRestore", fun () ->
Shell.ExecSuccess ("dotnet", "tool restore")
let clean = "clean", fun () ->
!! "src/**/bin"
++ "src/**/obj"
++ ".pack"
|> Shell.cleanDirs
let slnPath = "./FsHttp.sln"
let build = "build", fun () ->
Shell.ExecSuccess ("dotnet", $"build {slnPath}")
let CsTestProjectPath = "./src/Test.CSharp/Test.CSharp.csproj"
let FsharpTestProjectPath = "./src/Tests/Tests.fsproj"
let test = "test", fun () ->
Shell.ExecSuccess ("dotnet", $"test {FsharpTestProjectPath}")
Shell.ExecSuccess ("dotnet", $"test {CsTestProjectPath}")
let pack = "pack", fun () ->
!! "src/**/FsHttp*.fsproj"
|> Seq.iter (fun p ->
Trace.trace $"SourceDir is: {__SOURCE_DIRECTORY__}"
Shell.ExecSuccess ("dotnet", sprintf "pack %s -o %s -c Release" p (Path.combine __SOURCE_DIRECTORY__ ".pack"))
)
// TODO: git tag + release
let publish = "publish", fun () ->
let nugetApiKey = Environment.environVar Properties.nugetPushEnvVarName
!! ".pack/*.nupkg"
|> Seq.iter (fun p ->
Shell.ExecSuccess ("dotnet", $"nuget push {p} -k {nugetApiKey} -s {Properties.nugetServer} --skip-duplicate")
)
run [
clean
toolRestore
if shallBuild then
build
if shallTest then
test
if shallPack then
pack
if shallPublish then
build
pack
publish
]
Trace.trace $"Finished script..."