@@ -9,7 +9,15 @@ open Fake.Core.TargetOperators
9
9
open Fake.Api
10
10
open Fake.BuildServer
11
11
open Argu
12
- open Helpers
12
+
13
+ let environVarAsBoolOrDefault varName defaultValue =
14
+ let truthyConsts = [ " 1" ; " Y" ; " YES" ; " T" ; " TRUE" ]
15
+ Environment.environVar varName
16
+ |> ValueOption.ofObj
17
+ |> ValueOption.map ( fun envvar ->
18
+ truthyConsts
19
+ |> List.exists ( fun ``const`` -> String.Equals ( `` const `` , envvar, StringComparison.InvariantCultureIgnoreCase)))
20
+ |> ValueOption.defaultValue defaultValue
13
21
14
22
//-----------------------------------------------------------------------------
15
23
// Metadata and Configuration
@@ -61,6 +69,7 @@ let gitHubRepoUrl = $"https://github.com/%s{gitOwner}/%s{gitRepoName}"
61
69
62
70
let documentationRootUrl = $" https://%s {gitOwner}.github.io/%s {gitRepoName}"
63
71
72
+ let releaseBranch = " main"
64
73
let readme = " README.md"
65
74
let changelogFile = " CHANGELOG.md"
66
75
@@ -87,6 +96,53 @@ let githubToken = Environment.environVarOrNone "GITHUB_TOKEN"
87
96
88
97
let nugetToken = Environment.environVarOrNone " NUGET_TOKEN"
89
98
99
+ //-----------------------------------------------------------------------------
100
+ // Helpers
101
+ //-----------------------------------------------------------------------------
102
+
103
+
104
+ let isRelease ( targets : Target list ) =
105
+ targets
106
+ |> Seq.map ( fun t -> t.Name)
107
+ |> Seq.exists ((=) " PublishToNuGet" )
108
+
109
+ let invokeAsync f = async { f () }
110
+
111
+ let configuration ( targets : Target list ) =
112
+ let defaultVal = if isRelease targets then " Release" else " Debug"
113
+
114
+ match Environment.environVarOrDefault " CONFIGURATION" defaultVal with
115
+ | " Debug" -> DotNet.BuildConfiguration.Debug
116
+ | " Release" -> DotNet.BuildConfiguration.Release
117
+ | config -> DotNet.BuildConfiguration.Custom config
118
+
119
+ let failOnBadExitAndPrint ( p : ProcessResult ) =
120
+ if p.ExitCode <> 0 then
121
+ p.Errors |> Seq.iter Trace.traceError
122
+
123
+ failwithf " failed with exitcode %d " p.ExitCode
124
+
125
+
126
+ let isCI = lazy environVarAsBoolOrDefault " CI" false
127
+
128
+ // CI Servers can have bizarre failures that have nothing to do with your code
129
+ let rec retryIfInCI times fn =
130
+ match isCI.Value with
131
+ | true ->
132
+ if times > 1 then
133
+ try
134
+ fn ()
135
+ with _ ->
136
+ retryIfInCI ( times - 1 ) fn
137
+ else
138
+ fn ()
139
+ | _ -> fn ()
140
+
141
+ let failOnWrongBranch () =
142
+ if Git.Information.getBranchName " " <> releaseBranch then
143
+ failwithf " Not on %s . If you want to release please switch to this branch." releaseBranch
144
+
145
+
90
146
module dotnet =
91
147
let watch cmdParam program args = DotNet.exec cmdParam ( sprintf " watch %s " program) args
92
148
0 commit comments