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

Refactor next version calculator (get rid of taggedSemanticVersion) #3244

Merged
merged 11 commits into from
Feb 19, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public void CanTakePreReleaseVersionFromReleasesBranchWithNumericPreReleaseTag()
fixture.Repository.MakeCommits(5);
fixture.Repository.CreateBranch("releases/2.0.0");
fixture.Checkout("releases/2.0.0");
fixture.Repository.ApplyTag("v2.0.0-1");
fixture.Repository.ApplyTag("v2.0.0-beta.1");

var variables = fixture.GetVersion();
Assert.AreEqual("2.0.0-1", variables.FullSemVer);
Assert.AreEqual("2.0.0-beta.1", variables.FullSemVer);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ public void ChoosesHighestVersionReturnedFromStrategies()
repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any<HashSet<IBranch>>()).Returns(Enumerable.Empty<IBranch>());
var dateTimeOffset = DateTimeOffset.Now;
var versionStrategies = new IVersionStrategy[] { new V1Strategy(DateTimeOffset.Now), new V2Strategy(dateTimeOffset) };
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), Substitute.For<IMainlineVersionCalculator>(),
var mainlineVersionCalculatorMock = Substitute.For<IMainlineVersionCalculator>();
mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any<ICommit?>()).Returns(new SemanticVersionBuildMetaData());
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), mainlineVersionCalculatorMock,
repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock);

// Act
Expand Down Expand Up @@ -338,7 +340,9 @@ public void UsesWhenFromNextBestMatchIfHighestDoesntHaveWhen()
repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any<HashSet<IBranch>>()).Returns(Enumerable.Empty<IBranch>());
var when = DateTimeOffset.Now;
var versionStrategies = new IVersionStrategy[] { new V1Strategy(when), new V2Strategy(null) };
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), Substitute.For<IMainlineVersionCalculator>(),
var mainlineVersionCalculatorMock = Substitute.For<IMainlineVersionCalculator>();
mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any<ICommit?>()).Returns(new SemanticVersionBuildMetaData());
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), mainlineVersionCalculatorMock,
repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock);

// Act
Expand Down Expand Up @@ -367,7 +371,9 @@ public void UsesWhenFromNextBestMatchIfHighestDoesntHaveWhenReversedOrder()
repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any<HashSet<IBranch>>()).Returns(Enumerable.Empty<IBranch>());
var when = DateTimeOffset.Now;
var versionStrategies = new IVersionStrategy[] { new V2Strategy(null), new V1Strategy(when) };
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), Substitute.For<IMainlineVersionCalculator>(),
var mainlineVersionCalculatorMock = Substitute.For<IMainlineVersionCalculator>();
mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any<ICommit?>()).Returns(new SemanticVersionBuildMetaData());
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), mainlineVersionCalculatorMock,
repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock);

// Act
Expand Down Expand Up @@ -397,7 +403,9 @@ public void ShouldNotFilterVersion()
repositoryStoreMock.GetSourceBranches(branchMock, configuration, Arg.Any<HashSet<IBranch>>()).Returns(Enumerable.Empty<IBranch>());
var version = new BaseVersion("dummy", false, new SemanticVersion(2), GitToolsTestingExtensions.CreateMockCommit(), null);
var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(version) };
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), Substitute.For<IMainlineVersionCalculator>(),
var mainlineVersionCalculatorMock = Substitute.For<IMainlineVersionCalculator>();
mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any<ICommit?>()).Returns(new SemanticVersionBuildMetaData());
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), mainlineVersionCalculatorMock,
repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock);

// Act
Expand Down Expand Up @@ -427,7 +435,9 @@ public void ShouldFilterVersion()
var higherVersion = new BaseVersion("exclude", false, new SemanticVersion(2), GitToolsTestingExtensions.CreateMockCommit(), null);
var lowerVersion = new BaseVersion("dummy", false, new SemanticVersion(1), GitToolsTestingExtensions.CreateMockCommit(), null);
var versionStrategies = new IVersionStrategy[] { new TestVersionStrategy(higherVersion, lowerVersion) };
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), Substitute.For<IMainlineVersionCalculator>(),
var mainlineVersionCalculatorMock = Substitute.For<IMainlineVersionCalculator>();
mainlineVersionCalculatorMock.CreateVersionBuildMetaData(Arg.Any<ICommit?>()).Returns(new SemanticVersionBuildMetaData());
var unitUnderTest = new NextVersionCalculator(Substitute.For<ILog>(), mainlineVersionCalculatorMock,
repositoryStoreMock, new(context), versionStrategies, effectiveBranchConfigurationFinderMock, incrementStrategyFinderMock);

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ public void ValidateVersionParsing(
Assert.AreEqual(major, version.Major);
Assert.AreEqual(minor, version.Minor);
Assert.AreEqual(patch, version.Patch);
version.PreReleaseTag.ShouldNotBeNull();
Assert.AreEqual(tag, version.PreReleaseTag.Name);
Assert.AreEqual(tagNumber, version.PreReleaseTag.Number);

version.BuildMetaData.ShouldNotBeNull();
Assert.AreEqual(numberOfBuilds, version.BuildMetaData.CommitsSinceTag);
Assert.AreEqual(branchName, version.BuildMetaData.Branch);
Assert.AreEqual(sha, version.BuildMetaData.Sha);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void VersionSourceSha()

var nextVersion = nextVersionCalculator.FindVersion();

nextVersion.IncrementedVersion.BuildMetaData.ShouldNotBeNull();
nextVersion.IncrementedVersion.BuildMetaData.VersionSourceSha.ShouldBeNull();
nextVersion.IncrementedVersion.BuildMetaData.CommitsSinceVersionSource.ShouldBe(3);
}
Expand All @@ -38,7 +37,6 @@ public void VersionSourceShaOneCommit()

var nextVersion = nextVersionCalculator.FindVersion();

nextVersion.IncrementedVersion.BuildMetaData.ShouldNotBeNull();
nextVersion.IncrementedVersion.BuildMetaData.VersionSourceSha.ShouldBeNull();
nextVersion.IncrementedVersion.BuildMetaData.CommitsSinceVersionSource.ShouldBe(1);
}
Expand All @@ -59,7 +57,6 @@ public void VersionSourceShaUsingTag()

var nextVersion = nextVersionCalculator.FindVersion();

nextVersion.IncrementedVersion.BuildMetaData.ShouldNotBeNull();
nextVersion.IncrementedVersion.BuildMetaData.VersionSourceSha.ShouldBe(secondCommit.Sha);
nextVersion.IncrementedVersion.BuildMetaData.CommitsSinceVersionSource.ShouldBe(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class AssemblyVersionsGeneratorExtensions
AssemblyVersioningScheme.Major => $"{sv.Major}.0.0.0",
AssemblyVersioningScheme.MajorMinor => $"{sv.Major}.{sv.Minor}.0.0",
AssemblyVersioningScheme.MajorMinorPatch => $"{sv.Major}.{sv.Minor}.{sv.Patch}.0",
AssemblyVersioningScheme.MajorMinorPatchTag => $"{sv.Major}.{sv.Minor}.{sv.Patch}.{sv.PreReleaseTag?.Number ?? 0}",
AssemblyVersioningScheme.MajorMinorPatchTag => $"{sv.Major}.{sv.Minor}.{sv.Patch}.{sv.PreReleaseTag.Number ?? 0}",
AssemblyVersioningScheme.None => null,
_ => throw new ArgumentException($"Unexpected value ({scheme}).", nameof(scheme))
};
Expand All @@ -19,7 +19,7 @@ public static class AssemblyVersionsGeneratorExtensions
AssemblyFileVersioningScheme.Major => $"{sv.Major}.0.0.0",
AssemblyFileVersioningScheme.MajorMinor => $"{sv.Major}.{sv.Minor}.0.0",
AssemblyFileVersioningScheme.MajorMinorPatch => $"{sv.Major}.{sv.Minor}.{sv.Patch}.0",
AssemblyFileVersioningScheme.MajorMinorPatchTag => $"{sv.Major}.{sv.Minor}.{sv.Patch}.{sv.PreReleaseTag?.Number ?? 0}",
AssemblyFileVersioningScheme.MajorMinorPatchTag => $"{sv.Major}.{sv.Minor}.{sv.Patch}.{sv.PreReleaseTag.Number ?? 0}",
AssemblyFileVersioningScheme.None => null,
_ => throw new ArgumentException($"Unexpected value ({scheme}).", nameof(scheme))
};
Expand Down
Loading