forked from fsprojects/FSharp.Data.GraphQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.fsx
More file actions
227 lines (175 loc) · 7.64 KB
/
build.fsx
File metadata and controls
227 lines (175 loc) · 7.64 KB
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 "nuget: Fake.Api.GitHub"
#r "nuget: Fake.Core.ReleaseNotes"
#r "nuget: Fake.Core.Target"
#r "nuget: Fake.Core.UserInput"
#r "nuget: Fake.DotNet.AssemblyInfoFile"
#r "nuget: Fake.DotNet.Cli"
#r "nuget: Fake.DotNet.Fsc"
#r "nuget: Fake.DotNet.MSBuild"
#r "nuget: Fake.IO.FileSystem"
#r "nuget: Fake.Tools.Git"
#r "nuget: System.Reactive"
#r "nuget: Octokit"
open System
open System.IO
open System.Collections.Generic
open System.Threading
open Fake
open Fake.Tools.Git
open Fake.DotNet
open Fake.DotNet.NuGet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open Fake.Tools
open Fake.Core
open Fake.Api
open Octokit
// https://github.com/fsprojects/FAKE/issues/2517
// Regular header and `#load ".fake/build.fsx/intellisense.fsx"`
#if !FAKE
let execContext =
System.Environment.GetCommandLineArgs ()
|> Array.skip 2 // skip fsi.exe; build.fsx
|> Array.toList
|> Fake.Core.Context.FakeExecutionContext.Create false __SOURCE_FILE__
execContext
|> Fake.Core.Context.RuntimeContext.Fake
|> Fake.Core.Context.setExecutionContext
#endif
// --------------------------------------------------------------------------------------
// Information about the project are used
// --------------------------------------------------------------------------------------
// - by the generated NuGet package
// - to run tests and to publish documentation on GitHub gh-pages
// - for documentation, you also need to edit info in "docs/tools/generate.fsx"
let [<Literal>] DotNetMoniker = "net6.0"
let project = "FSharp.Data.GraphQL"
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let projectRepo = "https://github.com/fsprojects/FSharp.Data.GraphQL.git"
// --------------------------------------------------------------------------------------
// Clean build results
Target.create "Clean" <| fun _ -> Shell.cleanDirs [ "bin"; "temp" ]
Target.create "CleanDocs" <| fun _ -> Shell.cleanDirs [ "docs/output" ]
// --------------------------------------------------------------------------------------
// Build library & test project
Target.create "Restore" <| fun _ ->
!! "src/**/*.??proj"
-- "src/**/*.shproj"
|> Seq.iter (fun pattern -> DotNet.restore id pattern)
Target.create "Build" <| fun _ ->
"FSharp.Data.GraphQL.sln"
|> DotNet.build (fun o ->
{ o with
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams = { o.MSBuildParams with DisableInternalBinLog = true } })
let startGraphQLServer (project : string) (streamRef : DataRef<Stream>) =
DotNet.build
(fun options ->
{ options with
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true } })
project
let projectName = Path.GetFileNameWithoutExtension (project)
let projectPath = Path.GetDirectoryName (project)
let serverExe = projectPath </> "bin" </> "Release" </> DotNetMoniker </> (projectName + ".dll")
CreateProcess.fromRawCommandLine "dotnet" serverExe
|> CreateProcess.withStandardInput (CreatePipe streamRef) |> Proc.start |> ignore
System.Threading.Thread.Sleep (2000)
let runTests (project : string) =
DotNet.build
(fun options ->
{ options with
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true } })
project
DotNet.test
(fun options ->
{ options with
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams = { options.MSBuildParams with DisableInternalBinLog = true }
Common = { options.Common with CustomParams = Some "--no-build -v=normal" } })
project
let starWarsServerStream = StreamRef.Empty
Target.create "StartStarWarsServer" <| fun _ ->
Target.activateFinal "StopStarWarsServer"
let project = "samples" </> "star-wars-api" </> "FSharp.Data.GraphQL.Samples.StarWarsApi.fsproj"
startGraphQLServer project starWarsServerStream
Target.createFinal "StopStarWarsServer" <| fun _ ->
try starWarsServerStream.Value.Write ([| 0uy |], 0, 1)
with e -> printfn "%s" e.Message
let integrationServerStream = StreamRef.Empty
Target.create "StartIntegrationServer" <| fun _ ->
Target.activateFinal "StopIntegrationServer"
let project = "tests" </> "FSharp.Data.GraphQL.IntegrationTests.Server" </> "FSharp.Data.GraphQL.IntegrationTests.Server.fsproj"
startGraphQLServer project integrationServerStream
Target.createFinal "StopIntegrationServer" <| fun _ ->
try integrationServerStream.Value.Write ([| 0uy |], 0, 1)
with e -> printfn "%s" e.Message
Target.create "RunUnitTests" <| fun _ -> runTests "tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj"
Target.create "RunIntegrationTests" <| fun _ -> runTests "tests/FSharp.Data.GraphQL.IntegrationTests/FSharp.Data.GraphQL.IntegrationTests.fsproj"
let prepareDocGen () =
Shell.rm "docs/release-notes.md"
Shell.cp "RELEASE_NOTES.md" "docs/RELEASE_NOTES.md"
Shell.rename "docs/release-notes.md" "docs/RELEASE_NOTES.md"
Shell.rm "docs/license.md"
Shell.cp "LICENSE.txt" "docs/LICENSE.txt"
Shell.rename "docs/license.md" "docs/LICENSE.txt"
Shell.cleanDir ".fsdocs"
Target.create "GenerateDocs" <| fun _ ->
prepareDocGen ()
DotNet.exec id "fsdocs" "build --clean" |> ignore
Target.create "GenerateDocsWatch" <| fun _ ->
prepareDocGen ()
DotNet.exec id "fsdocs" "watch --clean" |> ignore
System.Console.ReadKey () |> ignore
Target.create "ReleaseDocs" <| fun _ ->
Git.Repository.clone "" projectRepo "temp/gh-pages"
Git.Branches.checkoutBranch "temp/gh-pages" "gh-pages"
Shell.copyRecursive "output" "temp/gh-pages" true |> printfn "%A"
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" "add ." |> printfn "%s"
let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" release.NugetVersion
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd |> printfn "%s"
Git.Branches.push "temp/gh-pages"
let pack id =
Shell.cleanDir <| sprintf "nuget/%s.%s" project id
id |> NuGet.NuGetPack (fun p ->
{ p with
Version = release.NugetVersion
OutputPath = sprintf "nuget/%s.%s" project id
//IncludeReferencedProjects = false
})
let publishPackage id =
pack id
NuGet.NuGetPublish <| fun p -> { p with WorkingDir = sprintf "nuget/%s.%s" project id }
Target.create "PublishServer" <| fun _ -> publishPackage "Server"
Target.create "PublishClient" <| fun _ -> publishPackage "Client"
Target.create "PublishMiddleware" <| fun _ -> publishPackage "Server.Middleware"
Target.create "PackShared" <| fun _ -> pack "Shared"
Target.create "PackServer" <| fun _ -> pack "Server"
Target.create "PackClient" <| fun _ -> pack "Client"
Target.create "PackMiddleware" <| fun _ -> pack "Server.Middleware"
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build -t <Target>' to override
Target.create "All" ignore
Target.create "PackAll" ignore
"Clean"
==> "Restore"
==> "Build"
==> "RunUnitTests"
==> "StartStarWarsServer"
==> "StartIntegrationServer"
==> "RunIntegrationTests"
==> "All"
=?> ("GenerateDocs", Environment.environVar "APPVEYOR" = "True")
"CleanDocs" ==> "GenerateDocs"
"PackShared"
==> "PackServer"
==> "PackClient"
==> "PackMiddleware"
==> "PackAll"
Target.runOrDefaultWithArguments "All"
#if !FAKE
execContext.Context.Clear ()
#endif