-
Notifications
You must be signed in to change notification settings - Fork 74
/
build.fsx
196 lines (157 loc) · 6.46 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "nuget: System.Reactive ,5.0.0"
#r "nuget: Fake.Core.UserInput ,5.23.1"
#r "nuget: Fake.Core.ReleaseNotes ,5.23.1"
#r "nuget: Fake.Core.Target ,5.23.1"
#r "nuget: Fake.IO.FileSystem ,5.23.1"
#r "nuget: Fake.DotNet.Cli ,5.23.1"
#r "nuget: Fake.Tools.Git ,5.23.1"
#r "nuget: Fake.Api.Github ,5.23.1"
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
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
// --------------------------------------------------------------------------------------
// Information about the project to be used at NuGet and in AssemblyInfo files
// --------------------------------------------------------------------------------------
let gitOwner = "fsprojects"
let gitName = "Argu"
let gitHome = "https://github.com/" + gitOwner
let configuration = Environment.environVarOrDefault "Configuration" "Release"
let artifacts = __SOURCE_DIRECTORY__ @@ "artifacts"
// --------------------------------------------------------------------------------------
// The rest of the code is standard F# build script
// --------------------------------------------------------------------------------------
// Read additional information from the release notes document
let release = ReleaseNotes.load "RELEASE_NOTES.md"
// --------------------------------------------------------------------------------------
// Clean build results & restore NuGet packages
Target.create "Clean" (fun _ ->
Shell.cleanDirs [ artifacts ]
)
//
// --------------------------------------------------------------------------------------
// 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
Target.create "RunTests" (fun _ ->
DotNet.test (fun c ->
{ c with
Configuration = DotNet.BuildConfiguration.fromString configuration
NoBuild = true
Blame = 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 artifacts
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams =
{ pack.MSBuildParams with
Properties =
[("Version", release.NugetVersion)
("PackageReleaseNotes", releaseNotes)] }
}) __SOURCE_DIRECTORY__
)
Target.create "NuGet.ValidateSourceLink" (fun _ ->
for nupkg in !! (artifacts @@ "*.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 !! (artifacts + "/*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"
)
// Doc generation
Target.create "GenerateDocs" (fun _ ->
Shell.cleanDir ".fsdocs"
DotNet.exec id "fsdocs" "build --clean --strict --properties Configuration=Release" |> ignore
)
// 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 "Prepare" ignore
Target.create "PrepareRelease" ignore
Target.create "Default" ignore
Target.create "Bundle" ignore
Target.create "Release" ignore
"Root"
==> "Clean"
==> "Prepare"
==> "Build"
==> "RunTests"
==> "Default"
"Default"
==> "PrepareRelease"
==> "NuGet.Pack"
// ==> "NuGet.ValidateSourceLink"
==> "GenerateDocs"
==> "Bundle"
"Bundle"
==> "ReleaseGitHub"
==> "NuGet.Push"
==> "Release"
Target.runOrDefault "Default"