From 2b808d969288658911e60fb81bb5b1ff634be855 Mon Sep 17 00:00:00 2001 From: Fredi Kats Date: Sat, 18 May 2024 17:00:50 +0200 Subject: [PATCH] Split package publish and changelog publish --- src/dotnet-releaser/ReleaserApp.Publishing.cs | 46 ++++++++++++++++--- src/dotnet-releaser/ReleaserApp.cs | 10 +++- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/dotnet-releaser/ReleaserApp.Publishing.cs b/src/dotnet-releaser/ReleaserApp.Publishing.cs index 3d9f2c0..995be9e 100644 --- a/src/dotnet-releaser/ReleaserApp.Publishing.cs +++ b/src/dotnet-releaser/ReleaserApp.Publishing.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; using DotNetReleaser.Changelog; using DotNetReleaser.Configuration; @@ -6,8 +7,8 @@ namespace DotNetReleaser; public partial class ReleaserApp { - private async Task PublishPackagesAndChangelog(string? nugetApiToken, BuildInformation buildInformation, GitHubDevHostingConfiguration hostingConfiguration, - IDevHosting? devHosting, IDevHosting? devHostingExtra, ChangelogResult? changelog, bool forceUpload) + private async Task PublishPackages(string? nugetApiToken, BuildInformation buildInformation, GitHubDevHostingConfiguration hostingConfiguration, + IDevHosting? devHosting, IDevHosting? devHostingExtra) { bool groupStarted = false; try @@ -32,9 +33,6 @@ private async Task PublishPackagesAndChangelog(string? nugetApiToken, BuildInfor { var appPackagesToPublish = buildPackageInformation.AppPackages; - // In the case of a build, we still want to upload a draft release notes - await devHosting.UpdateChangelogAndUploadPackages(hostingConfiguration.User, hostingConfiguration.Repo, releaseVersion, changelog, appPackagesToPublish, _config.EnablePublishPackagesInDraft, forceUpload); - if (!HasErrors && _config.Brew.Publish) { // Log an error if we don't have an extra access for homebrew @@ -50,7 +48,7 @@ private async Task PublishPackagesAndChangelog(string? nugetApiToken, BuildInfor await devHostingExtra.UploadHomebrewFormula(hostingConfiguration.User, _config.Brew.Home, packageInfo, brewFormula); } } - + if (!HasErrors && _config.Scoop.Publish) { // Log an error if we don't have an extra access for homebrew @@ -77,4 +75,38 @@ private async Task PublishPackagesAndChangelog(string? nugetApiToken, BuildInfor } } } + + private async Task PublishChangelog(BuildInformation buildInformation, GitHubDevHostingConfiguration hostingConfiguration, + IDevHosting? devHosting, ChangelogResult? changelog, bool forceUpload) + { + bool groupStarted = false; + try + { + var buildKind = buildInformation.BuildKind; + var branchName = buildInformation.GitInformation?.BranchName; + var releaseVersion = new ReleaseVersion(buildInformation.Version, IsDraft: buildKind == BuildKind.Build, $"{hostingConfiguration.VersionPrefix}{buildInformation.Version}", branchName is not null ? $"draft-{branchName}" : "draft"); + + _logger.LogStartGroup($"Publishing Changelog - {releaseVersion}"); + groupStarted = true; + + if (!HasErrors && devHosting is not null && buildKind == BuildKind.Publish) + { + List appPackagesToPublish = new List(); + foreach (var (packageInfo, buildPackageInformation) in buildInformation.BuildPackages) + { + appPackagesToPublish.AddRange(buildPackageInformation.AppPackages); + } + + // In the case of a build, we still want to upload a draft release notes + await devHosting.UpdateChangelogAndUploadPackages(hostingConfiguration.User, hostingConfiguration.Repo, releaseVersion, changelog, appPackagesToPublish, _config.EnablePublishPackagesInDraft, forceUpload); + } + } + finally + { + if (groupStarted) + { + _logger.LogEndGroup(); + } + } + } } \ No newline at end of file diff --git a/src/dotnet-releaser/ReleaserApp.cs b/src/dotnet-releaser/ReleaserApp.cs index 01653e5..0390dfa 100644 --- a/src/dotnet-releaser/ReleaserApp.cs +++ b/src/dotnet-releaser/ReleaserApp.cs @@ -376,10 +376,18 @@ private async Task RunImpl(string configurationFile, BuildKind buildKind, // ------------------------------------------------------------------ // Publish all packages NuGet + (deb, zip, rpm, tar...) // ------------------------------------------------------------------ + if (buildInformation.BuildKind == BuildKind.Publish || buildInformation.PublishNuGet) + { + await PublishPackages(nugetApiToken, buildInformation, hostingConfiguration, devHosting, devHostingExtra); + } + + // ------------------------------------------------------------------ + // Publish changelog + // ------------------------------------------------------------------ // Draft if we are just building and not publishing (to allow to update the changelog) if (buildInformation.BuildKind == BuildKind.Publish || buildInformation.PublishNuGet) { - await PublishPackagesAndChangelog(nugetApiToken, buildInformation, hostingConfiguration, devHosting, devHostingExtra, changelog, forceUpload); + await PublishChangelog(buildInformation, hostingConfiguration, devHosting, changelog, forceUpload); } // ------------------------------------------------------------------