-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.fsx
150 lines (121 loc) · 5.71 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
#load ".fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
#nowarn "3180"
module Environment =
let [<Literal>] APPVEYOR = "APPVEYOR"
let [<Literal>] APPVEYOR_BUILD_NUMBER = "APPVEYOR_BUILD_NUMBER"
let [<Literal>] APPVEYOR_PULL_REQUEST_NUMBER = "APPVEYOR_PULL_REQUEST_NUMBER"
let [<Literal>] APPVEYOR_REPO_BRANCH = "APPVEYOR_REPO_BRANCH"
let [<Literal>] APPVEYOR_REPO_COMMIT = "APPVEYOR_REPO_COMMIT"
let [<Literal>] APPVEYOR_REPO_TAG_NAME = "APPVEYOR_REPO_TAG_NAME"
let [<Literal>] BUILD_CONFIGURATION = "BuildConfiguration"
let [<Literal>] REPOSITORY = "https://github.com/OrleansContrib/Orleans.Persistence.Minio.git"
module Process =
let private timeout =
System.TimeSpan.FromMinutes 2.
let execWithMultiResult f =
Process.execWithResult f timeout
|> fun r -> r.Messages
let execWithSingleResult f =
execWithMultiResult f
|> List.head
module GitVersion =
let showVariable =
let commit =
match Environment.environVarOrNone Environment.APPVEYOR_REPO_COMMIT with
| Some c -> c
| None -> Process.execWithSingleResult (fun info -> { info with FileName = "git"; Arguments = "rev-parse HEAD" })
printfn "Executing gitversion from commit '%s'." commit
fun variable ->
match Environment.environVarOrNone Environment.APPVEYOR_REPO_BRANCH, Environment.environVarOrNone Environment.APPVEYOR_PULL_REQUEST_NUMBER with
| Some branch, None ->
Process.execWithSingleResult (fun info ->
{ info with
FileName = "gitversion"
Arguments = sprintf "/showvariable %s /url %s /b b-%s /dynamicRepoLocation .\gitversion /c %s" variable Environment.REPOSITORY branch commit })
| _ ->
Process.execWithSingleResult (fun info -> { info with FileName = "gitversion"; Arguments = sprintf "/showvariable %s" variable })
let get =
let mutable value: Option<string * string * string> = None
Target.createFinal "ClearGitVersionRepositoryLocation" (fun _ ->
Shell.deleteDir "gitversion"
)
fun () ->
match value with
| None ->
value <-
match Environment.environVarOrNone Environment.APPVEYOR_REPO_TAG_NAME with
| Some v -> Some (v, showVariable "AssemblySemVer", v)
| None -> Some (showVariable "FullSemVer", showVariable "AssemblySemVer", showVariable "NuGetVersionV2")
Target.activateFinal "ClearGitVersionRepositoryLocation"
Option.get value
| Some v -> v
Target.create "Clean" (fun _ ->
!! "**/bin"
++ "**/obj"
++ "**/artifacts"
++ "gitversion"
|> Shell.deleteDirs
)
Target.create "PrintVersion" (fun _ ->
let (fullSemVer, assemblyVer, nugetVer) = GitVersion.get()
printfn "Full version: '%s'" fullSemVer
printfn "Assembly version: '%s'" assemblyVer
printfn "NuGet version: '%s'" nugetVer
)
Target.create "UpdateBuildVersion" (fun _ ->
let (fullSemVer, _, _) = GitVersion.get()
Shell.Exec("appveyor", sprintf "UpdateBuild -Version \"%s (%s)\"" fullSemVer (Environment.environVar Environment.APPVEYOR_BUILD_NUMBER))
|> ignore
)
Target.create "GatherReleaseNotes" (fun _ ->
let (fullSemVer, _, _) = GitVersion.get()
let prevCommitHash =
Process.execWithSingleResult (fun info -> { info with FileName = "git"; Arguments = "rev-list --tags --skip=1 --max-count=1" })
let previousTag =
Process.execWithSingleResult (fun info -> { info with FileName = "git"; Arguments = sprintf "describe --abbrev=0 --tags %s" prevCommitHash })
let releaseNotes =
Process.execWithMultiResult (fun info -> { info with FileName = "git"; Arguments = sprintf "log --pretty=format:\"%%h %%s\" %s..%s" previousTag fullSemVer})
|> String.concat(System.Environment.NewLine)
printfn "Gathered release notes:"
printfn "%s" releaseNotes
Shell.Exec("appveyor", sprintf "SetVariable -Name release_notes -Value \"%s\"" releaseNotes)
|> ignore
)
Target.create "Build" (fun _ ->
let (fullSemVer, assemblyVer, _) = GitVersion.get()
let setParams (buildOptions: DotNet.BuildOptions) =
{ buildOptions with
Common = { buildOptions.Common with DotNet.CustomParams = Some (sprintf "/p:Version=%s /p:FileVersion=%s" fullSemVer assemblyVer) }
Configuration = DotNet.BuildConfiguration.fromEnvironVarOrDefault Environment.BUILD_CONFIGURATION DotNet.BuildConfiguration.Debug }
!! "**/*.*proj"
-- "**/Orleans.Persistence.Minio.*Test.*proj"
-- "**/gitversion/**/*.*proj"
|> Seq.iter (DotNet.build setParams)
)
Target.create "Pack" (fun _ ->
let (_, _, nuGetVer) = GitVersion.get()
let setParams (packOptions: DotNet.PackOptions) =
{ packOptions with
Configuration = DotNet.BuildConfiguration.fromEnvironVarOrDefault Environment.BUILD_CONFIGURATION DotNet.BuildConfiguration.Debug
OutputPath = Some "../artifacts"
NoBuild = true
Common = { packOptions.Common with CustomParams = Some (sprintf "/p:PackageVersion=%s" nuGetVer) } }
!! "**/*.*proj"
-- "**/Orleans.Persistence.Minio.*Test.*proj"
-- "**/gitversion/**/*.*proj"
|> Seq.iter (DotNet.pack setParams)
)
Target.create "All" ignore
"Clean"
==> "PrintVersion"
=?> ("UpdateBuildVersion", Environment.environVarAsBool Environment.APPVEYOR)
=?> ("GatherReleaseNotes", not <| String.isNullOrWhiteSpace(Environment.environVar Environment.APPVEYOR_REPO_TAG_NAME))
==> "Build"
==> "Pack"
==> "All"
Target.runOrDefault "Build"