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
2 changes: 1 addition & 1 deletion actions/validate-inbound-local/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ runs:
- name: Validate Inbound Links
uses: elastic/docs-builder/actions/assembler@main
with:
command: "link validate-inbound-local"
command: "inbound-links validate-link-reference"
4 changes: 0 additions & 4 deletions build/Targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ let private pristineCheck (arguments:ParseResults<Build>) =
let private publishBinaries _ =
exec { run "dotnet" "publish" "src/docs-builder/docs-builder.csproj" }
exec { run "dotnet" "publish" "src/docs-assembler/docs-assembler.csproj" }
Zip.zip
".artifacts/publish/docs-builder/release"
$"docs-builder-%s{OS.Name}-{OS.Arch}.zip"
[".artifacts/publish/docs-builder/release/docs-builder"]

let private publishZip _ =
exec { run "dotnet" "publish" "src/docs-builder/docs-builder.csproj" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Documentation.Assembler.Cli;

internal sealed class LinkCommands(ILoggerFactory logger, ICoreService githubActionsService)
internal sealed class InboundLinkCommands(ILoggerFactory logger, ICoreService githubActionsService)
{
private void AssignOutputLogger()
{
Expand All @@ -27,33 +27,44 @@ private void AssignOutputLogger()
#pragma warning restore CA2254
}

/// <summary>
/// Validate all published cross_links in all published links.json files.
/// </summary>
/// <summary> Validate all published cross_links in all published links.json files. </summary>
/// <param name="ctx"></param>
[Command("validate-inbound-all")]
[Command("validate-all")]
public async Task<int> ValidateAllInboundLinks(Cancel ctx = default)
{
AssignOutputLogger();
return await new LinkIndexLinkChecker(logger).CheckAll(githubActionsService, ctx);
}

/// <summary>
/// Create an index.json file from all discovered links.json files in our S3 bucket
/// </summary>
/// <summary> Validate all published cross_links in all published links.json files. </summary>
/// <param name="repository"></param>
/// <param name="file"></param>
/// <param name="ctx"></param>
[Command("validate-inbound-local")]
public async Task<int> ValidateLocalInboundLinks(string? repository = null, string? file = null, Cancel ctx = default)
[Command("validate")]
public async Task<int> ValidateRepoInboundLinks(string? repository = null, Cancel ctx = default)
{
AssignOutputLogger();
file ??= ".artifacts/docs/html/links.json";
var fs = new FileSystem();
var root = fs.DirectoryInfo.New(Paths.Root.FullName);
repository ??= GitCheckoutInformation.Create(root, new FileSystem()).RepositoryName;
if (repository == null)
throw new Exception("Unable to determine repository name");
return await new LinkIndexLinkChecker(logger).CheckRepository(githubActionsService, repository, ctx);
}

/// <summary>
/// Validate a locally published links.json file against all published links.json files in the registry
/// </summary>
/// <param name="file"></param>
/// <param name="ctx"></param>
[Command("validate-link-reference")]
public async Task<int> ValidateLocalLinkReference(string? file = null, Cancel ctx = default)
{
AssignOutputLogger();
file ??= ".artifacts/docs/html/links.json";
var fs = new FileSystem();
var root = fs.DirectoryInfo.New(Paths.Root.FullName);
var repository = GitCheckoutInformation.Create(root, new FileSystem()).RepositoryName
?? throw new Exception("Unable to determine repository name");

return await new LinkIndexLinkChecker(logger).CheckWithLocalLinksJson(githubActionsService, repository, file, ctx);
}
Expand All @@ -69,14 +80,21 @@ public async Task CreateLinkIndex(Cancel ctx = default)

IAmazonS3 client = new AmazonS3Client();
var bucketName = "elastic-docs-link-index";
var request = new ListObjectsV2Request { BucketName = bucketName, MaxKeys = 5 };
var request = new ListObjectsV2Request
{
BucketName = bucketName,
MaxKeys = 5
};

Console.WriteLine("--------------------------------------");
Console.WriteLine($"Listing the contents of {bucketName}:");
Console.WriteLine("--------------------------------------");


var linkIndex = new LinkIndex { Repositories = [] };
var linkIndex = new LinkIndex
{
Repositories = []
};
try
{
ListObjectsV2Response response;
Expand All @@ -95,11 +113,20 @@ public async Task CreateLinkIndex(Cancel ctx = default)
var repository = tokens[1];
var branch = tokens[2];

var entry = new LinkIndexEntry { Repository = repository, Branch = branch, ETag = obj.ETag.Trim('"'), Path = obj.Key };
var entry = new LinkIndexEntry
{
Repository = repository,
Branch = branch,
ETag = obj.ETag.Trim('"'),
Path = obj.Key
};
if (linkIndex.Repositories.TryGetValue(repository, out var existingEntry))
existingEntry[branch] = entry;
else
linkIndex.Repositories.Add(repository, new Dictionary<string, LinkIndexEntry> { { branch, entry } });
linkIndex.Repositories.Add(repository, new Dictionary<string, LinkIndexEntry>
{
{ branch, entry }
});
Console.WriteLine(entry);
}

Expand Down
17 changes: 15 additions & 2 deletions src/docs-assembler/Links/LinkIndexLinkChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public async Task<int> CheckAll(ICoreService githubActionsService, Cancel ctx)
return await ValidateCrossLinks(githubActionsService, crossLinks, resolver, null, ctx);
}

public async Task<int> CheckRepository(ICoreService githubActionsService, string repository, Cancel ctx)
{
var fetcher = new LinksIndexCrossLinkFetcher(logger);
var resolver = new CrossLinkResolver(fetcher);
//todo add ctx
var crossLinks = await resolver.FetchLinks();

return await ValidateCrossLinks(githubActionsService, crossLinks, resolver, repository, ctx);
}

public async Task<int> CheckWithLocalLinksJson(
ICoreService githubActionsService,
string repository,
Expand Down Expand Up @@ -75,7 +85,10 @@ private async Task<int> ValidateCrossLinks(
_ = collector.StartAsync(ctx);
foreach (var (repository, linkReference) in crossLinks.LinkReferences)
{
_logger.LogInformation("Validating {Repository}", repository);
if (!string.IsNullOrEmpty(currentRepository))
_logger.LogInformation("Validating '{CurrentRepository}://' links in {TargetRepository}", currentRepository, repository);
else
_logger.LogInformation("Validating all cross_links in {Repository}", repository);
foreach (var crossLink in linkReference.CrossLinks)
{
// if we are filtering we only want errors from inbound links to a certain
Expand All @@ -96,10 +109,10 @@ private async Task<int> ValidateCrossLinks(
}

collector.EmitError(repository, s);

}, uri, out _);
}
}

collector.Channel.TryComplete();
await collector.StopAsync(ctx);
return collector.Errors + collector.Warnings;
Expand Down
2 changes: 1 addition & 1 deletion src/docs-assembler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
app.UseFilter<StopwatchFilter>();
app.UseFilter<CatchExceptionFilter>();

app.Add<LinkCommands>("link");
app.Add<InboundLinkCommands>("inbound-links");
app.Add<RepositoryCommands>("repo");

var githubActions = ConsoleApp.ServiceProvider.GetService<ICoreService>();
Expand Down