-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.fsx
172 lines (141 loc) · 5.67 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r @"packages/FAKE/tools/FakeLib.dll"
open Fake
open Fake.Git
open Fake.AssemblyInfoFile
open Fake.ReleaseNotesHelper
open System
open System.IO
let project = "Zipkin"
let summary = "A minimalistic .NET client library for Twitter Zipkin tracing."
let solutionFile = "Zipkin.sln"
let testAssemblies = "tests/**/bin/Release/*Tests*.dll"
let gitOwner = "openzipkin"
let gitHome = "https://github.com/" + gitOwner
let gitName = "Zipkin-csharp"
let gitRaw = environVarOrDefault "gitRaw" "https://raw.github.com/openzipkin"
let binDir = currentDirectory @@ "bin"
// Read additional information from the release notes document
let release = LoadReleaseNotes "RELEASE_NOTES.md"
// Helper active pattern for project types
let (|Fsproj|Csproj|Vbproj|) (projFileName:string) =
match projFileName with
| f when f.EndsWith("fsproj") -> Fsproj
| f when f.EndsWith("csproj") -> Csproj
| f when f.EndsWith("vbproj") -> Vbproj
| _ -> failwith (sprintf "Project file %s not supported. Unknown project type." projFileName)
// Copies binaries from default VS location to expected bin folder
// But keeps a subdirectory structure for each project in the
// src folder to support multiple project outputs
Target "CopyBinaries" (fun _ ->
!! "src/**/*.??proj"
|> Seq.map (fun f -> ((System.IO.Path.GetDirectoryName f) @@ "bin/Release", "bin" @@ (System.IO.Path.GetFileNameWithoutExtension f)))
|> Seq.iter (fun (fromDir, toDir) -> CopyDir toDir fromDir (fun _ -> true))
)
// --------------------------------------------------------------------------------------
// Restore Packages
Target "RestorePackages" (fun _ ->
let nugetExe = NuGetHelper.NuGetDefaults().ToolPath
let nugetCmd = "restore"
let result = ExecProcess (fun info ->
info.FileName <- nugetExe
info.Arguments <- nugetCmd)(TimeSpan.FromSeconds 10.0)
printfn "Restored packages."
)
// --------------------------------------------------------------------------------------
// Clean build results
Target "Clean" (fun _ ->
CleanDirs ["bin"; "temp"]
)
Target "CleanDocs" (fun _ ->
CleanDirs ["docs/output"]
)
// --------------------------------------------------------------------------------------
// Build library & test project
Target "Build" (fun _ ->
!! solutionFile
|> MSBuildRelease "" "Rebuild"
|> ignore
)
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner
open Fake.Testing.XUnit2
Target "RunTests" (fun _ ->
!! testAssemblies
|> xUnit2 (fun p ->
{ p with
TimeOut = TimeSpan.FromMinutes 20.
XmlOutputPath = Some "TestResults.xml"
ToolPath = "packages/xunit.runner.console/tools/xunit.console.exe" })
)
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target "NuGet" (fun _ ->
!! "src/**/*.nuspec"
|> Seq.toArray
|> Array.iter (fun nuspec ->
let project = Path.GetFileNameWithoutExtension nuspec
let dir = (Path.GetDirectoryName nuspec)
let packagesFile = dir @@ "packages.config"
let dependencies = NuGetHelper.getDependencies packagesFile
let buildDir = binDir @@ project
NuGetHelper.NuGetPack
(fun p ->
{ p with
Copyright = "OpenZipkin Developers"
Project = project
Properties = ["Configuration", "Release"]
ReleaseNotes = release.Notes |> String.concat "\n"
Version = release.NugetVersion
IncludeReferencedProjects = true
OutputPath = buildDir
WorkingDir = dir
Dependencies = dependencies })
(nuspec.Replace(".nuspec", ".csproj")))
)
Target "PublishNuget" (fun _ ->
let rec publishPackage trialsLeft nupkg =
let nugetExe = NuGetHelper.NuGetDefaults().ToolPath
let key = getBuildParam "key"
let url = "https://www.nuget.org/api/v2/package"
let nugetCmd = sprintf "push \"%s\" %s -source %s" nupkg key url
tracefn "Pushing %s Attempts left: %d" nupkg trialsLeft
try
let result = ExecProcess (fun info ->
info.FileName <- nugetExe
info.WorkingDirectory <- (Path.GetDirectoryName nupkg)
info.Arguments <- nugetCmd) (TimeSpan.FromSeconds 10.0)
if result <> 0 then failwithf "Error during NuGet symbol push. %s %s" nugetExe nugetCmd
with exn ->
if (trialsLeft > 0) then (publishPackage (trialsLeft-1) nupkg)
else raise exn
!! "**/*.nupkg"
|> Seq.toArray
|> Array.iter (publishPackage 5)
)
Target "KeepRunning" (fun _ ->
use watcher = new FileSystemWatcher(DirectoryInfo("docs/content").FullName,"*.*")
watcher.EnableRaisingEvents <- true
traceImportant "Waiting for help edits. Press any key to stop."
System.Console.ReadKey() |> ignore
watcher.EnableRaisingEvents <- false
watcher.Dispose()
)
Target "BuildPackage" DoNothing
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target "All" DoNothing
"Clean"
==> "RestorePackages"
==> "Build"
==> "CopyBinaries"
==> "RunTests"
==> "All"
"All"
==> "NuGet"
==> "BuildPackage"
"BuildPackage"
==> "PublishNuget"
RunTargetOrDefault "All"