-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: fix retrieving version for publishing to GitHub
also extract helpers to a separate file
- Loading branch information
1 parent
7476c7e
commit b7df595
Showing
4 changed files
with
75 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module Helpers | ||
|
||
open System | ||
open Fake.Core | ||
open Fake.DotNet | ||
open Fake.Tools | ||
|
||
let releaseBranch = "main" | ||
|
||
let environVarAsBoolOrDefault varName defaultValue = | ||
let truthyConsts = [ "1"; "Y"; "YES"; "T"; "TRUE" ] | ||
Environment.environVar varName | ||
|> ValueOption.ofObj | ||
|> ValueOption.map (fun envvar -> | ||
truthyConsts | ||
|> List.exists (fun ``const`` -> String.Equals (``const``, envvar, StringComparison.InvariantCultureIgnoreCase))) | ||
|> ValueOption.defaultValue defaultValue | ||
|
||
let isRelease (targets : Target list) = | ||
targets | ||
|> Seq.map (fun t -> t.Name) | ||
|> Seq.exists ((=) "PublishToNuGet") | ||
|
||
let invokeAsync f = async { f () } | ||
|
||
let configuration (targets : Target list) = | ||
let defaultVal = if isRelease targets then "Release" else "Debug" | ||
|
||
match Environment.environVarOrDefault "CONFIGURATION" defaultVal with | ||
| "Debug" -> DotNet.BuildConfiguration.Debug | ||
| "Release" -> DotNet.BuildConfiguration.Release | ||
| config -> DotNet.BuildConfiguration.Custom config | ||
|
||
let failOnBadExitAndPrint (p : ProcessResult) = | ||
if p.ExitCode <> 0 then | ||
p.Errors |> Seq.iter Trace.traceError | ||
|
||
failwithf "failed with exitcode %d" p.ExitCode | ||
|
||
let isPublishToGitHub ctx = ctx.Context.FinalTarget = "PublishToGitHub" | ||
|
||
type TargetParameter with | ||
|
||
member ctx.IsPublishToGitHub = isPublishToGitHub ctx | ||
|
||
let isCI = lazy environVarAsBoolOrDefault "CI" false | ||
|
||
// CI Servers can have bizarre failures that have nothing to do with your code | ||
let rec retryIfInCI times fn = | ||
match isCI.Value with | ||
| true -> | ||
if times > 1 then | ||
try | ||
fn () | ||
with _ -> | ||
retryIfInCI (times - 1) fn | ||
else | ||
fn () | ||
| _ -> fn () | ||
|
||
let failOnWrongBranch () = | ||
if Git.Information.getBranchName "" <> releaseBranch then | ||
failwithf "Not on %s. If you want to release please switch to this branch." releaseBranch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters