Skip to content

Commit 68dd86b

Browse files
authored
Merge pull request #7094 from valadas/harmonize-versioning
Prevent noisy PRs for SolutionInfo.cs version changes
2 parents c5af539 + c88d6db commit 68dd86b

3 files changed

Lines changed: 51 additions & 4 deletions

File tree

Build/Tasks/CreateGitHubPullRequest.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace DotNetNuke.Build.Tasks
1111
using System.Net.Http.Headers;
1212
using System.Security.Cryptography;
1313
using System.Text;
14+
using System.Text.RegularExpressions;
1415

1516
using Cake.Common;
1617
using Cake.Common.Diagnostics;
@@ -47,6 +48,7 @@ public sealed class CreateGitHubPullRequest : FrostingTask<Context>
4748
{
4849
private const string TargetBranch = "develop";
4950
private const string BugReportPath = ".github/ISSUE_TEMPLATE/bug-report.yml";
51+
private const string SolutionInfoPath = "SolutionInfo.cs";
5052
private const string GitUserName = "DNN Platform CI Bot";
5153
private const string GitUserEmail = "noreply@dnncommunity.org";
5254

@@ -101,6 +103,10 @@ public override void Run(Context context)
101103
// Update bug-report.yml with version info from GitHub releases
102104
UpdateBugReportVersions(context, client, owner, repo);
103105

106+
// Reset SolutionInfo.cs if only the commit count/SHA changed (not the major.minor.patch)
107+
// to avoid creating a PR for every single commit.
108+
ResetSolutionInfoIfVersionUnchanged(context);
109+
104110
// Only proceed with the PR if there are actual changes
105111
if (!HasUncommittedChanges(context))
106112
{
@@ -377,6 +383,48 @@ private static bool HasUncommittedChanges(ICakeContext context)
377383
return output.Count > 0;
378384
}
379385

386+
private static void ResetSolutionInfoIfVersionUnchanged(Context context)
387+
{
388+
var committedProcess = context.StartAndReturnProcess(
389+
"git",
390+
new ProcessSettings
391+
{
392+
Arguments = $"show HEAD:{SolutionInfoPath}",
393+
RedirectStandardOutput = true,
394+
});
395+
committedProcess.WaitForExit();
396+
397+
if (committedProcess.GetExitCode() != 0)
398+
{
399+
context.Information("Could not read committed {0}, skipping reset check.", SolutionInfoPath);
400+
return;
401+
}
402+
403+
var committedContent = string.Join("\n", committedProcess.GetStandardOutput());
404+
var currentContent = File.ReadAllText(SolutionInfoPath);
405+
406+
var committedVersion = ExtractAssemblyVersion(committedContent);
407+
var currentVersion = ExtractAssemblyVersion(currentContent);
408+
409+
context.Information("SolutionInfo.cs AssemblyVersion — committed: '{0}', current: '{1}'.", committedVersion, currentVersion);
410+
411+
if (string.Equals(committedVersion, currentVersion, StringComparison.Ordinal))
412+
{
413+
context.Information("Major.Minor.Patch has not changed. Resetting {0} to avoid a noisy PR.", SolutionInfoPath);
414+
Git(context, $"checkout -- {SolutionInfoPath}");
415+
}
416+
else
417+
{
418+
context.Information("Major.Minor.Patch changed ({0} → {1}). Keeping {2} modifications.", committedVersion, currentVersion, SolutionInfoPath);
419+
}
420+
}
421+
422+
private static string ExtractAssemblyVersion(string content)
423+
{
424+
var match = Regex.Match(content, @"\[assembly:\s*AssemblyVersion\(""([^""]+)""\)\]");
425+
return match.Success ? match.Groups[1].Value : string.Empty;
426+
}
427+
380428
private static void Git(ICakeContext context, string arguments, bool redactOutput = false)
381429
{
382430
context.Information("git {0}", redactOutput ? "[redacted]" : arguments);

Build/Tasks/SetPackageVersions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public override void Run(Context context)
3232
// Set all package.json in Admin Experience to the current version and to consume the current (local) version of dnn-react-common.
3333
foreach (var file in packages)
3434
{
35-
context.Information($"Updating {file} to version {context.Version.FullSemVer}");
35+
context.Information($"Updating {file} to version {context.Version.SemVer}");
3636
context.ReplaceRegexInFiles(
3737
file.ToString(),
3838
@"""version"": "".*""",
39-
$@"""version"": ""{context.Version.FullSemVer}""");
39+
$@"""version"": ""{context.Version.SemVer}""");
4040
context.ReplaceRegexInFiles(
4141
file.ToString(),
4242
@"""@dnnsoftware\/dnn-react-common"": "".*""",
43-
$@"""@dnnsoftware/dnn-react-common"": ""{context.Version.FullSemVer}""");
43+
$@"""@dnnsoftware/dnn-react-common"": ""{context.Version.SemVer}""");
4444
}
4545
}
4646
}

Build/Tasks/SetVersion.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace DotNetNuke.Build.Tasks
55
{
66
using System;
7-
using System.Linq;
87

98
using Cake.Common.Diagnostics;
109
using Cake.Common.Tools.GitVersion;

0 commit comments

Comments
 (0)