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
8 changes: 3 additions & 5 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
content-source-match: ${{ steps.event-check.outputs.content-source-match != '' && steps.event-check.outputs.content-source-match || steps.match.outputs.content-source-match }}
content-source-next: ${{ steps.event-check.outputs.content-source-next != '' && steps.event-check.outputs.content-source-next || steps.match.outputs.content-source-next }}
content-source-current: ${{ steps.event-check.outputs.content-source-current != '' && steps.event-check.outputs.content-source-current || steps.match.outputs.content-source-current }}
content-source-edge: ${{ steps.event-check.outputs.content-source-edge != '' && steps.event-check.outputs.content-source-edge || steps.match.outputs.content-source-edge }}
content-source-speculative: ${{ steps.event-check.outputs.content-source-speculative != '' && steps.event-check.outputs.content-source-speculative || steps.match.outputs.content-source-speculative }}
steps:
- name: Not a push event
Expand All @@ -92,6 +93,7 @@ jobs:
echo "content-source-match=true" >> $GITHUB_OUTPUT
echo "content-source-next=false" >> $GITHUB_OUTPUT
echo "content-source-current=false" >> $GITHUB_OUTPUT
echo "content-source-edge=false" >> $GITHUB_OUTPUT
echo "content-source-speculative=false" >> $GITHUB_OUTPUT
- name: Match for push events
id: match
Expand All @@ -106,6 +108,7 @@ jobs:
echo "content-source-match=${{ steps.event-check.outputs.content-source-match != '' && steps.event-check.outputs.content-source-match || steps.match.outputs.content-source-match }}"
echo "content-source-next=${{ steps.event-check.outputs.content-source-next != '' && steps.event-check.outputs.content-source-next || steps.match.outputs.content-source-next }}"
echo "content-source-current=${{ steps.event-check.outputs.content-source-current != '' && steps.event-check.outputs.content-source-current || steps.match.outputs.content-source-current }}"
echo "content-source-current=${{ steps.event-check.outputs.content-source-edge != '' && steps.event-check.outputs.content-source-edge || steps.match.outputs.content-source-edge }}"
echo "content-source-speculative=${{ steps.event-check.outputs.content-source-speculative != '' && steps.event-check.outputs.content-source-speculative || steps.match.outputs.content-source-speculative }}"
echo "ref=${{ github.ref_name }}"
echo "repo=${{ github.repository }}"
Expand Down Expand Up @@ -460,11 +463,6 @@ jobs:
env.MATCH == 'true'
&& (
contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name)
&& (
needs.match.outputs.content-source-current == 'true'
|| needs.match.outputs.content-source-next == 'true'
|| needs.match.outputs.content-source-speculative == 'true'
)
&& steps.s3-upload.outcome == 'success'
)
uses: elastic/docs-builder/actions/update-link-index@main
Expand Down
2 changes: 2 additions & 0 deletions actions/assembler-match/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ outputs:
description: "true/false indicating the branch acts as the next content source"
content-source-current:
description: "true/false indicating the branch acts as the current content source"
content-source-edge:
description: "true/false indicating the branch acts as the edge content source"
content-source-speculative:
description: "true/false speculative match, used to build version branches before they are marked as current/next"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static AssemblyConfiguration Deserialize(string yaml, bool skipPrivateRep
if (skipPrivateRepositories
&& config.ReferenceRepositories.TryGetValue("docs-builder", out var docsContentRepository)
&& Paths.GetSolutionDirectory() is { } solutionDir
)
)
{
var docsRepositoryPath = Path.Combine(solutionDir.FullName, "docs");
config.ReferenceRepositories["docs-builder"] = docsContentRepository with
Expand Down Expand Up @@ -86,7 +86,12 @@ private static TRepository RepositoryDefaults<TRepository>(TRepository r, string
};
// ensure we always null path if we are running in CI
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("CI")))
repository = repository with { Path = null };
{
repository = repository with
{
Path = null
};
}

if (string.IsNullOrEmpty(repository.Origin))
{
Expand Down Expand Up @@ -129,7 +134,7 @@ private static TRepository RepositoryDefaults<TRepository>(TRepository r, string
/// <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,32 +146,53 @@ public ContentSourceMatch Match(string repository, string branchOrTag)
{
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 };
{
match = match with
{
Current = ContentSource.Current
};
}

if (next == branchOrTag)
{
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
};
}
}
// assume we are newly onboarding the repository to current/next
else
{
match = match with
{
Speculative = true
};
}
}

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

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

if (Narrative.GetBranch(ContentSource.Next) == branchOrTag)
{
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 }
&& 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