This repository has been archived by the owner on Apr 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.fsx
256 lines (215 loc) · 8.01 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
#r "paket: groupref Build //"
#load "./.fake/build.fsx/intellisense.fsx"
#load "./paket-files/build/fsharp/FAKE/modules/Octokit/Octokit.fsx"
open Fake.Core
open Fake.Core.TargetOperators
open Fake.Documentation
open Fake.DotNet
open Fake.DotNet.Testing
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Tools
open Octokit
open System
Target.initEnvironment()
let [<Literal>] ProjectName = "XRoadProvider"
let [<Literal>] Summary = "Type providers for generating types and service interfaces for XRoad producers."
let [<Literal>] Description = "Type providers for generating types and service interfaces for XRoad producers."
let [<Literal>] Tags = "F# fsharp x-road xroad typeproviders x-tee xtee"
let [<Literal>] GitOwner = "janno-p"
let authors = [ "Janno Põldma" ]
let gitHome = "https://github.com/" + GitOwner
let gitName = ProjectName
let enableNet40 = Environment.environVarAsBool "DisableNet40" |> not
let projects = [
yield ProjectName
if enableNet40 then
yield sprintf "%s.net40" ProjectName
]
let testProjects = [
yield sprintf "%s.Tests" ProjectName
if enableNet40 then
yield sprintf "%s.Tests.net40" ProjectName
]
let projectPath = __SOURCE_DIRECTORY__ </> "src"
let testProjectPath = __SOURCE_DIRECTORY__ </> "tests"
let testAssemblies = testProjectPath </> "**" </> "bin" </> "Debug" </> "**" </> "*Tests*.exe"
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let docfxToolPath = __SOURCE_DIRECTORY__ </> "paket-files" </> "build" </> "github.com" </> "docfx.exe"
let tempDocsDir = "temp" </> "gh-pages"
Target.description "Generate assembly info files with the right version & up-to-date information"
Target.create "AssemblyInfo" (fun _ ->
let getAssemblyInfoAttributes projectName =
[ AssemblyInfo.Title (projectName)
AssemblyInfo.Product ProjectName
AssemblyInfo.Description Summary
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion
AssemblyInfo.InformationalVersion release.NugetVersion ]
let getProjectDetails projectPath =
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
( projectPath,
projectName,
System.IO.Path.GetDirectoryName(projectPath),
(getAssemblyInfoAttributes projectName)
)
!! "src/**/*.fsproj"
|> Seq.map getProjectDetails
|> Seq.iter (fun (_, _, folderName, attributes) -> AssemblyInfoFile.createFSharp (folderName </> "AssemblyInfo.fs") attributes)
)
Target.description "Copies binaries from default VS location to exepcted bin folder, but keeps a subdirectory structure for each project in the src folder to support multiple project outputs"
Target.create "CopyBinaries" (fun _ ->
!! "src/**/*.fsproj"
|> Seq.map (fun f -> ((System.IO.Path.GetDirectoryName f) </> "bin" </> "Release", "bin"))
|> Seq.iter (fun (fromDir, toDir) -> Shell.copyDir toDir fromDir (fun _ -> true))
)
Target.description "Clean build results"
Target.create "Clean" (fun _ ->
Shell.cleanDirs ["bin"; "temp"]
)
Target.description "Build test project"
Target.create "BuildDebug" (fun _ ->
testProjects
|> Seq.map ((</>) testProjectPath)
|> Seq.iter (fun path ->
DotNet.restore id path
DotNet.build (fun p -> { p with Configuration = DotNet.BuildConfiguration.Debug }) path
)
)
Target.description "Build library for release"
Target.create "Build" (fun _ ->
projects
|> Seq.map ((</>) projectPath)
|> Seq.iter (fun path ->
DotNet.restore id path
DotNet.build
(fun p ->
{ p with
Common = { p.Common with CustomParams = Some(sprintf "/p:Version=%s" release.NugetVersion) }
Configuration = DotNet.BuildConfiguration.Release })
path
)
)
Target.description "Run the unit tests using test runner"
Target.create "RunTests" (fun _ ->
if Environment.isUnix then
!! testAssemblies
|> Seq.iter (fun testExe ->
let result =
Command.RawCommand(testExe, Arguments.Empty)
|> CreateProcess.fromCommand
|> CreateProcess.withFramework
|> CreateProcess.withTimeout TimeSpan.MaxValue
|> Proc.run
if result.ExitCode <> 0 then failwithf "Running test assembly '%s' failed." testExe
)
else
Expecto.run id (!! testAssemblies)
)
Target.description "Build a NuGet package"
Target.create "NuGet" (fun _ ->
Shell.copyDir ("temp" </> "lib") "bin" FileFilter.allFiles
NuGet.NuGet.NuGet (fun p ->
{ p with
Authors = authors
Project = ProjectName
Summary = Summary
Description = Description
Version = release.NugetVersion
ReleaseNotes = String.Join(Environment.NewLine, release.Notes)
Tags = Tags
WorkingDir = "temp"
OutputPath = "bin"
Dependencies = [] })
(ProjectName + ".nuspec")
)
Target.create "PublishNuget" (fun _ ->
let apiKey = Environment.environVarOrFail "NUGET_KEY"
Paket.push(fun p ->
{ p with
ApiKey = apiKey
ToolPath = "paket"
WorkingDir = "bin" })
)
Target.create "GenerateHelp" (fun _ ->
Shell.rm "docs/articles/release-notes.md"
Shell.copyFile "docs/articles/" "RELEASE_NOTES.md"
Shell.rename "docs/articles/release-notes.md" "docs/articles/RELEASE_NOTES.md"
Shell.rm "docs/articles/license.md"
Shell.copyFile "docs/articles/" "LICENSE.md"
Shell.rename "docs/articles/license.md" "docs/articles/LICENSE.md"
)
Target.create "CleanDocs" (fun _ ->
Shell.cleanDirs [ tempDocsDir ]
)
Target.create "Serve" (fun _ ->
DocFx.exec
(fun p ->
{ p with
DocFxPath = docfxToolPath
Timeout = TimeSpan.MaxValue })
"serve"
tempDocsDir
)
Target.description "Generate the documentation"
Target.create "GenerateDocs" (fun _ ->
DocFx.exec
(fun p -> { p with DocFxPath = docfxToolPath })
(__SOURCE_DIRECTORY__ </> "docs" </> "docfx.json")
""
)
Target.create "ReleaseDocs" (fun _ ->
Shell.cleanDirs [ tempDocsDir ]
Git.Repository.cloneSingleBranch "" (gitHome + "/" + gitName + ".git") "gh-pages" tempDocsDir
DocFx.exec
(fun p -> { p with DocFxPath = docfxToolPath })
(__SOURCE_DIRECTORY__ </> "docs" </> "docfx.json")
""
Git.Staging.stageAll tempDocsDir
Git.Commit.exec tempDocsDir (sprintf "Update generated documentation for version %s" release.NugetVersion)
Git.Branches.push tempDocsDir
)
Target.create "Release" (fun _ ->
let user = Environment.environVarOrFail "github-user"
let pw = Environment.environVarOrFail "github-pw"
let remote =
Git.CommandHelper.getGitResult "" "remote -v"
|> Seq.filter (fun (s: string) -> s.EndsWith("(push)"))
|> Seq.tryFind (fun (s: string) -> s.Contains(GitOwner + "/" + gitName))
|> function None -> gitHome + "/" + gitName | Some (s: string) -> s.Split().[0]
Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Bump version to %s" release.NugetVersion)
Git.Branches.pushBranch "" remote (Git.Information.getBranchName "")
Git.Branches.tag "" release.NugetVersion
Git.Branches.pushTag "" remote release.NugetVersion
createClient user pw
|> createDraft GitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
|> releaseDraft
|> Async.RunSynchronously
)
Target.create "BuildPackage" ignore
Target.create "All" ignore
"Clean"
==> "AssemblyInfo"
==> "BuildDebug"
==> "RunTests"
==> "Build"
==> "CopyBinaries"
=?> ("GenerateDocs", Environment.environVarAsBool "SkipDocs" |> not)
==> "All"
=?> ("ReleaseDocs", BuildServer.isLocalBuild)
"All"
==> "NuGet"
==> "BuildPackage"
"CleanDocs"
==> "GenerateHelp"
==> "GenerateDocs"
"GenerateHelp"
==> "Serve"
"ReleaseDocs"
==> "Release"
"BuildPackage"
==> "PublishNuget"
==> "Release"
Target.runOrDefault "All"