Skip to content

Commit

Permalink
fix: mutation comment during update (#705)
Browse files Browse the repository at this point in the history
When the mutation comment is updated, it adds an incorrect string
  • Loading branch information
vbreuss authored Jan 10, 2025
1 parent 8959969 commit 2f6e114
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
5 changes: 3 additions & 2 deletions Pipeline/Build.CodeAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Build;

partial class Build
{
[Parameter("The key to push to sonarcloud")] [Secret] readonly string SonarToken;
[Parameter("The key to push to sonarcloud")] [Secret] readonly string? SonarToken;

Target CodeAnalysisBegin => _ => _
.Unlisted()
Expand All @@ -21,7 +21,7 @@ partial class Build
.AddVSTestReports(TestResultsDirectory / "*.trx")
.AddOpenCoverPaths(TestResultsDirectory / "reports" / "OpenCover.xml")
.SetPullRequestOrBranchName(GitHubActions, GitVersion)
.SetVersion(GitVersion.SemVer)
.SetVersion(GitVersion?.SemVer)
.SetToken(SonarToken));
});

Expand All @@ -36,6 +36,7 @@ partial class Build
.SetToken(SonarToken));
});

// ReSharper disable once UnusedMember.Local
Target CodeAnalysis => _ => _
.DependsOn(CodeAnalysisBegin)
.DependsOn(CodeAnalysisEnd);
Expand Down
13 changes: 6 additions & 7 deletions Pipeline/Build.Compile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Nuke.Common.IO;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Utilities.Collections;
using Nuke.Components;
using Serilog;
using System;
using System.Linq;
Expand All @@ -15,15 +14,15 @@ namespace Build;

partial class Build
{
string SemVer;
string? SemVer;

Target CalculateNugetVersion => _ => _
.Unlisted()
.Executes(() =>
{
SemVer = GitVersion.SemVer;
SemVer = GitVersion?.SemVer;

if (GitHubActions?.IsPullRequest == true)
if (GitHubActions.IsPullRequest && GitVersion != null)
{
string buildNumber = GitHubActions.RunNumber.ToString();
Console.WriteLine(
Expand Down Expand Up @@ -73,8 +72,8 @@ partial class Build
.EnableNoLogo()
.EnableNoRestore()
.SetVersion(SemVer)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion));
.SetAssemblyVersion(GitVersion?.AssemblySemVer)
.SetFileVersion(GitVersion?.AssemblySemFileVer)
.SetInformationalVersion(GitVersion?.InformationalVersion));
});
}
10 changes: 5 additions & 5 deletions Pipeline/Build.MutationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ await gitHubClient.Issue.Comment.Update("Testably", "Testably.Abstractions",

foreach (KeyValuePair<Project, Project[]> project in projects)
{
string branchName = GitVersion.BranchName;
string? branchName = GitVersion?.BranchName;
if (GitHubActions?.Ref.StartsWith("refs/tags/",
StringComparison.OrdinalIgnoreCase) == true)
{
Expand All @@ -141,7 +141,7 @@ await gitHubClient.Issue.Comment.Update("Testably", "Testably.Abstractions",
"target-framework": "net8.0",
"since": {
"target": "main",
"enabled": {{(GitVersion.BranchName != "main").ToString().ToLowerInvariant()}},
"enabled": {{(GitVersion?.BranchName != "main").ToString().ToLowerInvariant()}},
"ignore-changes-in": [
"**/.github/**/*.*"
]
Expand Down Expand Up @@ -233,7 +233,7 @@ await gitHubClient.Issue.Comment.Update("Testably", "Testably.Abstractions",

foreach (KeyValuePair<Project, Project[]> project in projects)
{
string branchName = GitVersion.BranchName;
string? branchName = GitVersion?.BranchName;
if (GitHubActions?.Ref.StartsWith("refs/tags/",
StringComparison.OrdinalIgnoreCase) == true)
{
Expand All @@ -257,7 +257,7 @@ await gitHubClient.Issue.Comment.Update("Testably", "Testably.Abstractions",
"target-framework": "net8.0",
"since": {
"target": "main",
"enabled": {{(GitVersion.BranchName != "main").ToString().ToLowerInvariant()}},
"enabled": {{(GitVersion?.BranchName != "main").ToString().ToLowerInvariant()}},
"ignore-changes-in": [
"**/.github/**/*.*"
]
Expand Down Expand Up @@ -355,7 +355,7 @@ string ReplaceProject(string body, string project, string value)
if (startIndex >= 0 && endIndex > startIndex)
{
string prefix = body.Substring(0, startIndex);
string suffix = body.Substring(endIndex + 1);
string suffix = body.Substring(endIndex + $"<!-- END {project} -->".Length);
return prefix + value + suffix;
}

Expand Down
7 changes: 6 additions & 1 deletion Pipeline/Build.Pack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Utilities.Collections;
using Nuke.Components;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -20,6 +19,11 @@ partial class Build
.Before(Compile)
.Executes(() =>
{
if (GitVersion == null)
{
return;
}

string version = string.Join('.', GitVersion.SemVer.Split('.').Take(3));
if (version.IndexOf('-') != -1)
{
Expand Down Expand Up @@ -60,6 +64,7 @@ partial class Build
File.WriteAllText(ArtifactsDirectory / "README.md", sb.ToString());
});

// ReSharper disable once UnusedMember.Local
Target Pack => _ => _
.DependsOn(UpdateReadme)
.DependsOn(Compile)
Expand Down
7 changes: 4 additions & 3 deletions Pipeline/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ partial class Build : NukeBuild
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;

[Parameter("Github Token")] readonly string GithubToken;
[Parameter("Github Token")] readonly string? GithubToken;

[Required] [GitVersion(Framework = "net8.0", NoCache = true, NoFetch = true)] readonly GitVersion GitVersion;
[Required] [GitVersion(Framework = "net8.0", NoCache = true, NoFetch = true)] readonly GitVersion? GitVersion;

[Solution(GenerateProjects = true)] readonly Solution Solution;
[Solution(GenerateProjects = true)] readonly Solution Solution = null!;

AbsolutePath ArtifactsDirectory => RootDirectory / "Artifacts";
AbsolutePath TestResultsDirectory => RootDirectory / "TestResults";
Expand All @@ -30,5 +30,6 @@ partial class Build : NukeBuild
public static int Main() => Execute<Build>([
x => x.ApiChecks,
x => x.UnitTests,
x => x.MutationTests,
]);
}
1 change: 1 addition & 0 deletions Pipeline/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<TargetFramework>net8.0</TargetFramework>
<NoWarn>CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
Expand Down
8 changes: 4 additions & 4 deletions Pipeline/BuildExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public static class BuildExtensions
{
public static SonarScannerBeginSettings SetPullRequestOrBranchName(
this SonarScannerBeginSettings settings,
GitHubActions gitHubActions,
GitVersion gitVersion)
GitHubActions? gitHubActions,
GitVersion? gitVersion)
{
if (gitHubActions?.IsPullRequest == true)
{
Expand All @@ -30,7 +30,7 @@ public static SonarScannerBeginSettings SetPullRequestOrBranchName(
return settings.SetBranchName(branchName);
}

Log.Information("Use branch analysis for '{BranchName}'", gitVersion.BranchName);
return settings.SetBranchName(gitVersion.BranchName);
Log.Information("Use branch analysis for '{BranchName}'", gitVersion?.BranchName);
return settings.SetBranchName(gitVersion?.BranchName);
}
}

0 comments on commit 2f6e114

Please sign in to comment.