-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.fsx
153 lines (121 loc) · 4.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
// --------------------------------------------------------------------------------------
// 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 System
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let gitRepoUrl = "https://github.com/fsprojects/FSharp.Quotations.Evaluator"
let artifacts = __SOURCE_DIRECTORY__ @@ "artifacts"
// Read additional information from the release notes document
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let configuration = Environment.environVarOrDefault "Configuration" "Release"
// --------------------------------------------------------------------------------------
// Clean build results
Target.create "Clean" (fun _ ->
Shell.cleanDirs [artifacts; "docs/output"]
)
// --------------------------------------------------------------------------------------
// Clean build results
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
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 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"
)
// --------------------------------------------------------------------------------------
// Generate the documentation
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"
)
// --------------------------------------------------------------------------------------
// Release Scripts
Target.create "ReleaseDocs" (fun _ ->
let tempDocsDir = "temp/gh-pages"
let outputDocsDir = "docs/output"
Directory.ensure outputDocsDir
Shell.cleanDir tempDocsDir
Git.Repository.cloneSingleBranch "" (gitRepoUrl + ".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
)
Target.create "ReleaseTag" (fun _ ->
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
)
// --------------------------------------------------------------------------------------
// Run all Target.creates by default. Invoke 'build <Target.create>' to override
Target.create "Default" ignore
Target.create "Bundle" ignore
Target.create "Release" ignore
"Clean"
==> "Build"
==> "RunTests"
==> "Default"
"Default"
==> "GenerateDocs"
==> "NuGet.Pack"
==> "NuGet.ValidateSourceLink"
==> "Bundle"
"Bundle"
==> "ReleaseDocs"
==> "NuGet.Push"
==> "ReleaseTag"
==> "Release"
Target.runOrDefault "Default"