Skip to content

Commit 9143342

Browse files
committed
feat(ci): improve change log reading
1 parent 50554cd commit 9143342

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

build/Changelog.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ let getVersionNumber envVarName ctx =
101101

102102
failwith "Invalid version number"
103103

104-
let mutable changelogBackupFilename = ""
105-
106104
let updateChangelog changelogPath (changelog : Fake.Core.Changelog.Changelog) gitHubRepoUrl ctx =
107105

108106
let verStr = ctx |> getVersionNumber "RELEASE_VERSION"
@@ -174,7 +172,7 @@ let updateChangelog changelogPath (changelog : Fake.Core.Changelog.Changelog) gi
174172
Changelog.Changelog.New (changelog.Header, changelog.Description, None, newEntry :: changelog.Entries)
175173

176174
// Save changelog to temporary file before making any edits
177-
changelogBackupFilename <- System.IO.Path.GetTempFileName ()
175+
let changelogBackupFilename = System.IO.Path.GetTempFileName ()
178176

179177
changelogPath |> Shell.copyFile changelogBackupFilename
180178

@@ -230,4 +228,4 @@ let updateChangelog changelogPath (changelog : Fake.Core.Changelog.Changelog) gi
230228
// If build fails after this point but before we commit changes, undo our modifications
231229
Target.activateBuildFailure "RevertChangelog"
232230

233-
newEntry
231+
(newEntry, changelogBackupFilename)

build/build.fs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ let CHANGELOGlink = Uri (Uri (gitHubRepoUrl), $"blob/{releaseBranch}/{changelogF
7777

7878
let changelogPath = rootDirectory </> changelogFile
7979

80-
let changelog = Fake.Core.Changelog.load changelogPath
80+
let changelog = lazy (Fake.Core.Changelog.load changelogPath)
8181

8282
let mutable latestEntry =
83-
if Seq.isEmpty changelog.Entries then
83+
if Seq.isEmpty changelog.Value.Entries then
8484
Changelog.ChangelogEntry.New ("0.0.1", "0.0.1-alpha.1", Some DateTime.Today, None, [], false)
8585
else
86-
changelog.LatestEntry
86+
changelog.Value.LatestEntry
8787

88-
let mutable changelogBackupFilename = ""
88+
let mutable changelogBackupFilename : string voption = ValueNone
8989

9090
let publishUrl = "https://www.nuget.org"
9191

@@ -303,34 +303,37 @@ let dotnetToolRestore _ =
303303
failwithf "Failed to restore .NET tools: %A" result.Errors
304304

305305
let updateChangelog ctx =
306-
latestEntry <-
306+
let newEntry, backupFilename =
307307
if not <| isPublishToGitHub ctx then
308-
Changelog.updateChangelog changelogPath changelog gitHubRepoUrl ctx
309-
elif Seq.isEmpty changelog.Entries then
310-
latestEntry
308+
let newEntry, backupFilename = Changelog.updateChangelog changelogPath changelog.Value gitHubRepoUrl ctx
309+
(newEntry, ValueSome backupFilename)
310+
elif Seq.isEmpty changelog.Value.Entries then
311+
(latestEntry, ValueNone)
311312
else
312-
let latest = changelog.LatestEntry
313+
let latest = changelog.Value.LatestEntry
313314
let semVer = {
314315
latest.SemVer with
315316
Original = None
316317
Patch = latest.SemVer.Patch + 1u
317318
PreRelease = PreRelease.TryParse "ci"
318319
}
319-
{
320+
let entry = {
320321
latest with
321322
SemVer = semVer
322323
NuGetVersion = semVer.AsString
323324
AssemblyVersion = semVer.AsString
324325
}
326+
(entry, ValueNone)
327+
328+
latestEntry <- newEntry
329+
changelogBackupFilename <- backupFilename
325330

326331
let revertChangelog _ =
327-
if String.isNotNullOrEmpty Changelog.changelogBackupFilename then
328-
Changelog.changelogBackupFilename
329-
|> Shell.copyFile changelogPath
332+
changelogBackupFilename |> ValueOption.iter (Shell.copyFile changelogPath)
330333

331334
let deleteChangelogBackupFile _ =
332-
if String.isNotNullOrEmpty Changelog.changelogBackupFilename then
333-
Shell.rm Changelog.changelogBackupFilename
335+
changelogBackupFilename |> ValueOption.iter Shell.rm
336+
changelogBackupFilename <- ValueNone
334337

335338
let getPackageVersionProperty publishToGitHub =
336339
if publishToGitHub then
@@ -491,7 +494,7 @@ let generateAssemblyInfo _ =
491494

492495
let dotnetPack ctx =
493496
// Get release notes with properly-linked version number
494-
let releaseNotes = Changelog.mkReleaseNotes changelog latestEntry gitHubRepoUrl
497+
let releaseNotes = Changelog.mkReleaseNotes changelog.Value latestEntry gitHubRepoUrl
495498

496499
let args = [ getPackageVersionProperty (isPublishToGitHub ctx); $"/p:PackageReleaseNotes=\"{releaseNotes}\"" ]
497500

@@ -573,7 +576,7 @@ let githubRelease _ =
573576

574577
let files = !!distGlob
575578
// Get release notes with properly-linked version number
576-
let releaseNotes = Changelog.mkReleaseNotes changelog latestEntry gitHubRepoUrl
579+
let releaseNotes = Changelog.mkReleaseNotes changelog.Value latestEntry gitHubRepoUrl
577580

578581
GitHub.createClientWithToken token
579582
|> GitHub.draftNewRelease

0 commit comments

Comments
 (0)