-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
180 lines (149 loc) · 4.62 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
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
#r @"packages/build/FAKE/tools/FakeLib.dll"
open Fake
open Fake.Git
open Fake.AssemblyInfoFile
open Fake.ReleaseNotesHelper
open Fake.UserInputHelper
open System
let release = LoadReleaseNotes "RELEASE_NOTES.md"
let srcGlob = "src/**/*.fsproj"
let testsGlob = "tests/**/*.fsproj"
Target "Clean" (fun _ ->
["bin"; "temp" ;"dist"]
|> CleanDirs
!! srcGlob
++ testsGlob
|> Seq.collect(fun p ->
["bin";"obj"]
|> Seq.map(fun sp ->
IO.Path.GetDirectoryName p @@ sp)
)
|> CleanDirs
)
Target "DotnetRestore" (fun _ ->
!! srcGlob
++ testsGlob
|> Seq.iter (fun proj ->
DotNetCli.Restore (fun c ->
{ c with
Project = proj
//This makes sure that Proj2 references the correct version of Proj1
AdditionalArgs = [sprintf "/p:PackageVersion=%s" release.NugetVersion]
})
))
Target "DotnetBuild" (fun _ ->
!! srcGlob
|> Seq.iter (fun proj ->
DotNetCli.Build (fun c ->
{ c with
Project = proj
//This makes sure that Proj2 references the correct version of Proj1
AdditionalArgs = [sprintf "/p:PackageVersion=%s" release.NugetVersion]
})
))
let invoke f = f ()
let invokeAsync f = async { f () }
type TargetFramework =
| Full of string
| Core of string
let (|StartsWith|_|) prefix (s: string) =
if s.StartsWith prefix then Some () else None
let getTargetFramework tf =
match tf with
| StartsWith "net4" -> Full tf
| StartsWith "netcoreapp" -> Core tf
| _ -> failwithf "Unknown TargetFramework %s" tf
let getTargetFrameworksFromProjectFile (projFile : string)=
let doc = Xml.XmlDocument()
doc.Load(projFile)
doc.GetElementsByTagName("TargetFrameworks").[0].InnerText.Split(';')
|> Seq.map getTargetFramework
|> Seq.toList
let selectRunnerForFramework tf =
let runMono = sprintf "mono -f %s -c Release"
let runCore = sprintf "run -f %s -c Release"
match tf with
| Full t when isMono-> runMono t
| Full t -> runCore t
| Core t -> runCore t
let runTests modifyArgs =
!! testsGlob
|> Seq.map(fun proj -> proj, getTargetFrameworksFromProjectFile proj)
|> Seq.collect(fun (proj, targetFrameworks) ->
targetFrameworks
|> Seq.map selectRunnerForFramework
|> Seq.map(fun args -> fun () ->
DotNetCli.RunCommand (fun c ->
{ c with
WorkingDir = IO.Path.GetDirectoryName proj
}) (modifyArgs args))
)
Target "DotnetTest" (fun _ ->
runTests id
|> Seq.iter (invoke)
)
let execProcAndReturnMessages filename args =
let args' = args |> String.concat " "
ProcessHelper.ExecProcessAndReturnMessages
(fun psi ->
psi.FileName <- filename
psi.Arguments <-args'
) (TimeSpan.FromMinutes(1.))
let pkill args =
execProcAndReturnMessages "pkill" args
let killParentsAndChildren processId=
pkill [sprintf "-P %d" processId]
Target "WatchTests" (fun _ ->
runTests (sprintf "watch %s")
|> Seq.iter (invokeAsync >> Async.Catch >> Async.Ignore >> Async.Start)
printfn "Press enter to stop..."
Console.ReadLine() |> ignore
if isWindows |> not then
startedProcesses
|> Seq.iter(fst >> killParentsAndChildren >> ignore )
else
//Hope windows handles this right?
()
)
Target "DotnetPack" (fun _ ->
!! srcGlob
|> Seq.iter (fun proj ->
DotNetCli.Pack (fun c ->
{ c with
Project = proj
Configuration = "Release"
OutputPath = IO.Directory.GetCurrentDirectory() @@ "dist"
AdditionalArgs =
[
sprintf "/p:PackageVersion=%s" release.NugetVersion
sprintf "/p:PackageReleaseNotes=\"%s\"" (String.Join("\n",release.Notes))
]
})
)
)
Target "Publish" (fun _ ->
Paket.Push(fun c ->
{ c with
PublishUrl = "https://www.nuget.org"
WorkingDir = "dist"
}
)
)
Target "Release" (fun _ ->
if Git.Information.getBranchName "" <> "master" then failwith "Not on master"
StageAll ""
Git.Commit.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.push ""
Branches.tag "" release.NugetVersion
Branches.pushTag "" "origin" release.NugetVersion
)
"Clean"
==> "DotnetRestore"
==> "DotnetBuild"
==> "DotnetTest"
==> "DotnetPack"
==> "Publish"
==> "Release"
"DotnetRestore"
==> "WatchTests"
RunTargetOrDefault "DotnetPack"