forked from ionide/FsAutoComplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
206 lines (168 loc) · 5.63 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
// include Fake lib
#r @"packages/FAKE/tools/FakeLib.dll"
open Fake
open Fake.Git
open Fake.ReleaseNotesHelper
open Fake.UserInputHelper
open Fake.ZipHelper
open Fake.AssemblyInfoFile
open Fake.Testing
open System
open System.IO
open System.Text.RegularExpressions
let githubOrg = "fsharp"
let project = "FsAutoComplete"
let summary = "A command line tool for interfacing with FSharp.Compiler.Service over a pipe."
// Read additional information from the release notes document
let releaseNotesData =
File.ReadAllLines "RELEASE_NOTES.md"
|> parseAllReleaseNotes
let release = List.head releaseNotesData
let buildDir = "src" </> project </> "bin" </> "Debug"
let buildReleaseDir = "src" </> project </> "bin" </> "Release"
let integrationTestDir = "test" </> "FsAutoComplete.IntegrationTests"
let releaseArchive = "fsautocomplete.zip"
let suaveSummary = "A Suave web server for interfacing with FSharp.Compiler.Service over a HTTP."
let suaveProject = "FsAutoComplete.Suave"
let suaveBuildDebugDir = "src" </> suaveProject </> "bin" </> "Debug"
let suaveBuildReleaseDir = "src" </> suaveProject </> "bin" </> "Release"
let suaveReleaseArchive = "fsautocomplete.suave.zip"
// Pattern specifying assemblies to be tested using NUnit
let testAssemblies = "**/bin/*/*Tests*.dll"
Target "BuildDebug" (fun _ ->
MSBuildDebug "" "Build" ["./FsAutoComplete.sln"]
|> Log "Build-Output: "
)
Target "BuildRelease" (fun _ ->
MSBuildRelease "" "Build" ["./FsAutoComplete.sln"]
|> Log "Build-Output: "
)
let integrationTests =
!! (integrationTestDir + "/**/*Runner.fsx")
let runIntegrationTest (fn: string) : bool =
let dir = Path.GetDirectoryName fn
tracefn "Running FSIHelper '%s', '%s', '%s'" FSIHelper.fsiPath dir fn
let b, msgs = FSIHelper.executeFSI dir fn []
if not b then
for msg in msgs do
traceError msg.Message
b
Target "IntegrationTest" (fun _ ->
let runOk =
[ for i in integrationTests do
yield runIntegrationTest i ]
|> Seq.forall id
if not runOk then
failwith "Integration tests did not run successfully"
else
let ok, out, err =
Git.CommandHelper.runGitCommand
"."
("-c core.fileMode=false diff --exit-code " + integrationTestDir)
if not ok then
trace (toLines out)
failwithf "Integration tests failed:\n%s" err
)
Target "UnitTest" (fun _ ->
!! testAssemblies
|> NUnit3 (fun p ->
{ p with
ShadowCopy = true
TimeOut = TimeSpan.FromMinutes 20.
OutputDir = "TestResults.xml" })
)
Target "AssemblyInfo" (fun _ ->
let fileName = "src" </> project </> "AssemblyInfo.fs"
CreateFSharpAssemblyInfo fileName
[ Attribute.Title project
Attribute.Product project
Attribute.Description summary
Attribute.Version release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion ]
)
Target "SuaveAssemblyInfo" (fun _ ->
let fileName = "src" </> suaveProject </> "AssemblyInfo.fs"
CreateFSharpAssemblyInfo fileName
[ Attribute.Title suaveProject
Attribute.Product suaveProject
Attribute.Description suaveSummary
Attribute.Version release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion ]
)
Target "ReleaseArchive" (fun _ ->
Zip buildReleaseDir
releaseArchive
( !! (buildReleaseDir + "/*.dll")
++ (buildReleaseDir + "/*.exe")
++ (buildReleaseDir + "/*.exe.config"))
)
Target "SuaveReleaseArchive" (fun _ ->
Zip suaveBuildReleaseDir
suaveReleaseArchive
( !! (suaveBuildReleaseDir + "/*.dll")
++ (suaveBuildReleaseDir + "/*.exe")
++ (suaveBuildReleaseDir + "/*.exe.config"))
)
Target "LocalRelease" (fun _ ->
ensureDirectory "bin/release"
CopyFiles "bin/release"(
!! (buildReleaseDir + "/*.dll")
++ (buildReleaseDir + "/*.exe")
++ (buildReleaseDir + "/*.exe.config")
++ (suaveBuildReleaseDir + "/*.dll")
++ (suaveBuildReleaseDir + "/*.exe")
++ (suaveBuildReleaseDir + "/*.exe.config")
)
)
#load "lib/Octokit.fsx"
open Octokit
Target "Release" (fun _ ->
let user = getUserInput "Username: "
let pw = getUserPassword "Password: "
let remote =
Git.CommandHelper.getGitResult "" "remote -v"
|> Seq.filter (fun (s: string) -> s.EndsWith("(push)"))
|> Seq.tryFind (fun (s: string) -> s.Contains(githubOrg + "/" + project))
|> function None -> "https://github.com/" + githubOrg + "/" + project
| Some (s: string) -> s.Split().[0]
StageAll ""
Git.Commit.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.pushBranch "" remote (Information.getBranchName "")
Branches.tag "" release.NugetVersion
Branches.pushTag "" remote release.NugetVersion
// release on github
createClient user pw
|> createDraft githubOrg project release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
|> uploadFile releaseArchive
|> uploadFile suaveReleaseArchive
|> releaseDraft
|> Async.RunSynchronously
)
Target "Clean" (fun _ ->
CleanDirs [ buildDir; buildReleaseDir; suaveBuildDebugDir; suaveBuildReleaseDir ]
DeleteFiles [releaseArchive; suaveReleaseArchive ]
)
Target "Build" id
Target "Test" id
Target "All" id
"BuildDebug"
==> "Build"
==> "IntegrationTest"
"BuildDebug"
==> "Build"
==> "UnitTest"
"IntegrationTest" ==> "Test"
"UnitTest" ==> "Test"
"BuildDebug" ==> "All"
"Test" ==> "All"
"BuildRelease"
==> "LocalRelease"
"AssemblyInfo"
==> "BuildRelease"
==> "ReleaseArchive"
==> "Release"
"SuaveAssemblyInfo"
==> "BuildRelease"
==> "SuaveReleaseArchive"
==> "Release"
RunTargetOrDefault "BuildDebug"