diff --git a/build/Changelog.fs b/build/Changelog.fs index 4c135ee..ada09c5 100644 --- a/build/Changelog.fs +++ b/build/Changelog.fs @@ -3,7 +3,6 @@ module Changelog open System open Fake.Core open Fake.IO -open Helpers let isEmptyChange = function @@ -63,9 +62,10 @@ let mkReleaseNotes changelog (latestEntry : Changelog.ChangelogEntry) gitHubRepo { latestEntry with Description = Some description }.ToString () let getVersionNumber envVarName ctx = + let args = ctx.Context.Arguments let verArg = - ctx.Context.Arguments + args |> List.tryHead |> Option.defaultWith (fun () -> Environment.environVarOrDefault envVarName "") @@ -100,24 +100,21 @@ let mutable changelogBackupFilename = "" let updateChangelog changelogPath (changelog : Fake.Core.Changelog.Changelog) gitHubRepoUrl ctx = - let newVersion = - if isPublishToGitHub ctx then - changelog.LatestEntry.SemVer - else - ctx |> getVersionNumber "RELEASE_VERSION" |> SemVer.parse - + let verStr = ctx |> getVersionNumber "RELEASE_VERSION" let description, unreleasedChanges = match changelog.Unreleased with | None -> None, [] | Some u -> u.Description, u.Changes + let newVersion = SemVer.parse verStr + changelog.Entries |> List.tryFind (fun entry -> entry.SemVer = newVersion) |> Option.iter (fun entry -> Trace.traceErrorfn "Version %s already exists in %s, released on %s" - newVersion.AsString + verStr changelogPath (if entry.Date.IsSome then entry.Date.Value.ToString ("yyyy-MM-dd") @@ -131,7 +128,7 @@ let updateChangelog changelogPath (changelog : Fake.Core.Changelog.Changelog) gi |> Option.iter (fun entry -> Trace.traceErrorfn "You're trying to release version %s, but a later version %s already exists, released on %s" - newVersion.AsString + verStr entry.SemVer.AsString (if entry.Date.IsSome then entry.Date.Value.ToString ("yyyy-MM-dd") diff --git a/build/Helpers.fs b/build/Helpers.fs deleted file mode 100644 index fd16058..0000000 --- a/build/Helpers.fs +++ /dev/null @@ -1,63 +0,0 @@ -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 diff --git a/build/build.fs b/build/build.fs index 6067ce4..1665147 100644 --- a/build/build.fs +++ b/build/build.fs @@ -9,7 +9,15 @@ open Fake.Core.TargetOperators open Fake.Api open Fake.BuildServer open Argu -open Helpers + +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 //----------------------------------------------------------------------------- // Metadata and Configuration @@ -61,6 +69,7 @@ let gitHubRepoUrl = $"https://github.com/%s{gitOwner}/%s{gitRepoName}" let documentationRootUrl = $"https://%s{gitOwner}.github.io/%s{gitRepoName}" +let releaseBranch = "main" let readme = "README.md" let changelogFile = "CHANGELOG.md" @@ -87,6 +96,53 @@ let githubToken = Environment.environVarOrNone "GITHUB_TOKEN" let nugetToken = Environment.environVarOrNone "NUGET_TOKEN" +//----------------------------------------------------------------------------- +// Helpers +//----------------------------------------------------------------------------- + + +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 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 + + module dotnet = let watch cmdParam program args = DotNet.exec cmdParam (sprintf "watch %s" program) args diff --git a/build/build.fsproj b/build/build.fsproj index 3f5c4f9..86538f0 100644 --- a/build/build.fsproj +++ b/build/build.fsproj @@ -11,7 +11,6 @@ -