Skip to content
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 @@ -204,6 +204,7 @@ public ContentSourceMatch Match(ILoggerFactory logFactory, string repository, st
if (SemVersion.TryParse(current + ".0", out var currentVersion))
{
logger.LogInformation("Current is already using versioned branches {Current}", currentVersion);
var previousCurrentVersion = new SemVersion(currentVersion.Major, Math.Max(currentVersion.Minor - 1, 0), 0);
if (v >= currentVersion)
{
logger.LogInformation("Speculative build because {Branch} is gte current {Current}", branchOrTag, currentVersion);
Expand All @@ -212,6 +213,14 @@ public ContentSourceMatch Match(ILoggerFactory logFactory, string repository, st
Speculative = true
};
}
else if (v == previousCurrentVersion)
{
logger.LogInformation("Speculative build {Branch} is the previous minor '{ProductPreviousMinor}' of current {Current}", branchOrTag, previousCurrentVersion, currentVersion);
match = match with
{
Speculative = true
};
}
else
logger.LogInformation("NO speculative build because {Branch} is lt {Current}", branchOrTag, currentVersion);
}
Expand All @@ -221,7 +230,6 @@ public ContentSourceMatch Match(ILoggerFactory logFactory, string repository, st
logger.LogInformation("Current is not using versioned branches checking product info");
var productVersion = versioningSystem.Current;
var anchoredProductVersion = new SemVersion(productVersion.Major, productVersion.Minor, 0);
var previousMinorVersion = new SemVersion(productVersion.Major, Math.Max(productVersion.Minor - 1, 0), 0);
if (v >= anchoredProductVersion)
{
logger.LogInformation("Speculative build {Branch} is gte product current '{ProductCurrent}' anchored at {ProductAnchored}", branchOrTag, productVersion, anchoredProductVersion);
Expand All @@ -230,14 +238,6 @@ public ContentSourceMatch Match(ILoggerFactory logFactory, string repository, st
Speculative = true
};
}
else if (v == previousMinorVersion)
{
logger.LogInformation("Speculative build {Branch} is gte product current previous minor '{ProductPreviousMinor}'", branchOrTag, previousMinorVersion);
match = match with
{
Speculative = true
};
}
else
logger.LogInformation("NO speculative build {Branch} is lte product current '{ProductCurrent}'", branchOrTag, productVersion);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Elastic.Markdown/IO/IPositionalNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public interface IPositionalNavigation

INavigationItem? GetPrevious(MarkdownFile current)
{
if (!MarkdownNavigationLookup.TryGetValue(current, out var currentNavigation))
return null;
var currentNavigation = GetCurrent(current);
var index = currentNavigation.NavigationIndex;
do
{
Expand All @@ -32,8 +31,7 @@ public interface IPositionalNavigation

INavigationItem? GetNext(MarkdownFile current)
{
if (!MarkdownNavigationLookup.TryGetValue(current, out var currentNavigation))
return null;
var currentNavigation = GetCurrent(current);
var index = currentNavigation.NavigationIndex;
do
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void VersionBranchSpeculativeBuildBasedOnCurrentVersion(string branch, st
[Theory]
[InlineData("8.16", "8.15", true)] // Greater than product version
[InlineData("8.15", "8.15", true)] // Equal to product version
[InlineData("8.14", "8.15", true)] // Previous minor version
[InlineData("8.14", "8.15", false)] // Previous minor version - but current is not versioned, so no previous minor logic
[InlineData("8.13", "8.15", false)] // Less than previous minor
[InlineData("8.0", "8.0", true)] // Edge case: minor version 0
public void VersionBranchSpeculativeBuildBasedOnProductVersion(string branch, string productVersion, bool shouldBeSpeculative)
Expand Down Expand Up @@ -305,20 +305,18 @@ public void VersionBranchNoSpeculativeBuildWhenLessThanAnchoredProductVersionAnd
}

[Theory]
[InlineData("9.1", "9.2.0")] // Previous minor version
[InlineData("8.14", "8.15.1")] // Previous minor version with patch
[InlineData("10.0", "10.1.0")] // Previous minor version at major boundary
public void VersionBranchSpeculativeBuildWhenMatchesPreviousMinorVersion(string branch, string productVersion)
[InlineData("9.1", "9.2")] // Previous minor version - current is versioned branch
[InlineData("8.14", "8.15")] // Previous minor version - current is versioned branch
[InlineData("10.0", "10.1")] // Previous minor version at major boundary - current is versioned branch
public void VersionBranchSpeculativeBuildWhenMatchesPreviousMinorVersion(string branch, string currentVersion)
{
var repositories = new Dictionary<string, Repository>
{
["test-repo"] = CreateRepository(current: "main", next: "main", edge: "main")
["test-repo"] = CreateRepository(current: currentVersion, next: "main", edge: "main")
};
var config = CreateConfiguration(repositories);
var versionParts = productVersion.Split('.');
var product = CreateProduct(new SemVersion(int.Parse(versionParts[0], null), int.Parse(versionParts[1], null), int.Parse(versionParts[2], null)));

var result = config.Match(LoggerFactory, "elastic/test-repo", branch, product);
var result = config.Match(LoggerFactory, "elastic/test-repo", branch, null);

result.Speculative.Should().BeTrue();
}
Expand Down Expand Up @@ -378,23 +376,21 @@ public void VersionBranchAnchorsProductVersionToMinorZero(string branch, string
}

[Theory]
[InlineData("8.0", "8.1.0")] // Previous minor when current is 8.1
[InlineData("7.17", "8.0.0")] // Previous minor when current is 8.0 (floor at 0)
public void VersionBranchPreviousMinorCalculationHandlesEdgeCases(string branch, string productVersion)
[InlineData("8.0", "8.1")] // Previous minor when current is 8.1
[InlineData("7.17", "8.0")] // NOT previous minor when current is 8.0 (previous would be 7.0, not 7.17)
public void VersionBranchPreviousMinorCalculationHandlesEdgeCases(string branch, string currentVersion)
{
var repositories = new Dictionary<string, Repository>
{
["test-repo"] = CreateRepository(current: "main", next: "main", edge: "main")
["test-repo"] = CreateRepository(current: currentVersion, next: "main", edge: "main")
};
var config = CreateConfiguration(repositories);
var versionParts = productVersion.Split('.');
var product = CreateProduct(new SemVersion(int.Parse(versionParts[0], null), int.Parse(versionParts[1], null), int.Parse(versionParts[2], null)));

var result = config.Match(LoggerFactory, "elastic/test-repo", branch, product);
var result = config.Match(LoggerFactory, "elastic/test-repo", branch, null);

// 8.0 should match previous minor of 8.1 (which is 8.0)
// 7.17 should NOT match previous minor of 8.0 (which is Math.Max(0-1, 0) = 8.0, not 7.17)
var expectedSpeculative = branch == "8.0" && productVersion == "8.1.0";
// 7.17 should NOT match previous minor of 8.0 (which is Math.Max(8-1, 0).0 = 7.0, not 7.17)
var expectedSpeculative = branch == "8.0" && currentVersion == "8.1";
result.Speculative.Should().Be(expectedSpeculative);
}
}
Loading