-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.fsx
261 lines (226 loc) · 8.78 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "paket: groupref build //"
#load "./.fake/build.fsx/intellisense.fsx"
#r "netstandard"
open Fake.Core
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.IO.FileSystemOperators
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
let testProjName = "Qsp.FSharp.Core.Tests"
let testProjPath = "tests" </> "Qsp.FSharp.Core.Tests" </> sprintf "%s.fsproj" testProjName
let serverProjName = "Qsp.FSharp.LanguageServer"
let serverProjDir = "src" </> "Qsp.FSharp.LanguageServer"
let serverProjPath = serverProjDir </> sprintf "%s.fsproj" serverProjName
let parserProjName = "Qsp.FSharp.Core"
let parserProjDir = "src" </> "Qsp.FSharp.Core"
let parserProjPath = parserProjDir </> sprintf "%s.fsproj" parserProjName
let utilityProjDir = "src" </> "Qsp.FSharp.Cli"
let utilityProjName = "Qsp.FSharp.Cli"
let utilityProjPath = utilityProjDir </> sprintf "%s.fsproj" utilityProjName
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
open Fake.DotNet
let dotnet cmd workingDir =
let result = DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir
module XmlText =
let escape rawText =
let doc = new System.Xml.XmlDocument()
let node = doc.CreateElement("root")
node.InnerText <- rawText
node.InnerXml
let targetFrameworks = ["net461"; "netcoreapp3.1"]
// --------------------------------------------------------------------------------------
// Targets
// --------------------------------------------------------------------------------------
let commonBuildArgs =
[
"-c Release"
]
|> String.concat " "
let dotnetBuild =
let commonBuildArgs =
[
yield commonBuildArgs
if not Environment.isWindows then
yield "--framework netcoreapp3.1"
]
|> String.concat " "
dotnet (sprintf "build %s" commonBuildArgs)
let dotnetRun framework args =
dotnet (sprintf "run --framework %s -- %s" framework args)
Target.create "CoreMeta" (fun _ ->
let release = ReleaseNotes.load (parserProjDir </> "RELEASE_NOTES.md")
[
"<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"
"<ItemGroup>"
" <PackageReference Include=\"Microsoft.SourceLink.GitHub\" Version=\"1.0.0\" PrivateAssets=\"All\"/>"
"</ItemGroup>"
"<PropertyGroup>"
" <EmbedUntrackedSources>true</EmbedUntrackedSources>"
" <PackageProjectUrl>https://github.com/gretmn102/FParserQSP/tree/master/src/Qsp.FSharp.Core</PackageProjectUrl>"
" <PackageLicenseExpression>MIT</PackageLicenseExpression>"
" <RepositoryUrl>https://github.com/gretmn102/FParserQSP.git</RepositoryUrl>"
sprintf " <PackageReleaseNotes>%s</PackageReleaseNotes>"
(String.concat "\n" release.Notes |> XmlText.escape)
" <PackageTags>fsharp;qsp;parser</PackageTags>"
" <Authors>gretmn102</Authors>"
sprintf " <Version>%s</Version>" release.SemVer.AsString
"</PropertyGroup>"
"</Project>"
]
|> File.write false (parserProjDir </> "Directory.Build.props")
)
Target.create "CorePack" (fun _ ->
let commonBuildArgs =
[
yield commonBuildArgs
if not Environment.isWindows then
yield "-p:TargetFrameworks=netstandard2.0"
]
|> String.concat " "
dotnet (sprintf "pack %s" commonBuildArgs) parserProjDir
)
Target.create "CorePushToGitlab" (fun _ ->
let release = ReleaseNotes.load (parserProjDir </> "RELEASE_NOTES.md")
let deployDir = parserProjDir </> "bin" </> "Release"
let packPath =
sprintf "Qsp.FSharp.Core.%s.nupkg" release.SemVer.AsString
deployDir
|> dotnet (sprintf "nuget push -s %s %s" "gitlab" packPath)
)
Target.create "LanguageServerMeta" (fun _ ->
let release = ReleaseNotes.load (serverProjDir </> "RELEASE_NOTES.md")
[
"<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"
"<ItemGroup>"
" <PackageReference Include=\"Microsoft.SourceLink.GitHub\" Version=\"1.0.0\" PrivateAssets=\"All\"/>"
"</ItemGroup>"
"<PropertyGroup>"
" <PackageId>Qsp.FSharp.LanguageServer</PackageId>"
" <EmbedUntrackedSources>true</EmbedUntrackedSources>"
" <PackageProjectUrl>https://github.com/gretmn102/FParserQSP/tree/master/src/Qsp.FSharp.LanguageServer</PackageProjectUrl>"
" <PackageLicenseExpression>MIT</PackageLicenseExpression>"
" <RepositoryUrl>https://github.com/gretmn102/FParserQSP.git</RepositoryUrl>"
sprintf " <PackageReleaseNotes>%s</PackageReleaseNotes>"
(String.concat "\n" release.Notes |> XmlText.escape)
" <PackageTags>fsharp;qsp;lsp</PackageTags>"
" <Authors>gretmn102</Authors>"
sprintf " <Version>%s</Version>" release.SemVer.AsString
"</PropertyGroup>"
"</Project>"
]
|> File.write false (serverProjDir </> "Directory.Build.props")
)
Target.create "LanguageServerPack" (fun _ ->
let commonBuildArgs =
[
yield commonBuildArgs
// If you use netcoreapp3.1, then Core will also try
// to compile to that framework, which will cause errors
if not Environment.isWindows then
yield "-p:TargetFrameworks=netstandard2.0"
]
|> String.concat " "
dotnet (sprintf "pack %s" commonBuildArgs) serverProjDir
)
Target.create "LanguageServerPushToGitlab" (fun _ ->
let release = ReleaseNotes.load (serverProjDir </> "RELEASE_NOTES.md")
let deployDir = serverProjDir </> "bin" </> "Release"
let packPath =
sprintf "Qsp.FSharp.LanguageServer.%s.nupkg" release.SemVer.AsString
deployDir
|> dotnet (sprintf "nuget push -s %s %s" "gitlab" packPath)
)
Target.create "BuildServer" (fun _ ->
serverProjPath
|> Fake.IO.Path.getDirectory
|> dotnetBuild
)
Target.create "BuildTest" (fun _ ->
testProjPath
|> Fake.IO.Path.getDirectory
|> dotnetBuild
)
Target.create "CliBuild" (fun _ ->
utilityProjPath
|> Fake.IO.Path.getDirectory
|> dotnetBuild
)
[<RequireQualifiedAccess>]
type TestOnMocksType =
| True
| Interactive
module TestOnMocksType =
let toString typ =
match typ with
| TestOnMocksType.True -> "true"
| TestOnMocksType.Interactive -> "interactive"
let testsRun isTestMain (isTestMocks: TestOnMocksType option) =
let args =
[
if isTestMain then
"--test-main"
match isTestMocks with
| None -> ""
| Some typ ->
let typ = TestOnMocksType.toString typ
sprintf "--test-mocks %s" typ
]
|> String.concat " "
Path.getDirectory testProjPath
|> dotnetRun
"netcoreapp3.1"
args
Target.create "TestsRun" (fun _ ->
testsRun true None
)
Target.create "TestsRunMock" (fun _ ->
testsRun false (Some TestOnMocksType.True)
)
Target.create "TestsRunFull" (fun _ ->
testsRun true (Some TestOnMocksType.True)
)
Target.create "TestsRunInteractiveFull" (fun _ ->
testsRun true (Some TestOnMocksType.Interactive)
)
Target.create "TrimTrailingWhitespace" (fun _ ->
// по-хорошему, нужно использовать .gitignore, но и так пока сойдет
let files =
!! "**/*.fs"
++ "**/*.fsx"
++ "**/*.fsproj"
++ "**/*.cs"
++ "**/*.csproj"
-- "**/obj/**"
-- "**/paket-files/**"
-- "**/packages/**"
files
|> Seq.iter (fun path ->
System.IO.File.ReadAllLines path
|> Array.map (fun x -> x.TrimEnd())
|> fun content -> System.IO.File.WriteAllLines(path, content)
)
)
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
open Fake.Core.TargetOperators
Target.create "Default" ignore
"CoreMeta"
==> "CorePack"
==> "CorePushToGitlab"
"LanguageServerMeta"
==> "LanguageServerPack"
==> "LanguageServerPushToGitlab"
"BuildServer"
==> "Default"
// "BuildServer" <=> "BuildTest"
// Copy3rd запускает и BuildServer, и BuildTest. Шо делать, чтобы он отдельно запускал?
Target.runOrDefault "Default"