diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index ea006e89a..82ad6c3de 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -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 @@ -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 @@ -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 }}" @@ -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 diff --git a/actions/assembler-match/action.yml b/actions/assembler-match/action.yml index 4ec49c42e..552a76354 100644 --- a/actions/assembler-match/action.yml +++ b/actions/assembler-match/action.yml @@ -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" diff --git a/src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs b/src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs index 3cccb9cf2..9b1ee2756 100644 --- a/src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs +++ b/src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs @@ -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 @@ -86,7 +86,12 @@ private static TRepository RepositoryDefaults(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)) { @@ -129,7 +134,7 @@ private static TRepository RepositoryDefaults(TRepository r, string /// . 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(); @@ -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; @@ -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 diff --git a/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs b/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs index 52f3c8435..7269d7447 100644 --- a/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs +++ b/src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs @@ -42,11 +42,12 @@ public async Task 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; @@ -60,6 +61,7 @@ public async Task 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; }