Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GitTools/GitVersion
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.10.0
Choose a base ref
...
head repository: GitTools/GitVersion
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5.10.1
Choose a head ref
  • 2 commits
  • 11 files changed
  • 1 contributor

Commits on Apr 14, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4cdea84 View commit details
  2. Merge pull request #3085 from GitTools/revert-3033-main

    Revert "Use GITHUB_REF only for CI builds on branches"
    arturcic authored Apr 14, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b17d33e View commit details
39 changes: 0 additions & 39 deletions src/GitVersion.Core.Tests/BuildAgents/AzurePipelinesTests.cs
Original file line number Diff line number Diff line change
@@ -80,43 +80,4 @@ public void AzurePipelinesBuildNumberWithSemVer(string buildNumberFormat, string
var logMessage = this.buildServer.GenerateSetVersionMessage(vars);
logMessage.ShouldBe(logPrefix + expectedBuildNumber);
}

[Test]
public void GetCurrentBranchShouldHandleBranches()
{
// Arrange
this.environment.SetEnvironmentVariable("BUILD_SOURCEBRANCH", $"refs/heads/{MainBranch}");

// Act
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBe($"refs/heads/{MainBranch}");
}

[Test]
public void GetCurrentBranchShouldHandleTags()
{
// Arrange
this.environment.SetEnvironmentVariable("BUILD_SOURCEBRANCH", "refs/tags/1.0.0");

// Act
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBeNull();
}

[Test]
public void GetCurrentBranchShouldHandlePullRequests()
{
// Arrange
this.environment.SetEnvironmentVariable("BUILD_SOURCEBRANCH", "refs/pull/1/merge");

// Act
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBeNull();
}
}
2 changes: 1 addition & 1 deletion src/GitVersion.Core.Tests/BuildAgents/BuildKiteTests.cs
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ public void GetCurrentBranchShouldHandlePullRequests()
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBeNull();
result.ShouldBe("refs/pull/55/head");
}

[Test]
26 changes: 0 additions & 26 deletions src/GitVersion.Core.Tests/BuildAgents/CodeBuildTests.cs
Original file line number Diff line number Diff line change
@@ -102,30 +102,4 @@ private void AssertVariablesAreWrittenToFile(string file)
props.ShouldContain("GitVersion_Major=1");
props.ShouldContain("GitVersion_Minor=2");
}

[Test]
public void GetCurrentBranchShouldHandleTags()
{
// Arrange
this.environment.SetEnvironmentVariable("CODEBUILD_WEBHOOK_HEAD_REF", "refs/tags/1.0.0");

// Act
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBeNull();
}

[Test]
public void GetCurrentBranchShouldHandlePullRequests()
{
// Arrange
this.environment.SetEnvironmentVariable("CODEBUILD_SOURCE_VERSION", "refs/pull/1/merge");

// Act
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBeNull();
}
}
4 changes: 2 additions & 2 deletions src/GitVersion.Core.Tests/BuildAgents/GitHubActionsTests.cs
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ public void GetCurrentBranchShouldHandleTags()
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBeNull();
result.ShouldBe("refs/tags/1.0.0");
}

[Test]
@@ -96,7 +96,7 @@ public void GetCurrentBranchShouldHandlePullRequests()
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBeNull();
result.ShouldBe("refs/pull/1/merge");
}

[Test]
7 changes: 4 additions & 3 deletions src/GitVersion.Core.Tests/BuildAgents/SpaceAutomationTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using GitVersion;
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Shouldly;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersionCore.Tests.BuildAgents;

[TestFixture]
public class SpaceAutomationTests : TestBase
@@ -70,7 +71,7 @@ public void GetCurrentBranchShouldHandleTags()
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBeNull();
result.ShouldBe("refs/tags/1.0.0");
}

[Test]
@@ -83,7 +84,7 @@ public void GetCurrentBranchShouldHandlePullRequests()
var result = this.buildServer.GetCurrentBranch(false);

// Assert
result.ShouldBeNull();
result.ShouldBe("refs/pull/1/merge");
}

[Test]
12 changes: 1 addition & 11 deletions src/GitVersion.Core/BuildAgents/AzurePipelines.cs
Original file line number Diff line number Diff line change
@@ -21,17 +21,7 @@ public override string[] GenerateSetParameterMessage(string name, string value)
$"##vso[task.setvariable variable=GitVersion.{name};isOutput=true]{value}"
};

public override string? GetCurrentBranch(bool usingDynamicRepos)
{
// https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables
// BUILD_SOURCEBRANCH does not contain the branch name if the build was triggered by a tag or pull request.
string? branchName = Environment.GetEnvironmentVariable("BUILD_SOURCEBRANCH");
if (branchName != null && branchName.StartsWith("refs/heads/"))
{
return branchName;
}
return null;
}
public override string? GetCurrentBranch(bool usingDynamicRepos) => Environment.GetEnvironmentVariable("BUILD_SOURCEBRANCH");

public override bool PreventFetch() => true;

6 changes: 3 additions & 3 deletions src/GitVersion.Core/BuildAgents/BuildKite.cs
Original file line number Diff line number Diff line change
@@ -30,9 +30,9 @@ public override string[] GenerateSetParameterMessage(string name, string value)
}
else
{
// To align the behavior with the other BuildAgent implementations
// we return here also null.
return null;
// For pull requests BUILDKITE_BRANCH refers to the head, so adjust the
// branch name for pull request versioning to function as expected
return string.Format("refs/pull/{0}/head", pullRequest);
}
}

14 changes: 3 additions & 11 deletions src/GitVersion.Core/BuildAgents/CodeBuild.cs
Original file line number Diff line number Diff line change
@@ -25,17 +25,9 @@ public override string[] GenerateSetParameterMessage(string name, string value)

public override string? GetCurrentBranch(bool usingDynamicRepos)
{
string? branchName = Environment.GetEnvironmentVariable(WebHookEnvironmentVariableName);
if (string.IsNullOrEmpty(branchName))
{
branchName = Environment.GetEnvironmentVariable(SourceVersionEnvironmentVariableName);
}

if (branchName != null && branchName.StartsWith("refs/heads/"))
{
return branchName;
}
return null;
var currentBranch = Environment.GetEnvironmentVariable(WebHookEnvironmentVariableName);

return currentBranch.IsNullOrEmpty() ? Environment.GetEnvironmentVariable(SourceVersionEnvironmentVariableName) : currentBranch;
}

public override void WriteIntegration(Action<string?> writer, VersionVariables variables, bool updateBuildNumber = true)
13 changes: 1 addition & 12 deletions src/GitVersion.Core/BuildAgents/GitHubActions.cs
Original file line number Diff line number Diff line change
@@ -50,18 +50,7 @@ public override void WriteIntegration(Action<string?> writer, VersionVariables v
}
}

public override string? GetCurrentBranch(bool usingDynamicRepos)
{
// https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
// GITHUB_REF must be used only for "real" branches, not for tags and pull requests.
// Bug fix for https://github.com/GitTools/GitVersion/issues/2838
string? githubRef = Environment.GetEnvironmentVariable("GITHUB_REF");
if (githubRef != null && githubRef.StartsWith("refs/heads/"))
{
return githubRef;
}
return null;
}
public override string? GetCurrentBranch(bool usingDynamicRepos) => Environment.GetEnvironmentVariable("GITHUB_REF");

public override bool PreventFetch() => true;
}
4 changes: 1 addition & 3 deletions src/GitVersion.Core/BuildAgents/GitLabCi.cs
Original file line number Diff line number Diff line change
@@ -22,9 +22,7 @@ public override string[] GenerateSetParameterMessage(string name, string value)
$"GitVersion_{name}={value}"
};

// According to https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
// the CI_COMMIT_BRANCH environment variable must be used.
public override string? GetCurrentBranch(bool usingDynamicRepos) => Environment.GetEnvironmentVariable("CI_COMMIT_BRANCH");
public override string? GetCurrentBranch(bool usingDynamicRepos) => Environment.GetEnvironmentVariable("CI_COMMIT_REF_NAME");

public override bool PreventFetch() => true;

10 changes: 1 addition & 9 deletions src/GitVersion.Core/BuildAgents/SpaceAutomation.cs
Original file line number Diff line number Diff line change
@@ -13,15 +13,7 @@ public SpaceAutomation(IEnvironment environment, ILog log) : base(environment, l

protected override string EnvironmentVariable => EnvironmentVariableName;

public override string? GetCurrentBranch(bool usingDynamicRepos)
{
string? branchName = Environment.GetEnvironmentVariable("JB_SPACE_GIT_BRANCH");
if (branchName != null && branchName.StartsWith("refs/heads/"))
{
return branchName;
}
return null;
}
public override string? GetCurrentBranch(bool usingDynamicRepos) => Environment.GetEnvironmentVariable("JB_SPACE_GIT_BRANCH");

public override string[] GenerateSetParameterMessage(string name, string value) => Array.Empty<string>();