-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.template
285 lines (233 loc) · 8.88 KB
/
build.template
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
283
284
285
#r @"packages/build/FAKE/tools/FakeLib.dll"
open Fake
open Fake.AssemblyInfoFile
open Fake.ProcessHelper
open System
open System.IO
open System.Text.RegularExpressions
(*################################# Definitions #################################*)
type GitVersionInfo = {
Major: int
Minor: int
Patch: int
CommitsAhead : int
IsReleaseCandidate : bool
PreReleaseVersion: (string*int) option
Hash: string
Sha: string
Branch: string
LatestReleaseTag: string option
}
let BuildAssemblyVersion info =
if info.CommitsAhead = 0
then new Version(info.Major, info.Minor, info.Patch, info.CommitsAhead)
else
match info.Branch with
| "release" -> new Version(info.Major, info.Minor + 1, 0, 0)
| "hotfix" -> new Version(info.Major, info.Minor, info.Patch + 1, 0)
| _ -> new Version(info.Major, info.Minor, info.Patch, info.CommitsAhead)
let CreateAssemblyVersion info =
let assemblyVersion = BuildAssemblyVersion info
sprintf "%i.%i.%i.%i" assemblyVersion.Major assemblyVersion.Minor assemblyVersion.Build assemblyVersion.Revision
let CreateSemVer info =
let assemblyVersion = BuildAssemblyVersion info
match info.PreReleaseVersion with
| Some (tag, version) -> sprintf "%i.%i.%i-%s%i" assemblyVersion.Major assemblyVersion.Minor assemblyVersion.Build tag version
| None -> sprintf "%i.%i.%i" assemblyVersion.Major assemblyVersion.Minor assemblyVersion.Build
let CreateInformationalVersion info =
sprintf "%s+%i.Branch.%s.Sha.%s" (CreateSemVer info) info.CommitsAhead info.Branch info.Sha
let IsPublishAllowed info =
(info.Branch = "master" && info.CommitsAhead = 0) || (info.Branch = "integration" && info.CommitsAhead <> 0)
let GetPreReleaseTag branch =
match branch with
| "master" -> None
| "hotfix" -> Some("rc")
| "release" -> Some("rc")
| "develop" -> Some("beta")
| _ -> Some("alpha")
let ApplyBranchConvention info =
let preReleaseTag = GetPreReleaseTag info.Branch
match preReleaseTag with
| Some tag ->
{ info with
IsReleaseCandidate = tag = "rc"
PreReleaseVersion = Some(tag, info.CommitsAhead) }
| None -> info
let ApplyConvention info =
match info.LatestReleaseTag with
| Some tag ->
let versionRegEx = Regex.Match(tag, "(?<version>\d+\.\d+(\.\d+)?)(-(?<prerelease>[A-Za-z-]*)((?<preversion>\d+))?)?")
if versionRegEx.Success
then
let version = Version.Parse versionRegEx.Groups.["version"].Value
let preReleaseTagGroup = versionRegEx.Groups.["prerelease"]
let preReleaseVersion =
if preReleaseTagGroup.Success
then
let preReleaseVersion =
let preReleaseVersionGroup = versionRegEx.Groups.["preversion"]
if preReleaseVersionGroup.Success
then int preReleaseVersionGroup.Value
else info.CommitsAhead
Some(preReleaseTagGroup.Value, preReleaseVersion)
else info.PreReleaseVersion
{ info with
Major = version.Major
Minor = version.Minor
Patch = if version.Build < 0 then 0 else version.Build
IsReleaseCandidate = preReleaseVersion |> Option.fold (fun _ (tag, version) -> tag = "rc") false
PreReleaseVersion = preReleaseVersion
}
else ApplyBranchConvention info
| None -> ApplyBranchConvention info
let GetVersionInfo tagPrefix =
let sha = Git.Information.getCurrentSHA1 ""
let latestReleaseTag =
Git.CommandHelper.runSimpleGitCommand "" (sprintf "describe --tags --abbrev=0 HEAD --always --match \"%s[0-9]*.[0-9]*\"" tagPrefix)
|> (fun result -> if result <> sha then Some(result) else None)
let branch = Git.CommandHelper.runSimpleGitCommand "" "rev-parse --abbrev-ref HEAD"
let commitsAhead =
if latestReleaseTag.IsSome
then Git.Branches.revisionsBetween "" latestReleaseTag.Value sha
else int (Git.CommandHelper.runSimpleGitCommand "" "rev-list HEAD --count")
{ Major = 0
Minor = 0
Patch = 0
CommitsAhead = commitsAhead
IsReleaseCandidate = false
PreReleaseVersion = None
Hash = Git.Information.getCurrentHash()
Sha = sha
Branch = branch
LatestReleaseTag = latestReleaseTag }
|> ApplyConvention
(*################################# Assign Variables #################################*)
let solutionFile = "##ProjectName##.sln"
let testAssemblies = "tests/**/bin/Release/*Tests*.dll"
let versionInfo = GetVersionInfo "release/*"
let dirBuildOutput = "_build.output"
let dirTestsOutput = dirBuildOutput @@ "tests"
let dirDocOutput = dirBuildOutput @@ "docs"
let dirNuGetOutput = dirBuildOutput @@ "nuget"
let dirBinOutput = dirBuildOutput @@ "bin"
let buildConfiguration = "Release"
(*################################# Print Variables #################################*)
traceHeader "Variables"
trace <| sprintf "%A" versionInfo
traceHeader ""
(*################################# Tasks #################################*)
Target "AssemblyInfo" (fun _ ->
let assemblyVersion = CreateAssemblyVersion versionInfo
let informationalVersion = CreateInformationalVersion versionInfo
trace <| sprintf "AssemblyVersion: %s" assemblyVersion
trace <| sprintf "AssemblyInformationalVersion: %s" informationalVersion
!! ("src/**/*Info.cs")
|> Seq.iter(fun file ->
(ReplaceAssemblyInfoVersions (fun f ->
{ f with
AssemblyInformationalVersion = informationalVersion
AssemblyVersion = assemblyVersion
OutputFileName = file })
Git.CommandHelper.fireAndForgetGitCommand "" ("update-index --assume-unchanged " + file)
)
)
)
Target "CopyBinaries" (fun _ ->
!! "src/**/*.??proj"
-- "src/**/*.shproj"
|> Seq.map (fun f -> ((System.IO.Path.GetDirectoryName f) </> "bin/Release", dirBuildOutput @@ "bin" </> (System.IO.Path.GetFileNameWithoutExtension f)))
|> Seq.iter (fun (fromDir, toDir) -> CopyDir toDir fromDir (fun _ -> true))
)
Target "Clean" (fun _ ->
CleanDirs [dirBuildOutput]
)
Target "CleanDocs" (fun _ ->
CleanDirs [ dirBuildOutput @@ "docs"]
)
Target "Build" (fun _ ->
MSBuildDefaults <- { MSBuildDefaults with Verbosity = Some(MSBuildVerbosity.Quiet) }
sprintf "building %s -> %s" solutionFile buildConfiguration |> traceHeader
MSBuild "" "Build" ["Configuration", buildConfiguration] [solutionFile] |> ignore
)
Target "RunTests" (fun _ ->
let tests = !! testAssemblies
if not (tests |> Seq.isEmpty)
then
ensureDirectory dirTestsOutput
tests
|> NUnit (fun p ->
{ p with
ShowLabels = false
ErrorLevel = DontFailBuild
DisableShadowCopy = true
TimeOut = (TimeSpan.FromMinutes 10.)
Domain = MultipleDomainModel
ProcessModel = MultipleProcessModel
OutputFile = (dirTestsOutput @@ "nunit-report.xml")
})
PublishArtifact dirTestsOutput
)
Target "NuGet" (fun _ ->
Paket.Pack(fun p ->
{p with
Version = (CreateSemVer versionInfo)
OutputPath = dirNuGetOutput
})
PublishArtifact dirNuGetOutput
)
Target "NuGetPush" (fun _ ->
if not (IsPublishAllowed versionInfo)
then failwithf "Vom aktuellen Stand darf keine keine Lieferung verteilt werden. %A" versionInfo
let nugetPublishUrl = environVarOrFail "NuGetPublishUrl"
let nugetApiKey = environVarOrFail "nugetkey"
Paket.Push(fun p ->
{p with
WorkingDir = (dirBuildOutput @@ "nuget")
PublishUrl = nugetPublishUrl
ApiKey = nugetApiKey
DegreeOfParallelism = 1
EndPoint = "api/packages"
})
)
Target "GenerateDocs" (fun _ ->
traceHeader "GenerateDocs"
let dirDocs = "docs"
let result =
ExecProcess (fun info ->
info.FileName <- currentDirectory @@ "packages" @@ "build" @@ "docfx.msbuild" @@ "tools" @@ "docfx.exe"
info.Arguments <- sprintf "%s" (dirDocs @@ "docfx.json")
) (TimeSpan.FromMinutes 5.)
if result <> 0 then failwithf "Error during docfx execution."
let testResults = dirTestsOutput @@ "nunit-report.xml"
if (fileExists testResults)
then
let result =
ExecProcess (fun info ->
info.FileName <- currentDirectory @@ "packages" @@ "build" @@ "NUnit2Report.Console.Runner" @@ "NUnit2Report.Console.exe"
info.Arguments <- sprintf "--fileset=\"%s\" --todir \"%s\"" testResults (dirDocOutput @@ "testreport")
) (TimeSpan.FromMinutes 15.)
if result <> 0 then failwithf "Error during NUnit2Report execution."
PublishArtifact dirDocOutput
)
Target "?" (fun _ ->
traceHeader "target summary"
trace ""
listTargets ()
trace ""
)
Target "Publish" DoNothing
Target "All" DoNothing
"Clean"
==> "AssemblyInfo"
==> "Build"
==> "CopyBinaries"
==> "RunTests"
==> "GenerateDocs"
==> "All"
"All"
==> "NuGet"
=?> ("NuGetPush", isLocalBuild || (IsPublishAllowed versionInfo))
==> "Publish"
"CleanDocs"
==> "GenerateDocs"
RunTargetOrDefault "All"