-
Notifications
You must be signed in to change notification settings - Fork 58
/
build.fsx
239 lines (184 loc) · 7.41 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
#r "nuget: Fake.Core.Target"
#r "nuget: Fake.Core.Process"
#r "nuget: Fake.Core.ReleaseNotes"
#r "nuget: Fake.IO.FileSystem"
#r "nuget: Fake.DotNet.Cli"
#r "nuget: Fake.DotNet.MSBuild"
#r "nuget: Fake.DotNet.AssemblyInfoFile"
#r "nuget: Fake.DotNet.Paket"
#r "nuget: Fake.DotNet.FSFormatting"
#r "nuget: Fake.Tools.Git"
#r "nuget: Fake.Api.GitHub"
// Boilerplate - https://github.com/fsprojects/FAKE/issues/2719#issuecomment-1470687052
System.Environment.GetCommandLineArgs()
|> Array.skip 2 // skip fsi.exe; build.fsx
|> Array.toList
|> Fake.Core.Context.FakeExecutionContext.Create false __SOURCE_FILE__
|> Fake.Core.Context.RuntimeContext.Fake
|> Fake.Core.Context.setExecutionContext
open Fake
open Fake.Core.TargetOperators
open Fake.Core
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.DotNet
open Fake.Tools
open System.IO
Target.initEnvironment()
// --------------------------------------------------------------------------------------
// Longer description of the project
// (used as a description for NuGet package; line breaks are automatically cleaned up)
let description = "F# Type Provider for Swagger & Open API"
// Git configuration (used for publishing documentation in gh-pages branch)
// The profile where the project is posted
let gitOwner = "fsprojects"
// The name of the project on GitHub
let gitName = "SwaggerProvider"
// --------------------------------------------------------------------------------------
// Read additional information from the release notes document
let release = ReleaseNotes.load "docs/RELEASE_NOTES.md"
// Generate assembly info files with the right version & up-to-date information
Target.create "AssemblyInfo" (fun _ ->
let fileName = "src/Common/AssemblyInfo.fs"
AssemblyInfoFile.createFSharp
fileName
[ AssemblyInfo.Title gitName
AssemblyInfo.Product gitName
AssemblyInfo.Description description
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion ])
// --------------------------------------------------------------------------------------
// Clean build results
Target.create "Clean" (fun _ ->
!! "**/**/bin/" |> Shell.cleanDirs
//!! "**/**/obj/" |> Shell.cleanDirs
Shell.cleanDirs [ "bin"; "temp" ]
try
File.Delete("swaggerlog")
with _ ->
())
Target.create "CleanDocs" (fun _ -> Shell.cleanDirs [ "docs/output" ])
// --------------------------------------------------------------------------------------
// Build library & test project
let dotnet cmd args =
let result = DotNet.exec id cmd args
if not result.OK then
failwithf "Failed: %A" result.Errors
Target.create "Build" (fun _ -> dotnet "build" "SwaggerProvider.sln -c Release")
let webApiInputStream = StreamRef.Empty
Target.create "StartServer" (fun _ ->
Target.activateFinal "StopServer"
CreateProcess.fromRawCommandLine "dotnet" "tests/Swashbuckle.WebApi.Server/bin/Release/net8.0/Swashbuckle.WebApi.Server.dll"
|> CreateProcess.withStandardInput(CreatePipe webApiInputStream)
|> Proc.start
|> ignore
// We need delay to guarantee that server is bootstrapped
System.Threading.Thread.Sleep(2000))
Target.createFinal "StopServer" (fun _ ->
// Write something to input stream to stop server
try
webApiInputStream.Value.Write([| 0uy |], 0, 1)
with e ->
printfn "%s" e.Message
//Process.killAllByName "dotnet"
)
Target.create "BuildTests" (fun _ -> dotnet "build" "SwaggerProvider.TestsAndDocs.sln -c Release")
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner
let runTests assembly =
dotnet "test" $"{assembly} -c Release --no-build"
Target.create "RunUnitTests" (fun _ -> runTests "tests/SwaggerProvider.Tests/bin/Release/net8.0/SwaggerProvider.Tests.dll")
Target.create "RunIntegrationTests" (fun _ -> runTests "tests/SwaggerProvider.ProviderTests/bin/Release/net8.0/SwaggerProvider.ProviderTests.dll")
Target.create "RunTests" ignore
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target.create "NuGet" (fun _ ->
Paket.pack(fun p ->
{ p with
ToolType = ToolType.CreateLocalTool()
OutputPath = "bin"
Version = release.NugetVersion
ReleaseNotes = String.toLines release.Notes }))
Target.create "PublishNuget" (fun _ ->
Paket.push(fun p ->
{ p with
ToolType = ToolType.CreateLocalTool()
WorkingDir = "bin" }))
// --------------------------------------------------------------------------------------
// Generate the documentation
Target.create "BrowseDocs" (fun _ ->
CreateProcess.fromRawCommandLine "dotnet" "serve -o -d ./docs"
|> (Proc.run >> ignore))
// --------------------------------------------------------------------------------------
// Release Scripts
Target.create "Release" (fun _ ->
// not fully converted from FAKE 4
// StageAll ""
// Git.Commit.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
// Branches.push ""
// Branches.tag "" release.NugetVersion
// Branches.pushTag "" "origin" release.NugetVersion
// // release on github
// createClient (getBuildParamOrDefault "github-user" "") (getBuildParamOrDefault "github-pw" "")
// |> createDraft gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
// // TODO: |> uploadFile "PATH_TO_FILE"
// |> releaseDraft
// |> Async.RunSynchronously
// using simplified FAKE 5 release for now
Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Bump version to %s" release.NugetVersion)
Git.Branches.push ""
Git.Branches.tag "" release.NugetVersion
Git.Branches.pushTag "" "origin" release.NugetVersion)
Target.create "BuildPackage" ignore
let sourceFiles =
!! "**/*.fs" ++ "**/*.fsx"
-- "packages/**/*.*"
-- "paket-files/**/*.*"
-- ".fake/**/*.*"
-- "**/obj/**/*.*"
-- "**/AssemblyInfo.fs"
Target.create "Format" (fun _ ->
let result =
sourceFiles
|> Seq.map(sprintf "\"%s\"")
|> String.concat " "
|> DotNet.exec id "fantomas"
if not result.OK then
printfn "Errors while formatting all files: %A" result.Messages)
Target.create "CheckFormat" (fun _ ->
let result =
sourceFiles
|> Seq.map(sprintf "\"%s\"")
|> String.concat " "
|> sprintf "%s --check"
|> DotNet.exec id "fantomas"
if result.ExitCode = 0 then
Trace.log "No files need formatting"
elif result.ExitCode = 99 then
failwith "Some files need formatting, run `dotnet fake build -t Format` to format them"
else
Trace.logf "Errors while formatting: %A" result.Errors
failwith "Unknown errors while formatting")
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target.create "All" ignore
// https://github.com/fsharp/FAKE/issues/2283
let skipTests = Environment.environVarAsBoolOrDefault "skipTests" false
"Clean"
==> "AssemblyInfo"
==> "CheckFormat"
==> "Build"
==> "RunUnitTests"
==> "StartServer"
==> "BuildTests"
=?> ("RunIntegrationTests", not skipTests)
==> "StopServer"
==> "RunTests"
==> "NuGet"
==> "All"
==> "BuildPackage"
==> "PublishNuget"
==> "Release"
Target.runOrDefault "BuildPackage"