Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -129,7 +129,7 @@
/// <paramref name="repository"/>.
public ContentSourceMatch Match(string repository, string branchOrTag)
{
var match = new ContentSourceMatch(null, null, false);
var match = new ContentSourceMatch(null, null, null, false);
var tokens = repository.Split('/');
var repositoryName = tokens.Last();
var owner = tokens.First();
Expand All @@ -141,34 +141,29 @@
{
var current = r.GetBranch(ContentSource.Current);
var next = r.GetBranch(ContentSource.Next);
var edge = r.GetBranch(ContentSource.Edge);
var isVersionBranch = ContentSourceRegex.MatchVersionBranch().IsMatch(branchOrTag);
if (current == branchOrTag)
match = match with { Current = ContentSource.Current };

if (next == branchOrTag)
match = match with
{
Next = ContentSource.Next
};
match = match with { Next = ContentSource.Next };

if (edge == branchOrTag)
match = match with { Edge = ContentSource.Edge };

if (isVersionBranch && SemVersion.TryParse(branchOrTag + ".0", out var v))
{
// if the current branch is a version, only speculatively match if branch is actually a new version
if (SemVersion.TryParse(current + ".0", out var currentVersion))
{
if (v >= currentVersion)
match = match with
{
Speculative = true
};
match = match with { Speculative = true };
}
// assume we are newly onboarding the repository to current/next
else
match = match with
{
Speculative = true
};
match = match with { Speculative = true };
}

return match;
}

Expand All @@ -177,27 +172,27 @@
// this is an unknown new elastic repository
var isVersionBranch = ContentSourceRegex.MatchVersionBranch().IsMatch(branchOrTag);
if (isVersionBranch || branchOrTag == "main" || branchOrTag == "master")
return match with
{
Speculative = true
};
return match with { Speculative = true };
}

if (Narrative.GetBranch(ContentSource.Current) == branchOrTag)
match = match with
{
Current = ContentSource.Current
};
match = match with { Current = ContentSource.Current };

if (Narrative.GetBranch(ContentSource.Next) == branchOrTag)
match = match with
{
Next = ContentSource.Next
};
match = match with { Next = ContentSource.Next };

if (Narrative.GetBranch(ContentSource.Edge) == branchOrTag)
match = match with { Edge = ContentSource.Edge };

// if we haven't matched anything yet, and the branch is 'main' or 'master' always build
if (match is { Current: null, Next: null, Edge: null, Speculative: false}

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (elastic/opentelemetry)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (elastic/docs-content)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (elastic/oblt-actions)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build (elastic/elasticsearch)

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / synthetics

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / validate-assembler

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / integration

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / integration

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 188 in src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
&& branchOrTag is "main" or "master")
return match with { Speculative = true };

return match;
}

public record ContentSourceMatch(ContentSource? Current, ContentSource? Next, bool Speculative);
public record ContentSourceMatch(ContentSource? Current, ContentSource? Next, ContentSource? Edge, bool Speculative);
}

internal static partial class ContentSourceRegex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public async Task<bool> ShouldBuild(IDiagnosticsCollector collector, string? rep
// environment does not matter to check the configuration, defaulting to dev
var assembleContext = new AssembleContext(configuration, configurationContext, "dev", collector, fileSystem, fileSystem, null, null);
var matches = assembleContext.Configuration.Match(repo, refName);
if (matches is { Current: null, Next: null, Speculative: false })
if (matches is { Current: null, Next: null, Edge: null, Speculative: false })
{
_logger.LogInformation("'{Repository}' '{BranchOrTag}' combination not found in configuration.", repo, refName);
await githubActionsService.SetOutputAsync("content-source-match", "false");
await githubActionsService.SetOutputAsync("content-source-next", "false");
await githubActionsService.SetOutputAsync("content-source-edge", "false");
await githubActionsService.SetOutputAsync("content-source-current", "false");
await githubActionsService.SetOutputAsync("content-source-speculative", "false");
return false;
Expand All @@ -60,6 +61,7 @@ public async Task<bool> ShouldBuild(IDiagnosticsCollector collector, string? rep
await githubActionsService.SetOutputAsync("content-source-match", "true");
await githubActionsService.SetOutputAsync("content-source-next", matches.Next is not null ? "true" : "false");
await githubActionsService.SetOutputAsync("content-source-current", matches.Current is not null ? "true" : "false");
await githubActionsService.SetOutputAsync("content-source-edge", matches.Edge is not null ? "true" : "false");
await githubActionsService.SetOutputAsync("content-source-speculative", matches.Speculative ? "true" : "false");
return true;
}
Expand Down
Loading