Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure DevOps] Leave the original Build Number when no GitVersion variable in Build Number #1770

Merged
merged 3 commits into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/input/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ Sets the format which will be used to format the `CommitDate` output variable.

The header for ignore configuration.

### update-build-number

Configures GitVersion to update the build number or not when running on a build server.

#### sha

A sequence of SHAs to be excluded from the version calculations. Useful when
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersionCore.Tests/BuildAgents/BuildServerBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public void BuildNumberIsFullSemVer()
buildServer.WriteIntegration(writes.Add, variables);

writes[1].ShouldBe("1.2.3-beta.1+5");

writes = new List<string>();
buildServer.WriteIntegration(writes.Add, variables, false);
writes.ShouldBeEmpty();
}

private class BuildAgent : BuildAgentBase
Expand Down
17 changes: 17 additions & 0 deletions src/GitVersionCore.Tests/BuildAgents/GitHubActionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ public void ShouldWriteIntegration()
.ShouldBe(string.Join(Environment.NewLine, expected));
}

[Test]
public void ShouldNotWriteIntegration()
{
// Arrange
var vars = new TestableVersionVariables("1.0.0");

var list = new List<string>();

// Assert
environment.GetEnvironmentVariable("GitVersion_Major").ShouldBeNullOrWhiteSpace();

// Act
buildServer.WriteIntegration(s => { list.Add(s); }, vars, false);

list.ShouldBeEmpty();
}

[Test]
public void GetEmptyGenerateSetVersionMessage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ ignore:
sha: []
commit-date-format: yyyy-MM-dd
merge-message-formats: {}
update-build-number: true
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ public TestEffectiveConfiguration(
IEnumerable<IVersionFilter> versionFilters = null,
bool tracksReleaseBranches = false,
bool isRelease = false,
string commitDateFormat = "yyyy-MM-dd") :
string commitDateFormat = "yyyy-MM-dd",
bool updateBuildNumber = false) :
base(assemblyVersioningScheme, assemblyFileVersioningScheme, assemblyInformationalFormat, assemblyVersioningFormat, assemblyFileVersioningFormat, versioningMode, gitTagPrefix, tag, nextVersion, IncrementStrategy.Patch,
branchPrefixToTrim, preventIncrementForMergedBranchVersion, tagNumberPattern, continuousDeploymentFallbackTag,
trackMergeTarget,
majorMessage, minorMessage, patchMessage, noBumpMessage,
commitMessageMode, legacySemVerPadding, buildMetaDataPadding, commitsSinceVersionSourcePadding,
versionFilters ?? Enumerable.Empty<IVersionFilter>(),
tracksReleaseBranches, isRelease, commitDateFormat, 0)
tracksReleaseBranches, isRelease, commitDateFormat, updateBuildNumber, 0)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/Model/CommitDateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void CommitDateFormatTest(string format, string expectedOutcome)
},
new EffectiveConfiguration(
AssemblyVersioningScheme.MajorMinorPatch, AssemblyFileVersioningScheme.MajorMinorPatch, "", "", "", VersioningMode.ContinuousDelivery, "", "", "", IncrementStrategy.Inherit,
"", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty<IVersionFilter>(), false, true, format, 0)
"", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty<IVersionFilter>(), false, true, format, false, 0)
);

Assert.That(formatValues.CommitDate, Is.EqualTo(expectedOutcome));
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore/BuildAgents/CodeBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override string GetCurrentBranch(bool usingDynamicRepos)
return Environment.GetEnvironmentVariable(EnvironmentVariableName);
}

public override void WriteIntegration(Action<string> writer, VersionVariables variables)
public override void WriteIntegration(Action<string> writer, VersionVariables variables, bool updateBuildNumber = true)
{
base.WriteIntegration(writer, variables);
writer($"Outputting variables to '{file}' ... ");
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore/BuildAgents/GitLabCi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override string GetCurrentBranch(bool usingDynamicRepos)

public override bool PreventFetch() => true;

public override void WriteIntegration(Action<string> writer, VersionVariables variables)
public override void WriteIntegration(Action<string> writer, VersionVariables variables, bool updateBuildNumber = true)
{
base.WriteIntegration(writer, variables);
writer($"Outputting variables to '{file}' ... ");
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore/BuildAgents/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override bool ShouldCleanUpRemotes()
return IsPipelineAsCode();
}

public override void WriteIntegration(Action<string> writer, VersionVariables variables)
public override void WriteIntegration(Action<string> writer, VersionVariables variables, bool updateBuildNumber = true)
{
base.WriteIntegration(writer, variables);
writer($"Outputting variables to '{file}' ... ");
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore/Common/IBuildAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace GitVersion
public interface IBuildAgent
{
bool CanApplyToCurrentContext();
void WriteIntegration(Action<string> writer, VersionVariables variables);
void WriteIntegration(Action<string> writer, VersionVariables variables, bool updateBuildNumber = true);
string GetCurrentBranch(bool usingDynamicRepos);
bool PreventFetch();
bool ShouldCleanUpRemotes();
Expand Down
3 changes: 3 additions & 0 deletions src/GitVersionCore/Configuration/ConfigExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static void Reset(this Config config)
config.BuildMetaDataPadding ??= 4;
config.CommitsSinceVersionSourcePadding ??= 4;
config.CommitDateFormat ??= "yyyy-MM-dd";
config.UpdateBuildNumber ??= true;

var configBranches = config.Branches.ToList();

Expand Down Expand Up @@ -263,6 +264,7 @@ public static EffectiveConfiguration CalculateEffectiveConfiguration(this Config
var patchMessage = configuration.PatchVersionBumpMessage;
var noBumpMessage = configuration.NoBumpMessage;
var commitDateFormat = configuration.CommitDateFormat;
var updateBuildNumber = configuration.UpdateBuildNumber ?? true;

var commitMessageVersionBump = currentBranchConfig.CommitMessageIncrementing ?? configuration.CommitMessageIncrementing.Value;

Expand All @@ -282,6 +284,7 @@ public static EffectiveConfiguration CalculateEffectiveConfiguration(this Config
currentBranchConfig.TracksReleaseBranches.Value,
currentBranchConfig.IsReleaseBranch.Value,
commitDateFormat,
updateBuildNumber,
preReleaseWeight);
}

Expand Down
4 changes: 2 additions & 2 deletions src/GitVersionCore/Core/BuildAgentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ protected BuildAgentBase(IEnvironment environment, ILog log)
public virtual bool PreventFetch() => true;
public virtual bool ShouldCleanUpRemotes() => false;

public virtual void WriteIntegration(Action<string> writer, VersionVariables variables)
public virtual void WriteIntegration(Action<string> writer, VersionVariables variables, bool updateBuildNumber = true)
{
if (writer == null)
if (writer == null || !updateBuildNumber)
{
return;
}
Expand Down
11 changes: 6 additions & 5 deletions src/GitVersionCore/Model/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@ private static T MergeObjects<T>(T target, T source)
[YamlMember(Alias = "merge-message-formats")]
public Dictionary<string, string> MergeMessageFormats { get; set; } = new Dictionary<string, string>();

[YamlMember(Alias = "update-build-number")]
public bool? UpdateBuildNumber { get; set; }

public override string ToString()
{
var stringBuilder = new StringBuilder();
using (var stream = new StringWriter(stringBuilder))
{
ConfigSerializer.Write(this, stream);
stream.Flush();
}
using var stream = new StringWriter(stringBuilder);
ConfigSerializer.Write(this, stream);
stream.Flush();
return stringBuilder.ToString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public EffectiveConfiguration(
bool tracksReleaseBranches,
bool isCurrentBranchRelease,
string commitDateFormat,
bool updateBuildNumber,
int preReleaseWeight)
{
AssemblyVersioningScheme = assemblyVersioningScheme;
Expand Down Expand Up @@ -63,6 +64,7 @@ public EffectiveConfiguration(
TracksReleaseBranches = tracksReleaseBranches;
IsCurrentBranchRelease = isCurrentBranchRelease;
CommitDateFormat = commitDateFormat;
UpdateBuildNumber = updateBuildNumber;
PreReleaseWeight = preReleaseWeight;
}

Expand Down Expand Up @@ -119,6 +121,8 @@ public EffectiveConfiguration(

public string CommitDateFormat { get; private set; }

public bool UpdateBuildNumber { get; private set; }

public int PreReleaseWeight { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public class OutputGenerator : IOutputGenerator
private readonly IConsole console;
private readonly IFileSystem fileSystem;
private readonly IOptions<GitVersionOptions> options;
private readonly Lazy<GitVersionContext> versionContext;
private readonly ICurrentBuildAgent buildAgent;

public OutputGenerator(ICurrentBuildAgent buildAgent, IConsole console, IFileSystem fileSystem, IOptions<GitVersionOptions> options)
public OutputGenerator(ICurrentBuildAgent buildAgent, IConsole console, IFileSystem fileSystem, IOptions<GitVersionOptions> options, Lazy<GitVersionContext> versionContext)
{
this.console = console ?? throw new ArgumentNullException(nameof(console));
this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
this.options = options ?? throw new ArgumentNullException(nameof(options));
this.versionContext = versionContext;
this.buildAgent = buildAgent;
}

Expand All @@ -30,7 +32,7 @@ public void Execute(VersionVariables variables, OutputContext context)
var gitVersionOptions = options.Value;
if (gitVersionOptions.Output.Contains(OutputType.BuildServer))
{
buildAgent?.WriteIntegration(console.WriteLine, variables);
buildAgent?.WriteIntegration(console.WriteLine, variables, versionContext.Value.Configuration.UpdateBuildNumber);
}
if (gitVersionOptions.Output.Contains(OutputType.File))
{
Expand Down