diff --git a/actions/validate-inbound-local/action.yml b/actions/validate-inbound-local/action.yml index 6ae079bc3..5bc31c760 100644 --- a/actions/validate-inbound-local/action.yml +++ b/actions/validate-inbound-local/action.yml @@ -7,4 +7,4 @@ runs: - name: Validate Inbound Links uses: elastic/docs-builder/actions/assembler@main with: - command: "link validate-inbound-local" \ No newline at end of file + command: "inbound-links validate-link-reference" \ No newline at end of file diff --git a/build/Targets.fs b/build/Targets.fs index f566ec9ac..5f0f9c74f 100644 --- a/build/Targets.fs +++ b/build/Targets.fs @@ -58,10 +58,6 @@ let private pristineCheck (arguments:ParseResults) = 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" } diff --git a/src/docs-assembler/Cli/LinkCommands.cs b/src/docs-assembler/Cli/InboundLinkCommands.cs similarity index 70% rename from src/docs-assembler/Cli/LinkCommands.cs rename to src/docs-assembler/Cli/InboundLinkCommands.cs index 86b0bdf20..19bca6d52 100644 --- a/src/docs-assembler/Cli/LinkCommands.cs +++ b/src/docs-assembler/Cli/InboundLinkCommands.cs @@ -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() { @@ -27,33 +27,44 @@ private void AssignOutputLogger() #pragma warning restore CA2254 } - /// - /// Validate all published cross_links in all published links.json files. - /// + /// Validate all published cross_links in all published links.json files. /// - [Command("validate-inbound-all")] + [Command("validate-all")] public async Task ValidateAllInboundLinks(Cancel ctx = default) { AssignOutputLogger(); return await new LinkIndexLinkChecker(logger).CheckAll(githubActionsService, ctx); } - /// - /// Create an index.json file from all discovered links.json files in our S3 bucket - /// + /// Validate all published cross_links in all published links.json files. /// - /// /// - [Command("validate-inbound-local")] - public async Task ValidateLocalInboundLinks(string? repository = null, string? file = null, Cancel ctx = default) + [Command("validate")] + public async Task 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); + } + + /// + /// Validate a locally published links.json file against all published links.json files in the registry + /// + /// + /// + [Command("validate-link-reference")] + public async Task 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); } @@ -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; @@ -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 { { branch, entry } }); + linkIndex.Repositories.Add(repository, new Dictionary + { + { branch, entry } + }); Console.WriteLine(entry); } diff --git a/src/docs-assembler/Links/LinkIndexLinkChecker.cs b/src/docs-assembler/Links/LinkIndexLinkChecker.cs index c1d66a29f..a64c18f5e 100644 --- a/src/docs-assembler/Links/LinkIndexLinkChecker.cs +++ b/src/docs-assembler/Links/LinkIndexLinkChecker.cs @@ -25,6 +25,16 @@ public async Task CheckAll(ICoreService githubActionsService, Cancel ctx) return await ValidateCrossLinks(githubActionsService, crossLinks, resolver, null, ctx); } + public async Task 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 CheckWithLocalLinksJson( ICoreService githubActionsService, string repository, @@ -75,7 +85,10 @@ private async Task 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 @@ -96,10 +109,10 @@ private async Task ValidateCrossLinks( } collector.EmitError(repository, s); - }, uri, out _); } } + collector.Channel.TryComplete(); await collector.StopAsync(ctx); return collector.Errors + collector.Warnings; diff --git a/src/docs-assembler/Program.cs b/src/docs-assembler/Program.cs index afd775857..05928660d 100644 --- a/src/docs-assembler/Program.cs +++ b/src/docs-assembler/Program.cs @@ -21,7 +21,7 @@ app.UseFilter(); app.UseFilter(); -app.Add("link"); +app.Add("inbound-links"); app.Add("repo"); var githubActions = ConsoleApp.ServiceProvider.GetService();