Skip to content

Commit f9fdff4

Browse files
committed
Revert "ci: fix retrieving version for publishing to GitHub"
This reverts commit b7df595.
1 parent b7df595 commit f9fdff4

File tree

4 files changed

+64
-75
lines changed

4 files changed

+64
-75
lines changed

build/Changelog.fs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module Changelog
33
open System
44
open Fake.Core
55
open Fake.IO
6-
open Helpers
76

87
let isEmptyChange =
98
function
@@ -63,9 +62,10 @@ let mkReleaseNotes changelog (latestEntry : Changelog.ChangelogEntry) gitHubRepo
6362
{ latestEntry with Description = Some description }.ToString ()
6463

6564
let getVersionNumber envVarName ctx =
65+
let args = ctx.Context.Arguments
6666

6767
let verArg =
68-
ctx.Context.Arguments
68+
args
6969
|> List.tryHead
7070
|> Option.defaultWith (fun () -> Environment.environVarOrDefault envVarName "")
7171

@@ -100,24 +100,21 @@ let mutable changelogBackupFilename = ""
100100

101101
let updateChangelog changelogPath (changelog : Fake.Core.Changelog.Changelog) gitHubRepoUrl ctx =
102102

103-
let newVersion =
104-
if isPublishToGitHub ctx then
105-
changelog.LatestEntry.SemVer
106-
else
107-
ctx |> getVersionNumber "RELEASE_VERSION" |> SemVer.parse
108-
103+
let verStr = ctx |> getVersionNumber "RELEASE_VERSION"
109104

110105
let description, unreleasedChanges =
111106
match changelog.Unreleased with
112107
| None -> None, []
113108
| Some u -> u.Description, u.Changes
114109

110+
let newVersion = SemVer.parse verStr
111+
115112
changelog.Entries
116113
|> List.tryFind (fun entry -> entry.SemVer = newVersion)
117114
|> Option.iter (fun entry ->
118115
Trace.traceErrorfn
119116
"Version %s already exists in %s, released on %s"
120-
newVersion.AsString
117+
verStr
121118
changelogPath
122119
(if entry.Date.IsSome then
123120
entry.Date.Value.ToString ("yyyy-MM-dd")
@@ -131,7 +128,7 @@ let updateChangelog changelogPath (changelog : Fake.Core.Changelog.Changelog) gi
131128
|> Option.iter (fun entry ->
132129
Trace.traceErrorfn
133130
"You're trying to release version %s, but a later version %s already exists, released on %s"
134-
newVersion.AsString
131+
verStr
135132
entry.SemVer.AsString
136133
(if entry.Date.IsSome then
137134
entry.Date.Value.ToString ("yyyy-MM-dd")

build/Helpers.fs

Lines changed: 0 additions & 63 deletions
This file was deleted.

build/build.fs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ open Fake.Core.TargetOperators
99
open Fake.Api
1010
open Fake.BuildServer
1111
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
1321

1422
//-----------------------------------------------------------------------------
1523
// Metadata and Configuration
@@ -61,6 +69,7 @@ let gitHubRepoUrl = $"https://github.com/%s{gitOwner}/%s{gitRepoName}"
6169

6270
let documentationRootUrl = $"https://%s{gitOwner}.github.io/%s{gitRepoName}"
6371

72+
let releaseBranch = "main"
6473
let readme = "README.md"
6574
let changelogFile = "CHANGELOG.md"
6675

@@ -87,6 +96,53 @@ let githubToken = Environment.environVarOrNone "GITHUB_TOKEN"
8796

8897
let nugetToken = Environment.environVarOrNone "NUGET_TOKEN"
8998

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+
90146
module dotnet =
91147
let watch cmdParam program args = DotNet.exec cmdParam (sprintf "watch %s" program) args
92148

build/build.fsproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<Compile Include="Helpers.fs" />
1514
<Compile Include="Changelog.fs" />
1615
<Compile Include="FsDocs.fs" />
1716
<Compile Include="build.fs" />

0 commit comments

Comments
 (0)