This repository has been archived by the owner on Jun 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.fsx
222 lines (180 loc) · 7.79 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
#r "paket: groupref FakeBuild //"
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.IO
open Fake.BuildServer
open Fake.IO.Globbing.Operators
open Fake.DotNet
open Fake.DotNet.NuGet
open Fake.Core
open Fake.Tools
open Fake.Api
open Fake.Windows
BuildServer.install [
AppVeyor.Installer
]
let isAppveyor = AppVeyor.detect()
let gitVersion = GitVersion.generateProperties id
Target.create "Clean" (fun _ ->
["reports" ; "src/common" ; "nuget/tools"]
|> Seq.iter Directory.delete
!! "nuget/*"
-- "nuget/*.txt"
-- "nuget/*.nuspec"
|> File.deleteAll
let configuration =
(fun p -> { p with
Properties = ["Configuration", "Release"]
Verbosity = Some MSBuildVerbosity.Minimal })
!! "src/BCC.Submission.sln"
|> MSBuild.run configuration null "Clean" list.Empty
|> Trace.logItems "Clean-Output: "
)
Target.create "Build" (fun _ ->
CreateProcess.fromRawWindowsCommandLine "gitversion" "/updateassemblyinfo src\common\SharedAssemblyInfo.cs /ensureassemblyinfo"
|> Proc.run
|> ignore
let configuration = (fun p -> { p with
DoRestore = true
Verbosity = Some MSBuildVerbosity.Minimal })
!! "src/BCC.Submission.sln"
|> MSBuild.runRelease configuration null "Build"
|> Trace.logItems "AppBuild-Output: "
)
Target.create "Test" (fun _ ->
List.allPairs ["BCC.Submission.Tests"] ["net471" ; "netcoreapp2.1"]
|> Seq.iter (fun (proj, framework) ->
let projectPath = sprintf "src\\%s\\%s.csproj" proj proj
let reportFile = sprintf "%s-%s.results.trx" proj framework
let configuration: (DotNet.TestOptions -> DotNet.TestOptions)
= (fun t -> {t with
Configuration = DotNet.BuildConfiguration.Release
NoBuild = true
Framework = Some framework
Logger = Some (sprintf "trx;LogFileName=%s" reportFile)
ResultsDirectory = Some "../../reports"})
DotNet.test configuration projectPath
Trace.publish ImportData.BuildArtifact (sprintf "reports/%s" reportFile)
)
)
Target.create "Package" (fun _ ->
Shell.copyRecursive "src/BCC.Submission/bin/Release" "nuget/tools" false
|> ignore
NuGet.NuGetPack (fun p -> { p with
Version = gitVersion.NuGetVersionV2
OutputPath = "nuget" }) "nuget/Package.nuspec"
!! "nuget/*.nupkg"
|> Seq.iter (Trace.publish ImportData.BuildArtifact)
)
Target.create "Coverage" (fun _ ->
List.allPairs ["BCC.Submission.Tests"] ["net471" ; "netcoreapp2.1"]
|> Seq.iter (fun (proj, framework) ->
let dllPath = sprintf "src\\%s\\bin\\Release\\%s\\%s.dll" proj framework proj
let projectPath = sprintf "src\\%s\\%s.csproj" proj proj
let reportPath = sprintf "reports/%s-%s.coverage.xml" proj framework
sprintf "%s --target \"dotnet\" --targetargs \"test -c Release -f %s %s --no-build\" --format opencover --output \"./%s\""
dllPath framework projectPath reportPath
|> CreateProcess.fromRawWindowsCommandLine "coverlet"
|> Proc.run
|> ignore
Trace.publish ImportData.BuildArtifact reportPath
if isAppveyor then
CreateProcess.fromRawWindowsCommandLine "codecov" (sprintf "-f \"%s\"" reportPath)
|> Proc.run
|> ignore
)
)
Target.create "DeployGitHub" (fun _ ->
let gitHubToken = Environment.environVarOrNone("GITHUB_TOKEN")
if(gitHubToken.IsNone) then
Trace.traceError "GITHUB_TOKEN is not defined"
else
let (gitOwner, gitName) =
AppVeyor.Environment.RepoName.Split('/')
|> Array.pairwise
|> Array.head
let repoTagName = AppVeyor.Environment.RepoTagName
let projectName = AppVeyor.Environment.ProjectName
GitHub.createClientWithToken gitHubToken.Value
|> (fun clientAsync ->
async {
let! client = clientAsync
let releaseClient = client.Repository.Release
let! someRelease = async {
let! exc = Async.Catch(async {
let! str = Async.AwaitTask (releaseClient.Get(gitOwner, gitName, repoTagName))
return str })
match exc with
| Choice1Of2 r -> return Some r
| Choice2Of2 _ -> return None
}
match someRelease with
| Some release -> Trace.traceErrorfn "Release '%s' @ '%s' already exists" release.Name repoTagName
| _ ->
let isPrerelease = not(String.isNullOrWhiteSpace gitVersion.PreReleaseTag)
let releaseName = sprintf "%s - v%s" projectName gitVersion.SemVer
let releaseBody = sprintf "## %s" releaseName
let newRelease = new Octokit.NewRelease(repoTagName);
newRelease.Name <- releaseName
newRelease.Body <- releaseBody
newRelease.Draft <- true
newRelease.Prerelease <- isPrerelease
let! release = releaseClient.Create(gitOwner, gitName, newRelease) |> Async.AwaitTask
let release : GitHub.Release = {
Client = client;
Owner = gitOwner;
RepoName = gitName;
Release = release
}
let files = !! "nuget/*.nupkg"
release
|> async.Return
|> GitHub.uploadFiles files
|> GitHub.publishDraft
|> Async.RunSynchronously
Trace.traceImportantfn "Created Release: '%s' @ '%s'" releaseName repoTagName
}
)
|> Async.Catch
|> Async.RunSynchronously
|> ignore
)
Target.create "DeployNuGet" (fun _ ->
let nugetApiKey = Environment.environVarOrNone("NUGET_API_KEY")
if (nugetApiKey.IsNone) then
Trace.traceError "NUGET_API_KEY is not defined"
else
try
NuGet.NuGetPublish (fun p -> { p with
AccessKey = nugetApiKey.Value
Project = "BCC-Submission"
Version = gitVersion.NuGetVersionV2
WorkingDir = "nuget" })
Trace.traceImportant "Uploaded NuGet Package"
with ex ->
Trace.traceError "Unable to create NuGet Package"
Trace.traceException ex
)
Target.create "DeployChocolatey" (fun _ ->
let chocoApiKey = Environment.environVarOrNone("CHOCO_API_KEY")
if (chocoApiKey.IsNone) then
Trace.traceError "CHOCO_API_KEY is not defined"
else
try
!! "nuget/*.nupkg"
|> Seq.iter (Choco.push (fun p -> { p with ApiKey = chocoApiKey.Value }))
with ex ->
Trace.traceError "Unable to create Chocolatey Package"
Trace.traceException ex
)
Target.create "Default" (fun _ -> ())
open Fake.Core.TargetOperators
"Clean" ==> "Build"
"Build" ==> "Package" ==> "Default"
"Build" ==> "Test" ==> "Default"
"Build" ==> "Coverage" ==> "Default"
let shouldDeploy = isAppveyor && AppVeyor.Environment.RepoTag
"Package" =?> ("DeployGitHub", (shouldDeploy)) ==> "Default"
"Package" =?> ("DeployNuGet", (shouldDeploy)) ==> "Default"
"Package" =?> ("DeployChocolatey", (shouldDeploy)) ==> "Default"
// start build
Target.runOrDefault "Default"