forked from elmish/elmish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
232 lines (188 loc) · 6.85 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// include Fake libs
#r "./packages/build/FAKE/tools/FakeLib.dll"
#r "System.IO.Compression.FileSystem"
open System
open System.IO
open Fake
open Fake.NpmHelper
open Fake.ReleaseNotesHelper
open Fake.Git
// Filesets
let projects =
!! "src/**.fsproj"
let dotnetcliVersion = "2.0.0"
let mutable dotnetExePath = "dotnet"
let runDotnet workingDir =
DotNetCli.RunCommand (fun p -> { p with ToolPath = dotnetExePath
WorkingDir = workingDir } )
Target "InstallDotNetCore" (fun _ ->
dotnetExePath <- DotNetCli.InstallDotNetSDK dotnetcliVersion
)
Target "Clean" (fun _ ->
CleanDir "src/obj"
CleanDir "src/bin"
)
Target "Install" (fun _ ->
projects
|> Seq.iter (fun s ->
let dir = IO.Path.GetDirectoryName s
runDotnet dir "restore"
)
)
Target "Build" (fun _ ->
projects
|> Seq.iter (fun s ->
let dir = IO.Path.GetDirectoryName s
runDotnet dir "build")
)
let release = LoadReleaseNotes "RELEASE_NOTES.md"
Target "Meta" (fun _ ->
[ "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"
"<PropertyGroup>"
"<Description>Elmish core for Fable apps</Description>"
"<PackageProjectUrl>https://github.com/fable-elmish/elmish</PackageProjectUrl>"
"<PackageLicenseUrl>https://raw.githubusercontent.com/fable-elmish/elmish/master/LICENSE.md</PackageLicenseUrl>"
"<PackageIconUrl>https://raw.githubusercontent.com/fable-elmish/elmish/master/docs/files/img/logo.png</PackageIconUrl>"
"<RepositoryUrl>https://github.com/fable-elmish/elmish.git</RepositoryUrl>"
"<PackageTags>fable;elm;fsharp</PackageTags>"
"<Authors>Eugene Tolmachev</Authors>"
sprintf "<Version>%s</Version>" (string release.SemVer)
"</PropertyGroup>"
"</Project>"]
|> WriteToFile false "Meta.props"
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target "Package" (fun _ ->
runDotnet "src" "pack"
)
Target "PublishNuget" (fun _ ->
let args = sprintf "nuget push Fable.Elmish.%s.nupkg -s nuget.org -k %s" (string release.SemVer) (environVar "nugetkey")
runDotnet "src/bin/Debug" args
)
// --------------------------------------------------------------------------------------
// Generate the documentation
let gitName = "elmish"
let gitOwner = "fable-elmish"
let gitHome = sprintf "https://github.com/%s" gitOwner
let fakePath = "packages" </> "build" </> "FAKE" </> "tools" </> "FAKE.exe"
let fakeStartInfo script workingDirectory args fsiargs environmentVars =
(fun (info: System.Diagnostics.ProcessStartInfo) ->
info.FileName <- System.IO.Path.GetFullPath fakePath
info.Arguments <- sprintf "%s --fsiargs -d:FAKE %s \"%s\"" args fsiargs script
info.WorkingDirectory <- workingDirectory
let setVar k v =
info.EnvironmentVariables.[k] <- v
for (k, v) in environmentVars do
setVar k v
setVar "MSBuild" msBuildExe
setVar "GIT" Git.CommandHelper.gitPath
setVar "FSI" fsiPath)
/// Run the given buildscript with FAKE.exe
let executeFAKEWithOutput workingDirectory script fsiargs envArgs =
let exitCode =
ExecProcessWithLambdas
(fakeStartInfo script workingDirectory "" fsiargs envArgs)
TimeSpan.MaxValue false ignore ignore
System.Threading.Thread.Sleep 1000
exitCode
let copyFiles() =
let header =
splitStr "\n" """(*** hide ***)
#I "../../src/bin/Debug/netstandard1.6"
#r "Fable.Core.dll"
#r "Fable.PowerPack.dll"
#r "Fable.Elmish.dll"
(**
*)"""
!!"src/*.fs"
|> Seq.map (fun fn -> ReadFile fn |> Seq.append header, fn)
|> Seq.iter (fun (lines,fn) ->
let fsx = Path.Combine("docs/content",Path.ChangeExtension(fn |> Path.GetFileName, "fsx"))
lines |> WriteFile fsx)
// Documentation
let buildDocumentationTarget fsiargs target =
trace (sprintf "Building documentation (%s), this could take some time, please wait..." target)
let exit = executeFAKEWithOutput "docs/tools" "generate.fsx" fsiargs ["target", target]
if exit <> 0 then
failwith "generating reference documentation failed"
()
let generateHelp fail debug =
copyFiles()
CleanDir "docs/tools/.fake"
let args =
if debug then "--define:HELP"
else "--define:RELEASE --define:HELP"
try
buildDocumentationTarget args "Default"
traceImportant "Help generated"
with
| e when not fail ->
traceImportant "generating help documentation failed"
Target "GenerateDocs" (fun _ ->
generateHelp true false
)
Target "WatchDocs" (fun _ ->
use watcher = !! "docs/content/**/*.*" |> WatchChanges (fun changes ->
generateHelp true true
)
traceImportant "Waiting for help edits. Press any key to stop."
System.Console.ReadKey() |> ignore
watcher.Dispose()
)
// --------------------------------------------------------------------------------------
// Release Scripts
Target "ReleaseDocs" (fun _ ->
let tempDocsDir = "temp/gh-pages"
CleanDir tempDocsDir
Repository.cloneSingleBranch "" (gitHome + "/" + gitName + ".git") "gh-pages" tempDocsDir
CopyRecursive "docs/output" tempDocsDir true |> tracefn "%A"
StageAll tempDocsDir
Git.Commit.Commit tempDocsDir (sprintf "Update generated documentation for version %s" release.NugetVersion)
Branches.push tempDocsDir
)
#load "paket-files/build/fsharp/FAKE/modules/Octokit/Octokit.fsx"
open Octokit
Target "Release" (fun _ ->
let user =
match getBuildParam "github-user" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserInput "Username: "
let pw =
match getBuildParam "github-pw" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserPassword "Password: "
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.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.pushBranch "" remote (Information.getBranchName "")
Branches.tag "" release.NugetVersion
Branches.pushTag "" remote release.NugetVersion
// release on github
createClient user pw
|> createDraft gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
|> releaseDraft
|> Async.RunSynchronously
)
Target "Publish" DoNothing
// Build order
"Clean"
==> "Meta"
==> "InstallDotNetCore"
==> "Install"
==> "Build"
==> "Package"
"Build"
==> "GenerateDocs"
==> "ReleaseDocs"
"Publish"
<== [ "Build"
"Package"
"PublishNuget"
"ReleaseDocs" ]
// start build
RunTargetOrDefault "Build"