Skip to content

Commit 8b7855c

Browse files
committed
(build) fixes to allow building from release branch
1 parent 599a412 commit 8b7855c

File tree

6 files changed

+42
-22
lines changed

6 files changed

+42
-22
lines changed

build/build/Tasks/Test/PublishCoverage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public override bool ShouldRun(BuildContext context)
1212
{
1313
var shouldRun = true;
1414
shouldRun &= context.ShouldRun(context.IsOnWindows, $"{nameof(PublishCoverage)} works only on Windows agents.");
15-
shouldRun &= context.ShouldRun(context.IsOnMainBranchOriginalRepo, $"{nameof(PublishCoverage)} works only for on main branch original repository.");
15+
shouldRun &= context.ShouldRun(context.IsOnMainOrReleaseBranchOriginalRepo, $"{nameof(PublishCoverage)} works only for on main or release branch original repository.");
1616

1717
return shouldRun;
1818
}

build/common/Utilities/BuildContextBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ protected BuildContextBase(ICakeContext context) : base(context)
99

1010
public bool IsOriginalRepo { get; set; }
1111
public bool IsMainBranch { get; set; }
12+
public bool IsReleaseBranch { get; set; }
1213
public bool IsPullRequest { get; set; }
1314
public bool IsTagged { get; set; }
1415
public bool IsLocalBuild { get; set; }
@@ -17,7 +18,7 @@ protected BuildContextBase(ICakeContext context) : base(context)
1718
public bool IsOnWindows { get; set; }
1819
public bool IsOnLinux { get; set; }
1920
public bool IsOnMacOS { get; set; }
20-
public bool IsOnMainBranchOriginalRepo => !IsLocalBuild && IsOriginalRepo && IsMainBranch && !IsPullRequest;
21-
public bool IsStableRelease => IsOnMainBranchOriginalRepo && IsTagged;
22-
public bool IsPreRelease => IsOnMainBranchOriginalRepo && !IsTagged;
21+
public bool IsOnMainOrReleaseBranchOriginalRepo => !IsLocalBuild && IsOriginalRepo && (IsMainBranch || IsReleaseBranch) && !IsPullRequest;
22+
public bool IsStableRelease => IsOnMainOrReleaseBranchOriginalRepo && IsTagged;
23+
public bool IsPreRelease => IsOnMainOrReleaseBranchOriginalRepo && !IsTagged;
2324
}

build/common/Utilities/BuildLifetimeBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public override void Setup(T context)
1515
context.IsPullRequest = buildSystem.IsPullRequest;
1616
context.IsOriginalRepo = context.IsOriginalRepo();
1717
context.IsMainBranch = context.IsMainBranch();
18+
context.IsReleaseBranch = context.IsReleaseBranch();
1819
context.IsTagged = context.IsTagged();
1920

2021
context.IsOnWindows = context.IsRunningOnWindows();
@@ -38,6 +39,7 @@ public override void Teardown(T context, ITeardownContext info)
3839
context.Information("Pull Request: {0}", context.IsPullRequest);
3940
context.Information("Original Repo: {0}", context.IsOriginalRepo);
4041
context.Information("Main Branch: {0}", context.IsMainBranch);
42+
context.Information("Release Branch: {0}", context.IsReleaseBranch);
4143
context.Information("Tagged: {0}", context.IsTagged);
4244

4345
context.Information("Finished running tasks.");
@@ -60,6 +62,7 @@ protected void LogBuildInformation(T context)
6062
context.Information("Pull Request: {0}", context.IsPullRequest);
6163
context.Information("Original Repo: {0}", context.IsOriginalRepo);
6264
context.Information("Main Branch: {0}", context.IsMainBranch);
65+
context.Information("Release Branch: {0}", context.IsReleaseBranch);
6366
context.Information("Tagged: {0}", context.IsTagged);
6467
}
6568
}

build/common/Utilities/ContextExtensions.cs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,22 @@ public static bool IsOriginalRepo(this ICakeContext context)
7373

7474
public static bool IsMainBranch(this ICakeContext context)
7575
{
76-
var buildSystem = context.BuildSystem();
77-
string repositoryBranch = context.ExecGitCmd("rev-parse --abbrev-ref HEAD").Single();
78-
if (buildSystem.IsRunningOnAppVeyor)
79-
{
80-
repositoryBranch = buildSystem.AppVeyor.Environment.Repository.Branch;
81-
}
82-
else if (buildSystem.IsRunningOnAzurePipelines)
83-
{
84-
repositoryBranch = buildSystem.AzurePipelines.Environment.Repository.SourceBranchName;
85-
}
86-
else if (buildSystem.IsRunningOnGitHubActions)
87-
{
88-
repositoryBranch = buildSystem.GitHubActions.Environment.Workflow.Ref.Replace("refs/heads/", "");
89-
}
76+
var repositoryBranch = GetBranchName(context);
9077

9178
context.Information("Repository Branch: {0}", repositoryBranch);
9279

9380
return !string.IsNullOrWhiteSpace(repositoryBranch) && StringComparer.OrdinalIgnoreCase.Equals("main", repositoryBranch);
9481
}
9582

83+
public static bool IsReleaseBranch(this ICakeContext context)
84+
{
85+
var repositoryBranch = GetBranchName(context);
86+
87+
context.Information("Repository Branch: {0}", repositoryBranch);
88+
89+
return !string.IsNullOrWhiteSpace(repositoryBranch) && repositoryBranch.StartsWith("release/", StringComparison.OrdinalIgnoreCase);
90+
}
91+
9692
public static bool IsTagged(this ICakeContext context)
9793
{
9894
var sha = context.ExecGitCmd("rev-parse --verify HEAD").Single();
@@ -122,6 +118,7 @@ public static string GetOS(this ICakeContext context)
122118
if (context.IsRunningOnWindows()) return "Windows";
123119
if (context.IsRunningOnLinux()) return "Linux";
124120
if (context.IsRunningOnMacOs()) return "macOs";
121+
125122
return string.Empty;
126123
}
127124

@@ -174,4 +171,24 @@ public static bool ShouldRun(this ICakeContext context, bool criteria, string sk
174171
context.Information(skipMessage);
175172
return false;
176173
}
174+
175+
private static string GetBranchName(ICakeContext context)
176+
{
177+
178+
var buildSystem = context.BuildSystem();
179+
string repositoryBranch = context.ExecGitCmd("rev-parse --abbrev-ref HEAD").Single();
180+
if (buildSystem.IsRunningOnAppVeyor)
181+
{
182+
repositoryBranch = buildSystem.AppVeyor.Environment.Repository.Branch;
183+
}
184+
else if (buildSystem.IsRunningOnAzurePipelines)
185+
{
186+
repositoryBranch = buildSystem.AzurePipelines.Environment.Repository.SourceBranchName;
187+
}
188+
else if (buildSystem.IsRunningOnGitHubActions)
189+
{
190+
repositoryBranch = buildSystem.GitHubActions.Environment.Workflow.Ref.Replace("refs/heads/", "");
191+
}
192+
return repositoryBranch;
193+
}
177194
}

build/publish/Tasks/PublishNuget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override bool ShouldRun(BuildContext context)
2626
public override void Run(BuildContext context)
2727
{
2828
// publish to github packages for commits on main and on original repo
29-
if (context.IsGitHubActionsBuild && context.IsOnMainBranchOriginalRepo)
29+
if (context.IsGitHubActionsBuild && context.IsOnMainOrReleaseBranchOriginalRepo)
3030
{
3131
var apiKey = context.Credentials?.GitHub?.Token;
3232
if (string.IsNullOrEmpty(apiKey))

src/GitVersion.Core.Tests/Extensions/StringFormatWithExtensionTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ public class StringFormatWithExtensionTests
1616
public void FormatWithNoTokens()
1717
{
1818
var propertyObject = new { };
19-
const string target = "Some String without tokens";
20-
var expected = target;
21-
var actual = target.FormatWith(propertyObject, this.environment);
19+
const string expected = "Some String without tokens";
20+
var actual = expected.FormatWith(propertyObject, this.environment);
2221
Assert.AreEqual(expected, actual);
2322
}
2423

0 commit comments

Comments
 (0)