Skip to content

Commit a624e2f

Browse files
authored
Add an action that validates if assembler.yml content-source mapping is fully published to the link registry (#1300)
1 parent 8d5a122 commit a624e2f

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed
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"

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

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/tooling/docs-assembler/Building/AssemblerCrossLinkFetcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace Documentation.Assembler.Building;
1313

14-
public class AssemblerCrossLinkFetcher(ILoggerFactory logger, AssemblyConfiguration configuration, PublishEnvironment publishEnvironment) : CrossLinkFetcher(logger)
14+
public class AssemblerCrossLinkFetcher(ILoggerFactory logger, AssemblyConfiguration configuration, PublishEnvironment publishEnvironment)
15+
: CrossLinkFetcher(logger)
1516
{
1617
public override async Task<FetchedCrossLinks> Fetch(Cancel ctx)
1718
{

src/tooling/docs-assembler/Cli/ContentSourceCommands.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
using System.IO.Abstractions;
77
using Actions.Core.Services;
88
using ConsoleAppFramework;
9+
using Documentation.Assembler.Building;
910
using Elastic.Documentation.Configuration.Assembler;
1011
using Elastic.Documentation.Tooling.Diagnostics.Console;
12+
using Elastic.Markdown.Links.CrossLinks;
1113
using Microsoft.Extensions.Logging;
1214

1315
namespace Documentation.Assembler.Cli;
@@ -22,6 +24,54 @@ private void AssignOutputLogger()
2224
ConsoleApp.LogError = msg => log.LogError(msg);
2325
}
2426

27+
[Command("validate")]
28+
public async Task<int> Validate(Cancel ctx = default)
29+
{
30+
AssignOutputLogger();
31+
await using var collector = new ConsoleDiagnosticsCollector(logFactory, githubActionsService)
32+
{
33+
NoHints = true
34+
};
35+
36+
_ = collector.StartAsync(ctx);
37+
38+
// environment does not matter to check the configuration, defaulting to dev
39+
var context = new AssembleContext("dev", collector, new FileSystem(), new FileSystem(), null, null)
40+
{
41+
Force = false,
42+
AllowIndexing = false
43+
};
44+
var fetcher = new AssemblerCrossLinkFetcher(logFactory, context.Configuration, context.Environment);
45+
var links = await fetcher.FetchLinkIndex(ctx);
46+
var repositories = context.Configuration.ReferenceRepositories.Values.Concat<Repository>([context.Configuration.Narrative]).ToList();
47+
48+
foreach (var repository in repositories)
49+
{
50+
if (!links.Repositories.TryGetValue(repository.Name, out var registryMapping))
51+
{
52+
collector.EmitError(context.ConfigurationPath, $"'{repository}' does not exist in {CrossLinkFetcher.RegistryUrl}");
53+
continue;
54+
}
55+
56+
var current = repository.GetBranch(ContentSource.Current);
57+
var next = repository.GetBranch(ContentSource.Next);
58+
if (!registryMapping.TryGetValue(next, out _))
59+
{
60+
collector.EmitError(context.ConfigurationPath,
61+
$"'{repository.Name}' has not yet published links.json for configured 'next' content source: '{next}' see {CrossLinkFetcher.RegistryUrl}");
62+
}
63+
if (!registryMapping.TryGetValue(current, out _))
64+
{
65+
collector.EmitError(context.ConfigurationPath,
66+
$"'{repository.Name}' has not yet published links.json for configured 'current' content source: '{current}' see {CrossLinkFetcher.RegistryUrl}");
67+
}
68+
}
69+
70+
71+
await collector.StopAsync(ctx);
72+
return collector.Errors == 0 ? 0 : 1;
73+
}
74+
2575
/// <summary> </summary>
2676
/// <param name="repository"></param>
2777
/// <param name="branchOrTag"></param>

0 commit comments

Comments
 (0)