Skip to content

Commit 96f33ab

Browse files
authored
Merge branch 'main' into ecs-9.0
2 parents 27a5789 + fcb8aeb commit 96f33ab

File tree

17 files changed

+146
-21
lines changed

17 files changed

+146
-21
lines changed

.github/workflows/pr.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ env:
1414
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
1515

1616
jobs:
17-
validate-navigation:
17+
validate-assembler:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- uses: actions/checkout@v4
@@ -23,9 +23,12 @@ jobs:
2323
id: bootstrap
2424
uses: ./.github/actions/bootstrap
2525

26-
- name: Build
26+
- name: Validate Navigation
2727
run: dotnet run --project src/tooling/docs-assembler -c release -- navigation validate
2828

29+
- name: Validate Content Sources
30+
run: dotnet run --project src/tooling/docs-assembler -c release -- content-source validate
31+
2932
build-lambda:
3033
uses: ./.github/workflows/build-link-index-updater-lambda.yml
3134

.github/workflows/preview-build.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
content-source-match: ${{ steps.event-check.outputs.content-source-match != '' && steps.event-check.outputs.content-source-match || steps.match.outputs.content-source-match }}
6262
content-source-next: ${{ steps.event-check.outputs.content-source-next != '' && steps.event-check.outputs.content-source-next || steps.match.outputs.content-source-next }}
6363
content-source-current: ${{ steps.event-check.outputs.content-source-current != '' && steps.event-check.outputs.content-source-current || steps.match.outputs.content-source-current }}
64+
content-source-speculative: ${{ steps.event-check.outputs.content-source-speculative != '' && steps.event-check.outputs.content-source-speculative || steps.match.outputs.content-source-speculative }}
6465
steps:
6566
- name: Not a push event
6667
id: event-check
@@ -70,6 +71,7 @@ jobs:
7071
echo "content-source-match=true" >> $GITHUB_OUTPUT
7172
echo "content-source-next=false" >> $GITHUB_OUTPUT
7273
echo "content-source-current=false" >> $GITHUB_OUTPUT
74+
echo "content-source-speculative=false" >> $GITHUB_OUTPUT
7375
- name: Match for push events
7476
id: match
7577
if: contains(fromJSON('["push"]'), github.event_name)
@@ -81,8 +83,9 @@ jobs:
8183
run: |
8284
echo "Non sensitive data, echo'ing here temporarily to validate this job before connecting it further into the build job"
8385
echo "content-source-match=${{ steps.event-check.outputs.content-source-match != '' && steps.event-check.outputs.content-source-match || steps.match.outputs.content-source-match }}"
84-
echo "content-source-name=${{ steps.event-check.outputs.content-source-next != '' && steps.event-check.outputs.content-source-next || steps.match.outputs.content-source-next }}"
86+
echo "content-source-next=${{ steps.event-check.outputs.content-source-next != '' && steps.event-check.outputs.content-source-next || steps.match.outputs.content-source-next }}"
8587
echo "content-source-current=${{ steps.event-check.outputs.content-source-current != '' && steps.event-check.outputs.content-source-current || steps.match.outputs.content-source-current }}"
88+
echo "content-source-speculative=${{ steps.event-check.outputs.content-source-speculative != '' && steps.event-check.outputs.content-source-speculative || steps.match.outputs.content-source-speculative }}"
8689
echo "ref=${{ github.ref_name }}"
8790
echo "repo=${{ github.repository }}"
8891
@@ -233,7 +236,11 @@ jobs:
233236
if: |
234237
env.MATCH == 'true' &&
235238
(contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name)
236-
&& (needs.match.outputs.content-source-current == 'true' || needs.match.outputs.content-source-next == 'true')
239+
&& (
240+
needs.match.outputs.content-source-current == 'true'
241+
|| needs.match.outputs.content-source-next == 'true'
242+
|| needs.match.outputs.content-source-speculative == 'true'
243+
)
237244
&& steps.s3-upload.outcome == 'success')
238245
uses: elastic/docs-builder/actions/update-link-index@main
239246

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 'Documentation Assembler Configuration Validator'
2+
description: 'Ensures the assembler configuration is valid'
3+
4+
branding:
5+
icon: 'filter'
6+
color: 'blue'
7+
8+
runs:
9+
using: 'docker'
10+
image: "docker://ghcr.io/elastic/docs-assembler:edge"
11+
env:
12+
INPUT_COMMAND: "content-source validate"

actions/assembler-match/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ outputs:
2020
description: "true/false indicating the branch acts as the next content source"
2121
content-source-current:
2222
description: "true/false indicating the branch acts as the current content source"
23+
content-source-speculative:
24+
description: "true/false speculative match, used to build version branches before they are marked as current/next"
2325

2426
runs:
2527
using: 'docker'

docs-builder.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assembler-match", "assemble
9494
actions\assembler-match\action.yml = actions\assembler-match\action.yml
9595
EndProjectSection
9696
EndProject
97+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assembler-config-validate", "assembler-config-validate", "{E20FEEF9-1D1A-4CDA-A546-7FDC573BE399}"
98+
ProjectSection(SolutionItems) = preProject
99+
actions\assembler-config-validate\action.yml = actions\assembler-config-validate\action.yml
100+
EndProjectSection
101+
EndProject
97102
Global
98103
GlobalSection(SolutionConfigurationPlatforms) = preSolution
99104
Debug|Any CPU = Debug|Any CPU
@@ -178,5 +183,6 @@ Global
178183
{059E787F-85C1-43BE-9DD6-CE319E106383} = {BE6011CC-1200-4957-B01F-FCCA10C5CF5A}
179184
{7D36DDDA-9E0B-4D2C-8033-5D62FF8B6166} = {059E787F-85C1-43BE-9DD6-CE319E106383}
180185
{FB1C1954-D8E2-4745-BA62-04DD82FB4792} = {245023D2-D3CA-47B9-831D-DAB91A2FFDC7}
186+
{E20FEEF9-1D1A-4CDA-A546-7FDC573BE399} = {245023D2-D3CA-47B9-831D-DAB91A2FFDC7}
181187
EndGlobalSection
182188
EndGlobal

docs/contribute/locally.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ This guide uses the first option. If you'd like to clone the repository and buil
4444

4545
2. **Run docs-builder from a docs folder**
4646

47-
Use the `serve` command from any docs folder to start serving the documentation at http://localhost:3000. The path to the `docset.yml` file that you want to build can be specified with `-p`:
47+
Use the `serve` command from any docs folder to start serving the documentation at http://localhost:3000:
4848

4949
```sh
5050
docs-builder serve
5151
```
52+
The path to the `docset.yml` file that you want to build can be specified with `-p`.
5253

5354
To download and install the binary file manually, refer to [Releases](https://github.com/elastic/docs-builder/releases) on GitHub.
5455

@@ -72,12 +73,12 @@ If you get a `Permission denied` error, make sure that you aren't trying to run
7273

7374
2. **Run docs-builder from a docs folder**
7475

75-
Use the `serve` command from any docs folder to start serving the documentation at http://localhost:3000. The path to the `docset.yml` file that you want to build can be specified with `-p`:
76+
Use the `serve` command from any docs folder to start serving the documentation at http://localhost:3000:
7677

7778
```sh
7879
docs-builder serve
7980
```
80-
81+
The path to the `docset.yml` file that you want to build can be specified with `-p`.
8182
:::
8283
::::
8384

@@ -111,7 +112,7 @@ cd docs-content
111112

112113
:::::{step} Run docs-builder
113114

114-
Run the `docs-builder` binary with the `serve` command to build and serve the content set to http://localhost:3000. Specify the path to the `docset.yml` file that you want to build with `-p`.
115+
Run the `docs-builder` binary with the `serve` command to build and serve the content set to http://localhost:3000. If necessary, specify the path to the `docset.yml` file that you want to build with `-p`.
115116

116117
For example:
117118

src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using System.Text.RegularExpressions;
56
using Elastic.Documentation.Serialization;
67
using YamlDotNet.Serialization;
78
using YamlStaticContext = Elastic.Documentation.Configuration.Serialization.YamlStaticContext;
@@ -83,19 +84,45 @@ private static TRepository RepositoryDefaults<TRepository>(TRepository r, string
8384
/// <paramref name="repository"/>.
8485
public ContentSourceMatch Match(string repository, string branchOrTag)
8586
{
86-
var repositoryName = repository.Split('/').Last();
87-
var match = new ContentSourceMatch(null, null);
87+
var match = new ContentSourceMatch(null, null, false);
88+
var tokens = repository.Split('/');
89+
var repositoryName = tokens.Last();
90+
var owner = tokens.First();
91+
92+
if (tokens.Length < 2 || owner != "elastic")
93+
return match;
94+
8895
if (ReferenceRepositories.TryGetValue(repositoryName, out var r))
8996
{
90-
if (r.GetBranch(ContentSource.Current) == branchOrTag)
97+
var current = r.GetBranch(ContentSource.Current);
98+
var next = r.GetBranch(ContentSource.Next);
99+
var isVersionBranch = ContentSourceRegex.MatchVersionBranch().IsMatch(branchOrTag);
100+
if (current == branchOrTag)
91101
match = match with { Current = ContentSource.Current };
92-
if (r.GetBranch(ContentSource.Next) == branchOrTag)
102+
if (next == branchOrTag)
93103
match = match with { Next = ContentSource.Next };
104+
if (isVersionBranch && SemVersion.TryParse(branchOrTag + ".0", out var v))
105+
{
106+
// if the current branch is a version, only speculatively match if branch is actually a new version
107+
if (SemVersion.TryParse(current + ".0", out var currentVersion))
108+
{
109+
if (v >= currentVersion)
110+
match = match with { Speculative = true };
111+
}
112+
// assume we are newly onboarding the repository to current/next
113+
else
114+
match = match with { Speculative = true };
115+
}
94116
return match;
95117
}
96118

97119
if (repositoryName != NarrativeRepository.RepositoryName)
98-
return match;
120+
{
121+
// this is an unknown new elastic repository
122+
var isVersionBranch = ContentSourceRegex.MatchVersionBranch().IsMatch(branchOrTag);
123+
if (isVersionBranch || branchOrTag == "main" || branchOrTag == "master")
124+
return match with { Speculative = true };
125+
}
99126

100127
if (Narrative.GetBranch(ContentSource.Current) == branchOrTag)
101128
match = match with { Current = ContentSource.Current };
@@ -105,5 +132,12 @@ public ContentSourceMatch Match(string repository, string branchOrTag)
105132
return match;
106133
}
107134

108-
public record ContentSourceMatch(ContentSource? Current, ContentSource? Next);
135+
public record ContentSourceMatch(ContentSource? Current, ContentSource? Next, bool Speculative);
136+
137+
}
138+
139+
internal static partial class ContentSourceRegex
140+
{
141+
[GeneratedRegex(@"^\d+\.\d+$", RegexOptions.IgnoreCase, "en-US")]
142+
public static partial Regex MatchVersionBranch();
109143
}

src/Elastic.Markdown/Helpers/SemVersion.cs renamed to src/Elastic.Documentation/SemVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Globalization;
77
using System.Text.RegularExpressions;
88

9-
namespace Elastic.Markdown.Helpers;
9+
namespace Elastic.Documentation;
1010

1111
/// <summary>
1212
/// A semver2 compatible version.

src/Elastic.Markdown/Links/CrossLinks/CrossLinkFetcher.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public record FetchedCrossLinks
3333

3434
public abstract class CrossLinkFetcher(ILoggerFactory logger) : IDisposable
3535
{
36+
public const string RegistryUrl = $"https://elastic-docs-link-index.s3.us-east-2.amazonaws.com/link-index.json";
3637
private readonly ILogger _logger = logger.CreateLogger(nameof(CrossLinkFetcher));
3738
private readonly HttpClient _client = new();
3839
private LinkReferenceRegistry? _linkIndex;
@@ -42,16 +43,16 @@ public static LinkReference Deserialize(string json) =>
4243

4344
public abstract Task<FetchedCrossLinks> Fetch(Cancel ctx);
4445

45-
protected async Task<LinkReferenceRegistry> FetchLinkIndex(Cancel ctx)
46+
public async Task<LinkReferenceRegistry> FetchLinkIndex(Cancel ctx)
4647
{
4748
if (_linkIndex is not null)
4849
{
4950
_logger.LogTrace("Using cached link index");
5051
return _linkIndex;
5152
}
52-
var url = $"https://elastic-docs-link-index.s3.us-east-2.amazonaws.com/link-index.json";
53-
_logger.LogInformation("Fetching {Url}", url);
54-
var json = await _client.GetStringAsync(url, ctx);
53+
54+
_logger.LogInformation("Fetching {Url}", RegistryUrl);
55+
var json = await _client.GetStringAsync(RegistryUrl, ctx);
5556
_linkIndex = LinkReferenceRegistry.Deserialize(json);
5657
return _linkIndex;
5758
}

src/Elastic.Markdown/Myst/Directives/VersionBlock.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5+
using Elastic.Documentation;
56
using Elastic.Markdown.Diagnostics;
67
using Elastic.Markdown.Helpers;
78
using static System.StringSplitOptions;

0 commit comments

Comments
 (0)