This repository has been archived by the owner on May 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.fsx
174 lines (158 loc) · 6.42 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
#r "paket: groupref netcorebuild //"
#load ".fake/build.fsx/intellisense.fsx"
#if !FAKE
#r "Facades/netstandard"
#r "netstandard"
#endif
#nowarn "52"
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.Tools.Git
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 inline yarnWorkDir (ws : string) (yarnParams : Yarn.YarnParams) =
{ yarnParams with WorkingDirectory = ws }
Target.create "Clean"
(fun _ ->
!!"docs/**/bin" ++ "docs/**/obj" ++ "src/**/bin" ++ "src/**/obj"
++ "templates/**/bin" ++ "templates/**/obj" |> Seq.iter Shell.cleanDir)
Target.create "Install" (fun _ ->
!!"src/**/*.fsproj"
|> Seq.iter (fun s ->
let dir = IO.Path.GetDirectoryName s
DotNet.restore id dir))
Target.create "Build" (fun _ ->
!!"src/**/*.fsproj"
|> Seq.iter (fun s ->
let dir = IO.Path.GetDirectoryName s
DotNet.build id dir))
Target.create "QuickBuild" (fun _ ->
!!"src/**/*.fsproj"
|> Seq.iter (fun s ->
let dir = IO.Path.GetDirectoryName s
DotNet.build id dir))
Target.create "YarnInstall" (fun _ -> Yarn.install id)
// --------------------------------------------------------------------------------------
// Docs targets
Target.create "InstallDocs" (fun _ ->
!!"docs/**.fsproj"
|> Seq.iter (fun s ->
let dir = IO.Path.GetDirectoryName s
DotNet.restore id dir))
let watchDocs _ =
Yarn.exec "webpack-dev-server --config docs/webpack.config.js"
(yarnWorkDir "docs")
Target.create "WatchDocs" watchDocs
Target.create "QuickWatchDocs" watchDocs
Target.create "BuildDocs"
(fun _ ->
Yarn.exec "webpack --config docs/webpack.config.js" (yarnWorkDir "docs"))
// --------------------------------------------------------------------------------------
// Build a NuGet package
let needsPublishing (versionRegex : Regex)
(releaseNotes : ReleaseNotes.ReleaseNotes) 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 pack failed with code %i" result.ExitCode
Directory.GetFiles(projDir </> "bin" </> "Release", "*.nupkg")
|> Array.find (fun nupkg -> nupkg.Contains(releaseNotes.NugetVersion))
|> (fun nupkg ->
Paket.push (fun p ->
{ p with ApiKey = nugetKey
WorkingDir = Path.getDirectory nupkg }))
Target.create "PublishNugets" (fun _ ->
!!"src/Fable.BluePrint.Core/Fable.BluePrint.Core.fsproj"
++ "src/Fable.BluePrint.DataTime/Fable.BluePrint.DataTime.fsproj"
++ "src/Fable.BluePrint.Select/Fable.BluePrint.Select.fsproj"
++ "src/Fable.BluePrint.Table/Fable.BluePrint.Table.fsproj"
++ "src/Fable.BluePrint.TimeZone/Fable.BluePrint.TimeZone.fsproj"
++ "src/Fable.BluePrint.Icons/Fable.BluePrint.Icons.fsproj"
|> Seq.iter (fun s ->
printfn "%s" s
let projFile = s
let projDir = IO.Path.GetDirectoryName(projFile)
let release = projDir </> "RELEASE_NOTES.md" |> ReleaseNotes.load
pushNuget release projFile))
// Where to push generated documentation
let githubLink = "git@github.com:kunjee17/GreenPrint.git"
let publishBranch = "gh-pages"
let fableRoot = __SOURCE_DIRECTORY__
let temp = fableRoot </> "temp"
let docsOuput = fableRoot </> "docs" </> "public"
// --------------------------------------------------------------------------------------
// Release Scripts
Target.create "PublishDocs" (fun _ ->
Shell.cleanDir temp
Repository.cloneSingleBranch "" githubLink publishBranch temp
Shell.copyRecursive docsOuput temp true |> Trace.tracefn "%A"
Staging.stageAll temp
Commit.exec temp
(sprintf "Update site (%s)" (DateTime.Now.ToShortDateString()))
Branches.push temp)
// Build order
"Clean" ==> "Install" ==> "Build" ==> "PublishNugets"
"Build" ==> "YarnInstall" ==> "InstallDocs" ==> "WatchDocs"
"Build" ==> "YarnInstall" ==> "InstallDocs" ==> "BuildDocs" ==> "PublishDocs"
// start build
Target.runOrDefault "Build"