Skip to content

Commit

Permalink
Merge pull request #3444 from HHobeck/feature/3443_change-to-immutabl…
Browse files Browse the repository at this point in the history
…e-class-type

Changing the following classes and define the properties as immutable SemanticVersion, SemanticVersionPreReleaseTag and SemanticVersionBuildMetaData
  • Loading branch information
arturcic authored Mar 18, 2023
2 parents 5ac47d5 + 2ae2c3c commit f3b7c36
Show file tree
Hide file tree
Showing 23 changed files with 397 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,17 @@ private void AssertVariablesAreWrittenToFile(string file)
Minor = 2,
Patch = 3,
PreReleaseTag = "beta1",
BuildMetaData = "5"
BuildMetaData = new SemanticVersionBuildMetaData("5")
{
Sha = "f28807e615e9f06aec8a33c87780374e0c1f6fb8",
CommitDate = new DateTimeOffset(2022, 4, 6, 16, 10, 59, TimeSpan.FromHours(10))
}
};

semanticVersion.BuildMetaData.CommitDate = new DateTimeOffset(2022, 4, 6, 16, 10, 59, TimeSpan.FromHours(10));
semanticVersion.BuildMetaData.Sha = "f28807e615e9f06aec8a33c87780374e0c1f6fb8";

var configuration = new TestEffectiveConfiguration();
var variableProvider = this.sp.GetRequiredService<IVariableProvider>();

var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, false);
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);

this.buildServer.WithPropertyFile(file);

Expand Down
11 changes: 6 additions & 5 deletions src/GitVersion.BuildAgents.Tests/Agents/BuildServerBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ public void BuildNumberIsFullSemVer()
Minor = 2,
Patch = 3,
PreReleaseTag = "beta1",
BuildMetaData = "5"
BuildMetaData = new SemanticVersionBuildMetaData("5")
{
Sha = "commitSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
}
};

semanticVersion.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
semanticVersion.BuildMetaData.Sha = "commitSha";

var configuration = new TestEffectiveConfiguration();

var variables = this.buildServer.GetVariablesFor(semanticVersion, configuration, false);
var variables = this.buildServer.GetVariablesFor(semanticVersion, configuration, null);
var buildAgent = this.sp.GetRequiredService<BuildAgent>();
buildAgent.WriteIntegration(writes.Add, variables);

Expand Down
11 changes: 6 additions & 5 deletions src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@ private void AssertVariablesAreWrittenToFile(string file)
Minor = 2,
Patch = 3,
PreReleaseTag = "beta1",
BuildMetaData = "5"
BuildMetaData = new SemanticVersionBuildMetaData("5")
{
Sha = "commitSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
}
};

semanticVersion.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
semanticVersion.BuildMetaData.Sha = "commitSha";

var configuration = new TestEffectiveConfiguration();

var variableProvider = this.sp.GetRequiredService<IVariableProvider>();

var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, false);
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);

this.buildServer.WithPropertyFile(file);

Expand Down
11 changes: 6 additions & 5 deletions src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ private void AssertVariablesAreWrittenToFile(string file)
Minor = 2,
Patch = 3,
PreReleaseTag = "beta1",
BuildMetaData = "5"
BuildMetaData = new SemanticVersionBuildMetaData("5")
{
Sha = "commitSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
}
};

semanticVersion.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
semanticVersion.BuildMetaData.Sha = "commitSha";

var configuration = new TestEffectiveConfiguration();
var variableProvider = this.sp.GetRequiredService<IVariableProvider>();

var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, false);
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);

this.buildServer.WithPropertyFile(file);

Expand Down
11 changes: 6 additions & 5 deletions src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,18 @@ private void AssertVariablesAreWrittenToFile(string file)
Minor = 2,
Patch = 3,
PreReleaseTag = "beta1",
BuildMetaData = "5"
BuildMetaData = new SemanticVersionBuildMetaData("5")
{
Sha = "commitSha",
CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
}
};

semanticVersion.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
semanticVersion.BuildMetaData.Sha = "commitSha";

var configuration = new TestEffectiveConfiguration();

var variableProvider = this.sp.GetRequiredService<IVariableProvider>();

var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, false);
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);

this.buildServer.WithPropertyFile(file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, IG
var context = contextOptions.Value;

var nextVersion = nextVersionCalculator.FindVersion();
return variableProvider.GetVariablesFor(nextVersion.IncrementedVersion, nextVersion.Configuration, context.IsCurrentCommitTagged);
return variableProvider.GetVariablesFor(
nextVersion.IncrementedVersion, nextVersion.Configuration, context.CurrentCommitTaggedVersion
);
}
catch (Exception)
{
Expand Down
23 changes: 23 additions & 0 deletions src/GitVersion.Core.Tests/IntegrationTests/OtherBranchScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ namespace GitVersion.Core.Tests.IntegrationTests;
[TestFixture]
public class OtherBranchScenarios : TestBase
{
/// <summary>
/// https://github.com/GitTools/GitVersion/issues/2340
/// </summary>
[Test]
public void ShouldOnlyConsiderTagsMatchingOfCurrentBranch()
{
var configuration = GitFlowConfigurationBuilder.New
.WithBranch("develop", builder => builder.WithLabel("snapshot"))
.WithBranch("release", builder => builder.WithLabel("rc"))
.Build();

using var fixture = new EmptyRepositoryFixture();

fixture.MakeACommit();
fixture.BranchTo("develop");
fixture.MakeACommit();
fixture.MakeATaggedCommit("0.1.2-snapshot.2");
fixture.BranchTo("release/0.1.2");

// ✅ succeeds as expected
fixture.AssertFullSemver("0.1.2-rc.1+0", configuration);
}

[Test]
public void CanTakeVersionFromReleaseBranch()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Json()
var serviceProvider = ConfigureServices();

var variableProvider = serviceProvider.GetRequiredService<IVariableProvider>();
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, false);
var variables = variableProvider.GetVariablesFor(semanticVersion, configuration, null);
var json = variables.ToString();
json.ShouldMatchApproved(c => c.SubFolder("Approved"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,20 @@ public string ToStringWithFormatITests(int major, int minor, int patch, string p
return semVer.ToString("i");
}

private static SemanticVersion BuildSemVer(int major, int minor, int patch, string? preReleaseName, int? preReleaseVersion, int? buildCount, string? branchName = null, string? sha = null, string? otherMetadata = null)
private static SemanticVersion BuildSemVer(int major, int minor, int patch, string? preReleaseName, int? preReleaseVersion,
int? buildCount, string? branchName = null, string? sha = null, string? otherMetadata = null)
{
var semVer = new SemanticVersion(major, minor, patch);

SemanticVersionPreReleaseTag? preReleaseTag = null;
if (preReleaseName != null)
{
semVer.PreReleaseTag = new SemanticVersionPreReleaseTag(preReleaseName, preReleaseVersion);
preReleaseTag = new SemanticVersionPreReleaseTag(preReleaseName, preReleaseVersion);
}

SemanticVersionBuildMetaData? buildMetaDate = null;
if (buildCount.HasValue)
{
semVer.BuildMetaData = new SemanticVersionBuildMetaData
buildMetaDate = new SemanticVersionBuildMetaData
{
CommitsSinceTag = buildCount.Value,
Sha = sha,
Expand All @@ -149,6 +153,10 @@ private static SemanticVersion BuildSemVer(int major, int minor, int patch, stri
};
}

return semVer;
return new SemanticVersion(major, minor, patch)
{
PreReleaseTag = preReleaseTag ?? new(),
BuildMetaData = buildMetaDate ?? new()
};
}
}
Loading

0 comments on commit f3b7c36

Please sign in to comment.