Skip to content

Commit

Permalink
Update Fsproj PackageReleaseNotes when publishing a new version
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime committed Oct 29, 2023
1 parent 379f993 commit ab42348
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/Fable.Build/Publish.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,26 @@ let private publishNuget (fsprojDir : string) =
let changelogPath = Path.Combine(fsprojDir, "CHANGELOG.md")
let lastChangelogVersion =
Changelog.getLastVersion changelogPath
let lastVersion =
lastChangelogVersion
|> fun v -> v.Version.ToString()

let lastVersionBody =
ChangelogParser.Version.bodyAsMarkdown lastChangelogVersion

printfn $"Publishing: %s{fsprojDir}"

let nugetKey = Environment.GetEnvironmentVariable("FABLE_NUGET_KEY")

if nugetKey = null then
failwithf $"Missing FABLE_NUGET_KEY environment variable"

if Fsproj.needPublishing fsprojContent lastVersion then
let updatedFsprojContent =
fsprojContent
|> Fsproj.replaceVersion lastVersion
|> Fsproj.replacePackageReleaseNotes lastVersionBody

if Fsproj.needPublishing fsprojContent lastChangelogVersion then
let updatedFsprojContent = Fsproj.replaceVersion fsprojContent lastChangelogVersion
File.WriteAllText(fsprojPath, updatedFsprojContent)
let nupkgPath = Dotnet.pack fsprojDir
Dotnet.Nuget.push(nupkgPath, nugetKey)
Expand Down
12 changes: 11 additions & 1 deletion src/Fable.Build/Utils/Fsproj.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ let needPublishing (fsprojContent: string) (versionToCheck: string) =
currentVersion <> versionToCheck
| None -> failwith "Could not find <Version>...</Version> in fsproj file"

let replaceVersion (fsprojContent: string) (version: string) =
let replaceVersion (version: string) (fsprojContent: string) =
Regex.Replace(
fsprojContent,
Regex.VERSION,
(fun (m: Match) ->
$"<Version>{version}</Version>"
)
)

let replacePackageReleaseNotes (releaseNotes: string) (fsprojContent: string) =
Regex.Replace(
fsprojContent,
"<PackageReleaseNotes>.*?</PackageReleaseNotes>",
(fun (m: Match) ->
$"<PackageReleaseNotes>{releaseNotes}</PackageReleaseNotes>"
),
RegexOptions.Singleline
)

0 comments on commit ab42348

Please sign in to comment.