From d8e4d17cbcfa56483aab49ed4061e4cb93c5dfe9 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 10 Sep 2025 12:43:32 +0200 Subject: [PATCH 1/3] Ensure keys in redirect.yml get validated as relative to docset.yml --- src/tooling/docs-builder/Cli/DiffCommands.cs | 45 +++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/tooling/docs-builder/Cli/DiffCommands.cs b/src/tooling/docs-builder/Cli/DiffCommands.cs index 94f2bc3ec..abfd8153f 100644 --- a/src/tooling/docs-builder/Cli/DiffCommands.cs +++ b/src/tooling/docs-builder/Cli/DiffCommands.cs @@ -56,6 +56,7 @@ public async Task ValidateRedirects(string? path = null, Cancel ctx = defau return collector.Errors; } + var sourceDirectory = buildContext.DocumentationSourceDirectory; var root = Paths.DetermineSourceDirectoryRoot(buildContext.DocumentationSourceDirectory); if (root is null) { @@ -77,31 +78,33 @@ public async Task ValidateRedirects(string? path = null, Cancel ctx = defau if (changed.Length != 0) _log.LogInformation("Found {Count} changes to files related to documentation in the current branch.", changed.Length); - var missingRedirects = changed - .Where(c => - c.ChangeType is GitChangeType.Deleted or GitChangeType.Renamed - && !redirects.ContainsKey(c is RenamedGitChange renamed ? renamed.OldFilePath : c.FilePath) - ) - .ToArray(); - - if (missingRedirects.Length != 0) + var deletedAndRenamed = changed.Where(c => c.ChangeType is GitChangeType.Deleted or GitChangeType.Renamed).ToArray(); + var missingCount = 0; + foreach (var change in deletedAndRenamed) { - var relativeRedirectFile = Path.GetRelativePath(root.FullName, redirectFile.Source.FullName); - _log.LogInformation("Found {Count} changes that still require updates to: {RedirectFile}", missingRedirects.Length, relativeRedirectFile); + var lookupPath = change is RenamedGitChange renamed ? renamed.OldFilePath : change.FilePath; + var docSetRelativePath = Path.GetRelativePath(buildContext.DocumentationSourceDirectory.FullName, Path.Combine(root.FullName, lookupPath)); + var rootRelativePath = Path.GetRelativePath(root.FullName, Path.Combine(root.FullName, lookupPath)); + if (redirects.ContainsKey(docSetRelativePath)) + continue; + if (redirects.ContainsKey(rootRelativePath)) + { + collector.EmitHint(redirectFile.Source, + $"Redirect contains path relative to root '{rootRelativePath}' but should be relative to the documentation set '{docSetRelativePath}'"); + continue; + } + missingCount++; + + if (change is RenamedGitChange rename) + collector.EmitError(redirectFile.Source, $"Missing '{docSetRelativePath}' in redirects.yml. '{rename.OldFilePath}' was renamed to '{rename.NewFilePath}' but it has no redirect configuration set."); + else if (change.ChangeType is GitChangeType.Deleted) + collector.EmitError(redirectFile.Source, $"Missing '{docSetRelativePath}' in redirects.yml. '{change.FilePath}' was deleted but it has no redirect targets. This will lead to broken links."); } - foreach (var notFound in missingRedirects) + if (missingCount != 0) { - if (notFound is RenamedGitChange renamed) - { - collector.EmitError(redirectFile.Source, - $"File '{renamed.OldFilePath}' was renamed to '{renamed.NewFilePath}' but it has no redirect configuration set."); - } - else if (notFound.ChangeType is GitChangeType.Deleted) - { - collector.EmitError(redirectFile.Source, - $"File '{notFound.FilePath}' was deleted but it has no redirect targets. This will lead to broken links."); - } + var relativeRedirectFile = Path.GetRelativePath(root.FullName, redirectFile.Source.FullName); + _log.LogInformation("Found {Count} changes that still require updates to: {RedirectFile}", missingCount, relativeRedirectFile); } await collector.StopAsync(ctx); From 14d04803369c1c311f8f099917ea927f26419faf Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 10 Sep 2025 13:03:06 +0200 Subject: [PATCH 2/3] Move from hint to warning --- src/tooling/docs-builder/Cli/DiffCommands.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tooling/docs-builder/Cli/DiffCommands.cs b/src/tooling/docs-builder/Cli/DiffCommands.cs index abfd8153f..116367059 100644 --- a/src/tooling/docs-builder/Cli/DiffCommands.cs +++ b/src/tooling/docs-builder/Cli/DiffCommands.cs @@ -56,7 +56,6 @@ public async Task ValidateRedirects(string? path = null, Cancel ctx = defau return collector.Errors; } - var sourceDirectory = buildContext.DocumentationSourceDirectory; var root = Paths.DetermineSourceDirectoryRoot(buildContext.DocumentationSourceDirectory); if (root is null) { @@ -89,7 +88,7 @@ public async Task ValidateRedirects(string? path = null, Cancel ctx = defau continue; if (redirects.ContainsKey(rootRelativePath)) { - collector.EmitHint(redirectFile.Source, + collector.EmitWarning(redirectFile.Source, $"Redirect contains path relative to root '{rootRelativePath}' but should be relative to the documentation set '{docSetRelativePath}'"); continue; } From df4f3460c7fce41c688cca26ca69f4ad1a26d088 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 10 Sep 2025 13:03:35 +0200 Subject: [PATCH 3/3] Make root relative keys an error --- src/tooling/docs-builder/Cli/DiffCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tooling/docs-builder/Cli/DiffCommands.cs b/src/tooling/docs-builder/Cli/DiffCommands.cs index 116367059..fad052e6b 100644 --- a/src/tooling/docs-builder/Cli/DiffCommands.cs +++ b/src/tooling/docs-builder/Cli/DiffCommands.cs @@ -88,7 +88,7 @@ public async Task ValidateRedirects(string? path = null, Cancel ctx = defau continue; if (redirects.ContainsKey(rootRelativePath)) { - collector.EmitWarning(redirectFile.Source, + collector.EmitError(redirectFile.Source, $"Redirect contains path relative to root '{rootRelativePath}' but should be relative to the documentation set '{docSetRelativePath}'"); continue; }