This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
227 lines (187 loc) · 6.53 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#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 productName = "FSharpPlus.Suave"
let sln = "FSharpPlus.Suave.sln"
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 _ ->
DotNetCli.Restore (fun c ->
{ c with
Project = sln
//This makes sure that Proj2 references the correct version of Proj1
AdditionalArgs = [sprintf "/p:PackageVersion=%s" release.NugetVersion]
}))
Target "DotnetBuild" (fun _ ->
DotNetCli.Build (fun c ->
{ c with
Project = sln
//This makes sure that Proj2 references the correct version of Proj1
AdditionalArgs =
[
sprintf "/p:PackageVersion=%s" release.NugetVersion
"--no-restore"
]
}))
let invoke f = f ()
let invokeAsync f = async { f () }
type TargetFramework =
| Full of string
| Core of string
let (|StartsWith|_|) (prefix: string) (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 --loggerlevel Warn"
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 (sprintf "%s --no-build")
|> 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 Ctrl+C (or Ctrl+Break) to stop..."
let cancelEvent = Console.CancelKeyPress |> Async.AwaitEvent |> Async.RunSynchronously
cancelEvent.Cancel <- true
if isWindows |> not then
startedProcesses
|> Seq.iter(fst >> killParentsAndChildren >> ignore )
else
//Hope windows handles this right?
()
)
Target "AssemblyInfo" (fun _ ->
let releaseChannel =
match release.SemVer.PreRelease with
| Some pr -> pr.Name
| _ -> "release"
let getAssemblyInfoAttributes projectName =
[ Attribute.Title (projectName)
Attribute.Product productName
// Attribute.Description summary
Attribute.Version release.AssemblyVersion
Attribute.Metadata("ReleaseDate", release.Date.Value.ToString("o"))
Attribute.FileVersion release.AssemblyVersion
Attribute.InformationalVersion release.AssemblyVersion
Attribute.Metadata("ReleaseChannel", releaseChannel)
Attribute.Metadata("GitHash", Information.getCurrentSHA1(null))
]
let getProjectDetails projectPath =
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
( projectPath,
projectName,
System.IO.Path.GetDirectoryName(projectPath),
(getAssemblyInfoAttributes projectName)
)
!! "src/**/*.??proj"
++ "tests/**/*.??proj"
|> Seq.map getProjectDetails
|> Seq.iter (fun (projFileName, projectName, folderName, attributes) ->
match projFileName with
| Fsproj -> CreateFSharpAssemblyInfo (folderName @@ "AssemblyInfo.fs") attributes
| Csproj -> CreateCSharpAssemblyInfo ((folderName @@ "Properties") @@ "AssemblyInfo.cs") attributes
| Vbproj -> CreateVisualBasicAssemblyInfo ((folderName @@ "My Project") @@ "AssemblyInfo.vb") attributes
| _ -> ()
)
)
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))
"/p:SourceLinkCreate=true"
]
})
)
)
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"
let releaseNotesGitCommitFormat = ("",release.Notes |> Seq.map(sprintf "* %s\n")) |> String.Join
StageAll ""
Git.Commit.Commit "" (sprintf "Bump version to %s \n%s" release.NugetVersion releaseNotesGitCommitFormat)
Branches.push ""
Branches.tag "" release.NugetVersion
Branches.pushTag "" "origin" release.NugetVersion
)
"Clean" ?=> "DotnetRestore"
"Clean" ==> "DotnetPack"
"DotnetRestore"
==> "AssemblyInfo"
==> "DotnetBuild"
==> "DotnetTest"
==> "DotnetPack"
==> "Publish"
==> "Release"
"DotnetRestore"
==> "WatchTests"
RunTargetOrDefault "DotnetPack"