-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.fsx
194 lines (159 loc) · 5.58 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
#r "paket: groupref netcorebuild //"
#load ".fake/build.fsx/intellisense.fsx"
#if !FAKE
#r "Facades/netstandard"
#r "netstandard"
#endif
open System
open System.IO
open System.Text.RegularExpressions
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.IO.FileSystemOperators
open Fake.JavaScript
module Util =
let visitFile (visitor: string->string) (fileName : string) =
File.ReadAllLines(fileName)
|> Array.map (visitor)
|> fun lines -> File.WriteAllLines(fileName, lines)
let replaceLines (replacer: string->Match->string option) (reg: Regex) (fileName: string) =
fileName |> visitFile (fun line ->
let m = reg.Match(line)
if not m.Success
then line
else
match replacer line m with
| None -> line
| Some newLine -> newLine)
let jsLibsOutput = "src" </> "WebApp" </> "public" </> "libs"
let testsDist = "tests" </> "dist"
Target.create "Clean" (fun _ ->
!! "src/**/bin"
++ "src/**/obj"
++ "tests/**/bin"
++ "tests/**/obj"
++ "src/WebApp/output"
++ jsLibsOutput
++ testsDist
|> Shell.cleanDirs
)
Target.create "YarnInstall" (fun _ ->
Yarn.install id
)
Target.create "Restore" (fun _ ->
!! "src/**/*.fsproj"
++ "tests/Tests.fsproj"
|> Seq.iter (fun file -> DotNet.restore id file)
)
Target.create "Build" (fun _ ->
Yarn.exec "webpack --config src/WebApp/webpack.config.js --mode production" id
)
Target.create "Watch" (fun _ ->
Yarn.exec "webpack-dev-server --config src/WebApp/webpack.config.js --watch" id
)
Target.create "CopyQUnitModules" (fun _ ->
Directory.create testsDist
Shell.cp_r ("./node_modules" </> "qunit" </> "qunit") (testsDist </> "qunit")
)
Target.create "RunLiveTests" (fun _ ->
Yarn.exec "webpack-dev-server --config tests/webpack.config.js --watch" id
)
Target.create "BuildTests" (fun _ ->
Yarn.exec "webpack --config tests/webpack.config.js --mode production" id
)
Target.create "RunTests" (fun _ ->
Yarn.exec "run qunit tests/dist/bundle.js" id
)
Target.create "Release" (fun _ ->
Yarn.exec "run gh-pages --dist src/WebApp/output" id
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
let needsPublishing (versionRegex: Regex) (releaseNotes: ReleaseNotes.ReleaseNotes) projFile =
printfn "Project: %s" projFile
if releaseNotes.NugetVersion.ToUpper().EndsWith("NEXT")
then
printfn "Version in Release Notes ends with NEXT, don't publish yet."
false
else
File.ReadLines(projFile)
|> Seq.tryPick (fun line ->
let m = versionRegex.Match(line)
if m.Success then Some m else None)
|> function
| None -> failwith "Couldn't find version in project file"
| Some m ->
let sameVersion = m.Groups.[1].Value = releaseNotes.NugetVersion
if sameVersion then
printfn "Already version %s, no need to publish." releaseNotes.NugetVersion
not sameVersion
let toPackageReleaseNotes (notes: string list) =
"* " + String.Join("\n * ", notes)
|> (fun txt -> txt.Replace("\"", "\\\""))
let pushNuget (releaseNotes: ReleaseNotes.ReleaseNotes) (projFile: string) =
let versionRegex = Regex("<Version>(.*?)</Version>", RegexOptions.IgnoreCase)
if needsPublishing versionRegex releaseNotes projFile then
let projDir = Path.GetDirectoryName(projFile)
let nugetKey =
match Environment.environVarOrNone "NUGET_KEY" with
| Some nugetKey -> nugetKey
| None -> failwith "The Nuget API key must be set in a NUGET_KEY environmental variable"
(versionRegex, projFile)
||> Util.replaceLines (fun line _ ->
versionRegex.Replace(line, "<Version>"+releaseNotes.NugetVersion+"</Version>") |> Some)
let result =
DotNet.exec
(DotNet.Options.withWorkingDirectory projDir)
"pack"
(sprintf "-c Release /p:PackageReleaseNotes=\"%s\"" (toPackageReleaseNotes releaseNotes.Notes))
if not result.OK then failwithf "dotnet fable failed with code %i" result.ExitCode
Directory.GetFiles(projDir </> "bin" </> "Release", "*.nupkg")
|> Array.find (fun nupkg -> nupkg.Contains(releaseNotes.NugetVersion))
|> (fun nupkg ->
let wd = Path.getDirectory nupkg
let args =
sprintf "push %s -s nuget.org -k %s" nupkg nugetKey
let res = DotNet.exec (DotNet.Options.withWorkingDirectory wd) "nuget" args
if not res.OK then
failwithf "paket failed to start: %A" res
)
Target.create "PublishNugets" (fun _ ->
!! "./src/HtmlConverter/Fable.HtmlConverter.fsproj"
|> Seq.iter(fun s ->
let projFile = s
let projDir = IO.Path.GetDirectoryName(projFile)
let release = projDir </> "RELEASE_NOTES.md" |> ReleaseNotes.load
pushNuget release projFile
)
)
Target.create "Setup" ignore
Target.create "CI" ignore
"Clean"
==> "YarnInstall"
==> "Restore"
==> "Setup"
"Setup"
==> "CopyQUnitModules"
==> "RunLiveTests"
"Setup"
==> "Watch"
// A "Build" include a "Setup"
"Setup"
==> "Build"
"Setup"
==> "BuildTests"
==> "RunTests"
// A "Release" include a "RunTests"
"RunTests"
==> "PublishNugets"
==> "Release"
"Build"
==> "Release"
"CI"
<== [ "Build"
"RunTests"]
// Start build
Target.runOrDefault "Build"