Skip to content

Add an action that validates if assembler.yml content-source mapping is fully published to the link registry #1300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
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
12 changes: 12 additions & 0 deletions actions/assembler-config-validate/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Documentation Assembler Configuration Validator'
description: 'Ensures the assembler configuration is valid'

branding:
icon: 'filter'
color: 'blue'

runs:
using: 'docker'
image: "docker://ghcr.io/elastic/docs-assembler:edge"
env:
INPUT_COMMAND: "content-source validate"
6 changes: 6 additions & 0 deletions docs-builder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assembler-match", "assemble
actions\assembler-match\action.yml = actions\assembler-match\action.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assembler-config-validate", "assembler-config-validate", "{E20FEEF9-1D1A-4CDA-A546-7FDC573BE399}"
ProjectSection(SolutionItems) = preProject
actions\assembler-config-validate\action.yml = actions\assembler-config-validate\action.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -178,5 +183,6 @@ Global
{059E787F-85C1-43BE-9DD6-CE319E106383} = {BE6011CC-1200-4957-B01F-FCCA10C5CF5A}
{7D36DDDA-9E0B-4D2C-8033-5D62FF8B6166} = {059E787F-85C1-43BE-9DD6-CE319E106383}
{FB1C1954-D8E2-4745-BA62-04DD82FB4792} = {245023D2-D3CA-47B9-831D-DAB91A2FFDC7}
{E20FEEF9-1D1A-4CDA-A546-7FDC573BE399} = {245023D2-D3CA-47B9-831D-DAB91A2FFDC7}
EndGlobalSection
EndGlobal
9 changes: 5 additions & 4 deletions src/Elastic.Markdown/Links/CrossLinks/CrossLinkFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public record FetchedCrossLinks

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

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

protected async Task<LinkReferenceRegistry> FetchLinkIndex(Cancel ctx)
public async Task<LinkReferenceRegistry> FetchLinkIndex(Cancel ctx)
{
if (_linkIndex is not null)
{
_logger.LogTrace("Using cached link index");
return _linkIndex;
}
var url = $"https://elastic-docs-link-index.s3.us-east-2.amazonaws.com/link-index.json";
_logger.LogInformation("Fetching {Url}", url);
var json = await _client.GetStringAsync(url, ctx);

_logger.LogInformation("Fetching {Url}", RegistryUrl);
var json = await _client.GetStringAsync(RegistryUrl, ctx);
_linkIndex = LinkReferenceRegistry.Deserialize(json);
return _linkIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Documentation.Assembler.Building;

public class AssemblerCrossLinkFetcher(ILoggerFactory logger, AssemblyConfiguration configuration, PublishEnvironment publishEnvironment) : CrossLinkFetcher(logger)
public class AssemblerCrossLinkFetcher(ILoggerFactory logger, AssemblyConfiguration configuration, PublishEnvironment publishEnvironment)
: CrossLinkFetcher(logger)
{
public override async Task<FetchedCrossLinks> Fetch(Cancel ctx)
{
Expand Down
50 changes: 50 additions & 0 deletions src/tooling/docs-assembler/Cli/ContentSourceCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using System.IO.Abstractions;
using Actions.Core.Services;
using ConsoleAppFramework;
using Documentation.Assembler.Building;
using Elastic.Documentation.Configuration.Assembler;
using Elastic.Documentation.Tooling.Diagnostics.Console;
using Elastic.Markdown.Links.CrossLinks;
using Microsoft.Extensions.Logging;

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

[Command("validate")]
public async Task<int> Validate(Cancel ctx = default)
{
AssignOutputLogger();
await using var collector = new ConsoleDiagnosticsCollector(logFactory, githubActionsService)
{
NoHints = true
};

_ = collector.StartAsync(ctx);

// environment does not matter to check the configuration, defaulting to dev
var context = new AssembleContext("dev", collector, new FileSystem(), new FileSystem(), null, null)
{
Force = false,
AllowIndexing = false
};
var fetcher = new AssemblerCrossLinkFetcher(logFactory, context.Configuration, context.Environment);
var links = await fetcher.FetchLinkIndex(ctx);
var repositories = context.Configuration.ReferenceRepositories.Values.Concat<Repository>([context.Configuration.Narrative]).ToList();

foreach (var repository in repositories)
{
if (!links.Repositories.TryGetValue(repository.Name, out var registryMapping))
{
collector.EmitError(context.ConfigurationPath, $"'{repository}' does not exist in {CrossLinkFetcher.RegistryUrl}");
continue;
}

var current = repository.GetBranch(ContentSource.Current);
var next = repository.GetBranch(ContentSource.Next);
if (!registryMapping.TryGetValue(next, out _))
{
collector.EmitError(context.ConfigurationPath,
$"'{repository.Name}' has not yet published links.json for configured 'next' content source: '{next}' see {CrossLinkFetcher.RegistryUrl}");
}
if (!registryMapping.TryGetValue(current, out _))
{
collector.EmitError(context.ConfigurationPath,
$"'{repository.Name}' has not yet published links.json for configured 'current' content source: '{current}' see {CrossLinkFetcher.RegistryUrl}");
}
}


await collector.StopAsync(ctx);
return collector.Errors == 0 ? 0 : 1;
}

/// <summary> </summary>
/// <param name="repository"></param>
/// <param name="branchOrTag"></param>
Expand Down
Loading