Skip to content

Commit

Permalink
Revert "ci: fix retrieving version for publishing to GitHub"
Browse files Browse the repository at this point in the history
This reverts commit b7df595.
  • Loading branch information
xperiandri committed Nov 22, 2024
1 parent b7df595 commit f9fdff4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 75 deletions.
17 changes: 7 additions & 10 deletions build/Changelog.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Changelog
open System
open Fake.Core
open Fake.IO
open Helpers

let isEmptyChange =
function
Expand Down Expand Up @@ -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 "")

Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
63 changes: 0 additions & 63 deletions build/Helpers.fs

This file was deleted.

58 changes: 57 additions & 1 deletion build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion build/build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</ItemGroup>

<ItemGroup>
<Compile Include="Helpers.fs" />
<Compile Include="Changelog.fs" />
<Compile Include="FsDocs.fs" />
<Compile Include="build.fs" />
Expand Down

0 comments on commit f9fdff4

Please sign in to comment.