-
Notifications
You must be signed in to change notification settings - Fork 46
/
build.fsx
188 lines (149 loc) · 6.2 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "paket: groupref build //"
#load "./.fake/build.fsx/intellisense.fsx"
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
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let gitOwner = "nessos"
let gitHome = "https://github.com/" + gitOwner
let gitName = "Streams"
let artifactsDir = "artifacts"
let configuration = Environment.environVarOrDefault "Configuration" "Release"
// --------------------------------------------------------------------------------------
// Read release notes & version info from RELEASE_NOTES.md
let release = ReleaseNotes.load "RELEASE_NOTES.md"
// --------------------------------------------------------------------------------------
// Clean build results & restore NuGet packages
Target.create "Clean" (fun _ ->
Shell.cleanDirs [ artifactsDir ]
)
// --------------------------------------------------------------------------------------
// Build library & test project
Target.create "Build" (fun _ ->
DotNet.build (fun c ->
{ c with
Configuration = DotNet.BuildConfiguration.fromString configuration
MSBuildParams =
{ c.MSBuildParams with
Properties = [("Version", release.NugetVersion)] }
}) __SOURCE_DIRECTORY__
)
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner & kill test runner when complete
Target.create "RunTests" (fun _ ->
DotNet.test (fun c ->
{ c with
Configuration = DotNet.BuildConfiguration.fromString configuration
NoBuild = true
Blame = true
MSBuildParams =
{ c.MSBuildParams with
Properties = [("ParallelizeAssemblies", "true"); ("ParallelizeTestCollections", "true")] }
}) __SOURCE_DIRECTORY__
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target.create "NuGet.Pack" (fun _ ->
let releaseNotes = String.toLines release.Notes |> System.Net.WebUtility.HtmlEncode
DotNet.pack (fun pack ->
{ pack with
OutputPath = Some artifactsDir
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams =
{ pack.MSBuildParams with
Properties =
[("Version", release.NugetVersion)
("PackageReleaseNotes", releaseNotes)] }
}) __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 apikey = Environment.environVarOrDefault "NUGET_KEY" ""
for artifact in !! (artifactsDir + "/*nupkg") do
let result = DotNet.exec id "nuget" (sprintf "push -s %s -k %s %s" source apikey artifact)
if not result.OK then failwith "failed to push packages"
)
// --------------------------------------------------------------------------------------
// Document generation
Target.create "GenerateDocs" (fun _ ->
let res = DotNet.exec id "fsi" "--define:RELEASE docs/tools/generate.fsx"
if not res.OK then failwith "failed to generate docs"
)
Target.create "ReleaseDocs" (fun _ ->
let tempDocsDir = "temp/gh-pages"
let outputDocsDir = "docs/output"
Directory.ensure outputDocsDir
Shell.cleanDir tempDocsDir
Git.Repository.cloneSingleBranch "" (gitHome + "/" + gitName + ".git") "gh-pages" tempDocsDir
Shell.copyRecursive outputDocsDir tempDocsDir true |> Trace.tracefn "%A"
Git.Staging.stageAll tempDocsDir
Git.Commit.exec tempDocsDir (sprintf "Update generated documentation for version %s" release.NugetVersion)
Git.Branches.push tempDocsDir
)
// Github Releases
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.getUserInput "Password: "
GitHub.createClient user pw
| token -> GitHub.createClientWithToken token
// release on github
client
|> GitHub.draftNewRelease gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
|> GitHub.publishDraft
|> Async.RunSynchronously
)
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target.create "Root" ignore
Target.create "Default" ignore
Target.create "Bundle" ignore
Target.create "Release" ignore
"Root"
==> "Clean"
==> "Build"
==> "RunTests"
==> "Default"
"Build"
==> "NuGet.Pack"
//==> "NuGet.ValidateSourceLink"
==> "GenerateDocs"
==> "Bundle"
"Bundle"
==> "ReleaseDocs"
==> "ReleaseGitHub"
==> "NuGet.Push"
==> "Release"
Target.runOrDefault "Default"