Skip to content

Commit

Permalink
Fix release notes (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
Smaug123 authored Feb 25, 2024
1 parent c403e47 commit 00a69b8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
31 changes: 31 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project>
<UsingTask TaskName="Base64Decode" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<EncodedString ParameterType="System.String" Required="true" />
<DecodedString Output="true" ParameterType="System.String" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.Text" />
<Code Type="Fragment" Language="cs">
<![CDATA[
DecodedString = Encoding.UTF8.GetString(Convert.FromBase64String(EncodedString));
]]>
</Code>
</Task>
</UsingTask>

<!-- This is the decode end of the base64-encoding that gets the release notes into `dotnet pack`.
The problem is that we can't supply MsBuild properties that contain MsBuild metacharacters.
(At least, I don't know how.)
The release notes are liable to contain MsBuild property metacharacters, such as the comma;
so just before we `dotnet pack`, we base64-encode it. -->
<Target Name="DecodeReleaseNotes" BeforeTargets="GenerateNuspec">
<Base64Decode EncodedString="$(RELEASE_NOTES)">
<Output TaskParameter="DecodedString" PropertyName="DecodedReleaseNotes" />
</Base64Decode>
<PropertyGroup>
<PackageReleaseNotes>$(DecodedReleaseNotes)</PackageReleaseNotes>
</PropertyGroup>
</Target>
</Project>
14 changes: 12 additions & 2 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,23 @@ Target.create "RunTests" (fun _ ->
// --------------------------------------------------------------------------------------
// Build a NuGet package

let base64 (s : string) =
Convert.ToBase64String (Encoding.UTF8.GetBytes s)

type HavePacked = HavePacked
let packNuGet (_ : HaveTested) : HavePacked =
Console.Write "Performing dotnet pack... "
let releaseNotes =
releaseNotes.Notes
|> String.concat "\n"
runProcess "dotnet" ["pack" ; "--configuration" ; "Release" ; $"-p:Version=%s{buildVersion}" ; "--output" ; "bin" ; $"-p:PackageReleaseNotes=%s{releaseNotes}"]
// MsBuild will interpret some characters, apparently including the comma.
// To work around this, we pass it in base64-encoded, and pick it up on the other side.
|> base64
let env = ["RELEASE_NOTES", releaseNotes ; "BUILD_VERSION", buildVersion ] |> Map.ofList
if RuntimeInformation.IsOSPlatform OSPlatform.Windows then
runProcessWithEnv env "cmd" ["/c" ; "dotnet pack --configuration Release -p:Version=%BUILD_VERSION% --output bin -p:RELEASE_NOTES=%RELEASE_NOTES%"]
else
runProcessWithEnv env "sh" ["-c" ; "dotnet pack --configuration Release -p:Version=\"$BUILD_VERSION\" --output bin -p:RELEASE_NOTES=\"$RELEASE_NOTES\""]

// I *believe* it is impossible to have a fixed (not floating) version number from a source reference
// via `dotnet pack`. Without this next bit, FsCheck.Xunit vA.B.C depends on >= FsCheck vA.B.C, not
Expand Down Expand Up @@ -401,7 +411,7 @@ let pushNuGet (_ : HaveTested) (_ : HavePacked) =
if RuntimeInformation.IsOSPlatform OSPlatform.Windows then
runProcessWithEnv env "cmd" ["/c" ; $"dotnet nuget push %s{package} --api-key %%NUGET_KEY%% --source https://api.nuget.org/v3/index.json"]
else
runProcessWithEnv env "sh" ["-c" ; $"dotnet nuget push %s{package} --api-key $NUGET_KEY --source https://api.nuget.org/v3/index.json"]
runProcessWithEnv env "sh" ["-c" ; $"dotnet nuget push %s{package} --api-key \"$NUGET_KEY\" --source https://api.nuget.org/v3/index.json"]
Console.WriteLine "done."
HavePushed

Expand Down

0 comments on commit 00a69b8

Please sign in to comment.