Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Store markdown & html release notes side by side in releases
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Aug 22, 2022
1 parent 1289317 commit c56e608
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 26 deletions.
7 changes: 4 additions & 3 deletions src/Squirrel.CommandLine/ReleasePackageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ void renderReleaseNotesMarkdown(string specPath, Func<string, string> releaseNot
var doc = new XmlDocument();
doc.Load(specPath);

// XXX: This code looks full tart
var metadata = doc.DocumentElement.ChildNodes
.OfType<XmlElement>()
.First(x => x.Name.ToLowerInvariant() == "metadata");
Expand All @@ -181,13 +180,15 @@ void renderReleaseNotesMarkdown(string specPath, Func<string, string> releaseNot
.OfType<XmlElement>()
.FirstOrDefault(x => x.Name.ToLowerInvariant() == "releasenotes");

if (releaseNotes == null) {
if (releaseNotes == null || String.IsNullOrWhiteSpace(releaseNotes.InnerText)) {
this.Log().Info("No release notes found in {0}", specPath);
return;
}

releaseNotes.InnerText = String.Format("<![CDATA[\n" + "{0}\n" + "]]>",
var releaseNotesHtml = doc.CreateElement("releaseNotesHtml");
releaseNotesHtml.InnerText = String.Format("<![CDATA[\n" + "{0}\n" + "]]>",
releaseNotesProcessor(releaseNotes.InnerText));
metadata.AppendChild(releaseNotesHtml);

doc.Save(specPath);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Squirrel.CommandLine/Sync/GitHubRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task UploadMissingPackages()
Log.Info($"Preparing to upload latest local release to GitHub");

var newReleaseReq = new NewRelease(semVer.ToString()) {
Body = "", // ver.GetReleaseNotes(releaseDirectoryInfo.FullName),
Body = ver.GetReleaseNotes(releaseDirectoryInfo.FullName, ReleaseNotesFormat.Markdown),
Draft = true,
Prerelease = semVer.HasMetadata || semVer.IsPrerelease,
Name = string.IsNullOrWhiteSpace(_options.releaseName)
Expand Down
4 changes: 4 additions & 0 deletions src/Squirrel/NuGet/NuspecManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal class NuspecManifest : IPackage
public SemanticVersion Version { get; private set; }
public Uri ProjectUrl { get; private set; }
public string ReleaseNotes { get; private set; }
public string ReleaseNotesHtml { get; private set; }
public Uri IconUrl { get; private set; }
public string Language { get; private set; }
public IEnumerable<string> Tags { get; private set; } = Enumerable.Empty<string>();
Expand Down Expand Up @@ -205,6 +206,9 @@ IEnumerable<string> getCommaDelimitedValue(string v)
case "runtimeDependencies":
RuntimeDependencies = getCommaDelimitedValue(value);
break;
case "releaseNotesHtml":
ReleaseNotesHtml = value;
break;
}
}

Expand Down
26 changes: 18 additions & 8 deletions src/Squirrel/ReleaseEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

namespace Squirrel
{
/// <summary>
/// Describes the requested release notes text format.
/// </summary>
public enum ReleaseNotesFormat
{
/// <summary> The original markdown release notes. </summary>
Markdown = 0,
/// <summary> Release notes translated into HTML. </summary>
Html = 1,
}

/// <summary>
/// Represents a Squirrel release, as described in a RELEASES file - usually also with an
/// accompanying package containing the files needed to apply the release.
Expand Down Expand Up @@ -51,7 +62,7 @@ public interface IReleaseEntry
/// Given a local directory containing a package corresponding to this release, returns the
/// correspoding release notes from within the package.
/// </summary>
string GetReleaseNotes(string packageDirectory);
string GetReleaseNotes(string packageDirectory, ReleaseNotesFormat format);

/// <summary>
/// Given a local directory containing a package corresponding to this release,
Expand Down Expand Up @@ -118,15 +129,14 @@ public string EntryAsString {
public string PackageName { get; }

/// <inheritdoc />
public string GetReleaseNotes(string packageDirectory)
public string GetReleaseNotes(string packageDirectory, ReleaseNotesFormat format)
{
var zp = new ZipPackage(Path.Combine(packageDirectory, Filename));

if (String.IsNullOrWhiteSpace(zp.ReleaseNotes)) {
throw new Exception(String.Format("Invalid 'ReleaseNotes' value in nuspec file at '{0}'", Path.Combine(packageDirectory, Filename)));
}

return zp.ReleaseNotes;
return format switch {
ReleaseNotesFormat.Markdown => zp.ReleaseNotes,
ReleaseNotesFormat.Html => zp.ReleaseNotesHtml,
_ => null,
};
}

/// <inheritdoc />
Expand Down
4 changes: 2 additions & 2 deletions src/Squirrel/UpdateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ protected UpdateInfo(ReleaseEntry currentlyInstalledVersion, IEnumerable<Release
/// <summary>
/// Retrieves all the release notes for pending packages (ie. <see cref="ReleasesToApply"/>)
/// </summary>
public Dictionary<ReleaseEntry, string> FetchReleaseNotes()
public Dictionary<ReleaseEntry, string> FetchReleaseNotes(ReleaseNotesFormat format)
{
return ReleasesToApply
.SelectMany(x => {
try {
var releaseNotes = x.GetReleaseNotes(PackageDirectory);
var releaseNotes = x.GetReleaseNotes(PackageDirectory, format);
return EnumerableExtensions.Return(Tuple.Create(x, releaseNotes));
} catch (Exception ex) {
this.Log().WarnException("Couldn't get release notes for:" + x.Filename, ex);
Expand Down
5 changes: 2 additions & 3 deletions src/Update.Windows/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ static async Task<string> Download(string updateUrl)
using var mgr = new UpdateManager(updateUrl);
var updateInfo = await mgr.CheckForUpdate(intention: UpdaterIntention.Update, progress: x => Console.WriteLine(x / 3));
await mgr.DownloadReleases(updateInfo.ReleasesToApply, x => Console.WriteLine(33 + x / 3));

var releaseNotes = updateInfo.FetchReleaseNotes();
var releaseNotes = updateInfo.FetchReleaseNotes(ReleaseNotesFormat.Html);

var sanitizedUpdateInfo = new {
currentVersion = updateInfo.LatestLocalReleaseEntry.Version.ToString(),
Expand All @@ -359,7 +358,7 @@ static async Task<string> CheckForUpdate(string updateUrl)
Log.Info("Fetching update information, downloading from " + updateUrl);
using var mgr = new UpdateManager(updateUrl);
var updateInfo = await mgr.CheckForUpdate(intention: UpdaterIntention.Update, progress: x => Console.WriteLine(x));
var releaseNotes = updateInfo.FetchReleaseNotes();
var releaseNotes = updateInfo.FetchReleaseNotes(ReleaseNotesFormat.Html);

var sanitizedUpdateInfo = new {
currentVersion = updateInfo.LatestLocalReleaseEntry.Version.ToString(),
Expand Down
9 changes: 0 additions & 9 deletions test/Squirrel.Tests/ReleaseEntryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public void ParseStagingPercentageTest(string releaseEntry, int major, int minor
}
}


[Fact]
public void CanParseGeneratedReleaseEntryAsString()
{
Expand All @@ -163,14 +162,6 @@ public void CanParseGeneratedReleaseEntryAsString()
ReleaseEntry.ParseReleaseEntry(entryAsString);
}

[Fact]
public void InvalidReleaseNotesThrowsException()
{
var path = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0.nupkg");
var fixture = ReleaseEntry.GenerateFromFile(path);
Assert.Throws<Exception>(() => fixture.GetReleaseNotes(IntegrationTestHelper.GetPath("fixtures")));
}

[Fact]
public void GetLatestReleaseWithNullCollectionReturnsNull()
{
Expand Down

0 comments on commit c56e608

Please sign in to comment.