From a3b35e65ad5ee5e16947a0422b23043863d8299a Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Thu, 8 Feb 2024 18:31:19 +0100 Subject: [PATCH] Fix coverage. Publish coverage only on push --- src/dotnet-releaser/ReleaserApp.Configuring.cs | 2 ++ src/dotnet-releaser/ReleaserApp.Coverage.cs | 6 +++--- src/dotnet-releaser/ReleaserApp.Projects.cs | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dotnet-releaser/ReleaserApp.Configuring.cs b/src/dotnet-releaser/ReleaserApp.Configuring.cs index e4dcdcd..dbda49b 100644 --- a/src/dotnet-releaser/ReleaserApp.Configuring.cs +++ b/src/dotnet-releaser/ReleaserApp.Configuring.cs @@ -102,6 +102,8 @@ public partial class ReleaserApp return null; } + buildInformation.IsPush = gitHubInfo.EventName == "push"; + // Automatically convert a run into a publish if we have a release tag if (gitHubInfo.EventName == "push" && gitHubInfo.RefType == GitHubActionRefType.Tag) { diff --git a/src/dotnet-releaser/ReleaserApp.Coverage.cs b/src/dotnet-releaser/ReleaserApp.Coverage.cs index eccc751..86836b4 100644 --- a/src/dotnet-releaser/ReleaserApp.Coverage.cs +++ b/src/dotnet-releaser/ReleaserApp.Coverage.cs @@ -15,7 +15,7 @@ public partial class ReleaserApp { private async Task PublishCoverageToGist(IDevHosting devHosting, BuildInformation buildInfo, HitCoverage coverage) { - if (!_config.Coverage.BadgeUploadToGist) return; + if (!_config.Coverage.BadgeUploadToGist || !buildInfo.IsPush) return; var gistId = _config.Coverage.BadgeGistId; if (string.IsNullOrWhiteSpace(gistId)) @@ -24,7 +24,7 @@ private async Task PublishCoverageToGist(IDevHosting devHosting, BuildInformatio return; } - var rate = (int)(Math.Round((double)coverage.Rate) * 100); + var rate = (int)Math.Round((double)coverage.Rate * 100); var svg = $""" coveragecoverage{rate:##}%{rate:##}% """; @@ -36,7 +36,7 @@ private async Task PublishCoverageToGist(IDevHosting devHosting, BuildInformatio private async Task PublishCoveralls(IDevHosting devHosting, BuildInformation buildInfo) { - if (!_config.Coveralls.Publish || _assemblyCoverages.Count == 0) return; + if (!_config.Coveralls.Publish || _assemblyCoverages.Count == 0 || !buildInfo.IsPush) return; var ownerRepo = $"{devHosting.Configuration.User}/{devHosting.Configuration.Repo}"; diff --git a/src/dotnet-releaser/ReleaserApp.Projects.cs b/src/dotnet-releaser/ReleaserApp.Projects.cs index 5e1a8f6..02111d5 100644 --- a/src/dotnet-releaser/ReleaserApp.Projects.cs +++ b/src/dotnet-releaser/ReleaserApp.Projects.cs @@ -43,6 +43,8 @@ public BuildInformation(ProjectPackageInfoCollection[] projectPackageInfoCollect public bool PublishNuGet { get; set; } + public bool IsPush { get; set; } + public bool AllowPublishDraft { get; set; } public BuildKind BuildKind { get; set; }