-
Notifications
You must be signed in to change notification settings - Fork 36
/
build.fsx
198 lines (158 loc) · 6.9 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "nuget: System.Reactive ,5.0.0"
#r "nuget: Fake.Core.UserInput ,5.20.4"
#r "nuget: Fake.Core.ReleaseNotes ,5.20.4"
#r "nuget: Fake.Core.Target ,5.20.4"
#r "nuget: Fake.IO.FileSystem ,5.20.4"
#r "nuget: Fake.DotNet.Cli ,5.20.4"
#r "nuget: Fake.Tools.Git ,5.20.4"
#r "nuget: Fake.Api.Github ,5.20.4"
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Tools
open Fake.Api
open System
#if !FAKE
Environment.GetCommandLineArgs()
|> Array.skip 2
|> Array.toList
|> Fake.Core.Context.FakeExecutionContext.Create false __SOURCE_FILE__
|> Fake.Core.Context.RuntimeContext.Fake
|> Fake.Core.Context.setExecutionContext
#endif
// --------------------------------------------------------------------------------------
// START TODO: Provide project-specific details below
// --------------------------------------------------------------------------------------
// Folder to deposit deploy artifacts
let artifactsDir = __SOURCE_DIRECTORY__ @@ "artifacts"
// Git configuration (used for publishing documentation in gh-pages branch)
// The profile where the project is posted
let gitOwner = "eiriktsarpalis"
let gitHome = "https://github.com/" + gitOwner
let gitName = "TypeShape"
let configuration = Environment.environVarOrDefault "configuration" "Release"
let noEmitConfiguration = "Release-NoEmit"
// --------------------------------------------------------------------------------------
// END TODO: The rest of the file includes standard build steps
// --------------------------------------------------------------------------------------
// Read additional information from the release notes document
let release = ReleaseNotes.load "RELEASE_NOTES.md"
// --------------------------------------------------------------------------------------
// Clean build results
Target.create "Clean" (fun _ ->
Shell.cleanDirs [ "bin" ; artifactsDir ; "temp" ; "docs/output" ]
)
// --------------------------------------------------------------------------------------
// Build library & test project
let Build configuration =
DotNet.build(fun c ->
{ c with
Configuration = DotNet.BuildConfiguration.fromString configuration
MSBuildParams =
{ c.MSBuildParams with
Properties = [("Version", release.NugetVersion)]
DisableInternalBinLog = true }
}) __SOURCE_DIRECTORY__
Target.create "Build" (fun _ -> Build configuration)
Target.create "Build.NoEmit" (fun _ -> Build noEmitConfiguration)
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner & kill test runner when complete
let Test configuration =
DotNet.test (fun c ->
{ c with
Configuration = DotNet.BuildConfiguration.fromString configuration
NoBuild = true
Blame = true
MSBuildParams =
{ c.MSBuildParams with
Properties = [("ParallelizeAssemblies", "true"); ("ParallelizeTestCollections", "true")]
DisableInternalBinLog = true }
}) __SOURCE_DIRECTORY__
Target.create "RunTests" (fun _ -> Test configuration)
Target.create "RunTests.NoEmit" (fun _ -> Test noEmitConfiguration)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target.create "NuGet.Bundle" (fun _ ->
let releaseNotes = String.toLines release.Notes |> System.Net.WebUtility.HtmlEncode
DotNet.pack (fun pack ->
{ pack with
OutputPath = Some artifactsDir
Configuration = DotNet.BuildConfiguration.fromString configuration
MSBuildParams =
{ pack.MSBuildParams with
Properties =
[("Version", release.NugetVersion)
("PackageReleaseNotes", releaseNotes)]
DisableInternalBinLog = true }
}) __SOURCE_DIRECTORY__
)
Target.create "NuGet.ValidateSourceLink" (fun _ ->
for nupkg in !! (artifactsDir @@ "*.nupkg") do
let p = DotNet.exec id "sourcelink" (sprintf "test %s" nupkg)
if not p.OK then failwithf "failed to validate sourcelink for %s" nupkg
)
Target.create "NuGet.Push" (fun _ ->
let source = "https://api.nuget.org/v3/index.json"
let key = Environment.GetEnvironmentVariable "NUGET_KEY"
for artifact in !! (artifactsDir + "/*nupkg") do
let result = DotNet.exec id "nuget" (sprintf "push -s %s -k %s %s" source key artifact)
if not result.OK then failwith "failed to push packages"
)
// --------------------------------------------------------------------------------------
// Release Scripts
Target.create "ReleaseGithub" (fun _ ->
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]
//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
let client =
match Environment.GetEnvironmentVariable "GITHUB_TOKEN" with
| null ->
let user =
match Environment.environVarOrDefault "github-user" "" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserInput "Username: "
let pw =
match Environment.environVarOrDefault "github-pw" "" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserPassword "Password: "
GitHub.createClient user pw
| token -> GitHub.createClientWithToken token
client
|> GitHub.draftNewRelease gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
|> GitHub.publishDraft
|> Async.RunSynchronously
)
Target.create "BuildPackage" ignore
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target.create "Default" ignore
Target.create "Bundle" ignore
Target.create "Release" ignore
"Clean"
==> "Build"
==> "RunTests"
==> "Build.NoEmit"
==> "RunTests.NoEmit"
==> "Default"
"Default"
==> "NuGet.Bundle"
//==> "NuGet.ValidateSourceLink"
==> "Bundle"
"Bundle"
==> "NuGet.Push"
==> "ReleaseGithub"
==> "Release"
Target.runOrDefault "Default"