forked from ctaggart/SourceLink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.fsx
More file actions
282 lines (243 loc) · 9.83 KB
/
build.fsx
File metadata and controls
282 lines (243 loc) · 9.83 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#I "packages/FAKE/tools"
#r "FakeLib.dll"
#load "packages/SourceLink.Fake/tools/SourceLink.fsx"
open System
open System.IO
open Fake
open Fake.AssemblyInfoFile
open SourceLink
open Fake.AppVeyor
open Fake.Testing
open System.Collections.Generic
open Fake.Git
let buildDate =
let pst = TimeZoneInfo.FindSystemTimeZoneById "Pacific Standard Time"
DateTimeOffset(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, pst), pst.BaseUtcOffset)
let revision =
use repo = new GitRepo(__SOURCE_DIRECTORY__)
repo.Commit
let isAppVeyorBuild = buildServer = BuildServer.AppVeyor
let hasRepoVersionTag = isAppVeyorBuild && AppVeyorEnvironment.RepoTag && AppVeyorEnvironment.RepoTagName.StartsWith "v"
let release = ReleaseNotesHelper.LoadReleaseNotes "RELEASE_NOTES.md"
let versionAssembly =
if hasRepoVersionTag then AppVeyor.AppVeyorEnvironment.RepoTagName.Substring 1
else release.NugetVersion
let buildVersion =
if hasRepoVersionTag then versionAssembly
else if isAppVeyorBuild then sprintf "%s-b%s" versionAssembly AppVeyorEnvironment.BuildNumber
else sprintf "%s-a%s" versionAssembly (buildDate.ToString "yyMMddHHmm") // 20 char limit
MSBuildDefaults <- { MSBuildDefaults with Verbosity = Some MSBuildVerbosity.Minimal }
Target "Clean" <| fun _ -> !! "**/bin/" ++ "**/obj/" ++ "**/docs/output/" |> CleanDirs
Target "BuildVersion" <| fun _ ->
let result =
ExecProcess (fun info ->
info.FileName <- @"C:\Program Files\AppVeyor\BuildAgent\appveyor.exe"
info.Arguments <- sprintf "UpdateBuild -Version \"%s\"" buildVersion) TimeSpan.MaxValue
if result <> 0 then failwithf "Error setting BuildVersion"
Target "AssemblyInfo" <| fun _ ->
let iv = Text.StringBuilder() // json
iv.Appendf "{\\\"buildVersion\\\":\\\"%s\\\"" buildVersion
iv.Appendf ",\\\"buildDate\\\":\\\"%s\\\"" (buildDate.ToString "yyyy'-'MM'-'dd'T'HH':'mm':'sszzz")
if isAppVeyorBuild then
iv.Appendf ",\\\"gitCommit\\\":\\\"%s\\\"" AppVeyor.AppVeyorEnvironment.RepoCommit
iv.Appendf ",\\\"gitBranch\\\":\\\"%s\\\"" AppVeyor.AppVeyorEnvironment.RepoBranch
iv.Appendf "}"
let common = [
Attribute.Version versionAssembly
Attribute.InformationalVersion iv.String ]
common |> CreateFSharpAssemblyInfo "SourceLink/AssemblyInfo.fs"
common |> CreateFSharpAssemblyInfo "Build/AssemblyInfo.fs"
common |> CreateFSharpAssemblyInfo "Git/AssemblyInfo.fs"
common |> CreateFSharpAssemblyInfo "SymbolStore/AssemblyInfo.fs"
common |> CreateCSharpAssemblyInfo "CorSym/Properties/AssemblyInfo.cs"
common |> CreateFSharpAssemblyInfo "Exe/AssemblyInfo.fs"
Target "Build" <| fun _ ->
!! "SourceLink.sln" |> MSBuildRelease "" "Rebuild" |> ignore
Target "UnitTest" <| fun _ ->
CreateDir "bin"
xUnit2 (fun p ->
{ p with
// IncludeTraits = ["Kind", "Unit"]
XmlOutputPath = Some @"bin\UnitTest.xml"
Parallel = ParallelMode.All
})
[ @"UnitTest\bin\Release\SourceLink.UnitTest.dll" ]
Target "SourceLink" <| fun _ ->
let sourceIndex proj pdb =
let p = VsProj.LoadRelease proj
let pdbToIndex = if Option.isSome pdb then pdb.Value else p.OutputFilePdb
let url = "https://raw.githubusercontent.com/ctaggart/SourceLink/{0}/%var2%"
SourceLink.Index p.Compiles pdbToIndex __SOURCE_DIRECTORY__ url
sourceIndex "SourceLink/SourceLink.fsproj" None
sourceIndex "Git/Git.fsproj" None
sourceIndex "SymbolStore/SymbolStore.fsproj" None
sourceIndex "CorSym/CorSym.csproj" (Some "SymbolStore/bin/Release/SourceLink.SymbolStore.CorSym.pdb")
sourceIndex "Exe/Exe.fsproj" None
let bin = "bin"
let nugetApiKey = environVarOrDefault "NuGetApiKey" ""
let chocolateyApiKey = environVarOrDefault "ChocolateyApiKey" ""
let githubToken = environVarOrDefault "GitHubToken" ""
let pSourceLink (p: NuGetParams) =
{ p with
Project = "SourceLink.Core"
Version = buildVersion
WorkingDir = "SourceLink/bin/Release"
OutputPath = bin
DependenciesByFramework =
[{
FrameworkVersion = "net45"
Dependencies = [ "Argu", GetPackageVersion "./packages/" "Argu"
"FSharp.Core", GetPackageVersion "./packages/" "FSharp.Core" ]
}]
AccessKey = nugetApiKey
}
let pBuild (p: NuGetParams) =
{ p with
Project = "SourceLink.Build"
Version = buildVersion
WorkingDir = "Build/bin/Release"
OutputPath = bin
AccessKey = nugetApiKey
}
let pFake (p: NuGetParams) =
{ p with
Project = "SourceLink.Fake"
Version = buildVersion
WorkingDir = "Fake"
OutputPath = bin
AccessKey = nugetApiKey
}
let pGit (p: NuGetParams) =
{ p with
Project = "SourceLink.Git"
Version = buildVersion
WorkingDir = "Git/bin/Release"
OutputPath = bin
DependenciesByFramework =
[{
FrameworkVersion = "net45"
Dependencies = [ "LibGit2Sharp", GetPackageVersion "./packages/" "LibGit2Sharp"
"FSharp.Core", GetPackageVersion "./packages/" "FSharp.Core" ]
}]
AccessKey = nugetApiKey
}
let pSymbolStore (p: NuGetParams) =
{ p with
Project = "SourceLink.SymbolStore"
Version = buildVersion
WorkingDir = "SymbolStore/bin/Release"
OutputPath = bin
DependenciesByFramework =
[{
FrameworkVersion = "net45"
Dependencies = [ "FSharp.Core", GetPackageVersion "./packages/" "FSharp.Core" ]
}]
AccessKey = nugetApiKey
}
let pExe (p: NuGetParams) =
{ p with
Project = "SourceLink"
Version = buildVersion
WorkingDir = "Exe/bin/Release"
OutputPath = bin
AccessKey = nugetApiKey
}
let pExeChocolatey (p: NuGetParams) =
{ pExe p with
PublishUrl = "https://chocolatey.org/"
AccessKey = chocolateyApiKey
}
Target "NuGet" <| fun _ ->
Directory.CreateDirectory bin |> ignore
NuGet pSourceLink "SourceLink/SourceLink.nuspec"
NuGet pFake "Fake/Fake.nuspec"
NuGet pBuild "Build/Build.nuspec"
NuGet pGit "Git/Git.nuspec"
NuGet pSymbolStore "SymbolStore/SymbolStore.nuspec"
NuGet pExe "Exe/Exe.nuspec"
Target "Publish" <| fun _ ->
NuGetPublish pSourceLink
NuGetPublish pFake
NuGetPublish pGit
NuGetPublish pSymbolStore
NuGetPublish pExe
NuGetPublish pExeChocolatey
//Target "GenerateReferenceDocs" <| fun _ ->
// if not <| executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"; "--define:REFERENCE"] [] then
// failwith "generating reference documentation failed"
let generateDocs fail =
if executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"; "--define:HELP"] [] then
traceImportant "Help generated"
else
if fail then
failwith "generating help documentation failed"
else
traceImportant "generating help documentation failed"
Target "Docs" <| fun _ ->
DeleteFile "docs/content/release-notes.md"
CopyFile "docs/content/" "RELEASE_NOTES.md"
Rename "docs/content/release-notes.md" "docs/content/RELEASE_NOTES.md"
// DeleteFile "docs/content/license.md"
// CopyFile "docs/content/" "LICENSE.txt"
// Rename "docs/content/license.md" "docs/content/LICENSE.txt"
generateDocs true
CopyFile "docs/output" "SourceLink128.jpg" // icon used by all NuGet packages
Target "WatchDocs" <| fun _ ->
use watcher = new FileSystemWatcher(DirectoryInfo("docs/content").FullName,"*.*")
watcher.EnableRaisingEvents <- true
watcher.Changed.Add(fun e -> generateDocs false)
watcher.Created.Add(fun e -> generateDocs false)
watcher.Renamed.Add(fun e -> generateDocs false)
watcher.Deleted.Add(fun e -> generateDocs false)
traceImportant "Waiting for help edits. Press any key to stop."
System.Console.ReadKey() |> ignore
watcher.EnableRaisingEvents <- false
watcher.Dispose()
Target "PushDocs" <| fun _ ->
CleanDir "gh-pages"
let auth = if githubToken = "" then "" else sprintf "%s@" githubToken
cloneSingleBranch "" (sprintf "https://%sgithub.com/ctaggart/SourceLink.git" auth) "gh-pages" "gh-pages"
fullclean "gh-pages"
CopyRecursive "docs/output" "gh-pages" true |> printfn "%A"
StageAll "gh-pages"
Commit "gh-pages" (sprintf "updated docs from %s" buildVersion)
Branches.push "gh-pages"
Target "Help" <| fun _ ->
printfn "build.cmd [<target>] [options]"
printfn @"for FAKE help: packages\FAKE\tools\FAKE.exe --help"
printfn "targets:"
printfn " * `Clean` removes temporary directories"
printfn " * `Build` builds the solution"
printfn " * `SourceLink` source indexes the built pdb files"
printfn " * `NuGet` creates the nupkg files"
printfn " * `Docs` creates the documentation"
// chain targets together only on AppVeyor
let (==>) a b = a =?> (b, isAppVeyorBuild)
"BuildVersion"
==> "AssemblyInfo"
==> "Build"
==> "UnitTest"
==> "SourceLink"
==> "NuGet"
==> "Publish"
let runTargets() =
// when on AppVeyor, allow targets to be specified as #hashtags
if isAppVeyorBuild then
if hasRepoVersionTag then
run "Publish"
else
let targets = HashSet(getAllTargetsNames(), StringComparer.OrdinalIgnoreCase)
let cm = AppVeyorEnvironment.RepoCommitMessage
let rx = Text.RegularExpressions.Regex @"\B#([a-zA-Z]\w+)"
let hashtags = seq {
for m in rx.Matches cm do
yield m.Groups.[1].Value } |> List.ofSeq
if hashtags.Length = 0 then
RunTargetOrDefault "NuGet"
else
for ht in hashtags do
if targets.Contains ht then
run ht
else
RunTargetOrDefault "Help"
runTargets()