Skip to content

Commit 809a2f5

Browse files
authored
Add diff-validate action and minor fixes (#1701)
1 parent 0150d27 commit 809a2f5

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

actions/diff-validate/action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: 'Validate Redirect Rules'
2+
description: 'Validates consistency of the documentation changes in relation to redirect rules'
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Validate Redirect Rules
8+
uses: elastic/docs-builder@main
9+
with:
10+
command: "diff validate"

docs-builder.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Documentation.Api.I
141141
EndProject
142142
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Documentation.Api.Lambda", "src\api\Elastic.Documentation.Api.Lambda\Elastic.Documentation.Api.Lambda.csproj", "{C6A121C5-DEB1-4FCE-9140-AF144EA98EEE}"
143143
EndProject
144+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "diff-validate", "diff-validate", "{E7C7A02B-9AB4-455A-9A64-3D326ED1A95A}"
145+
ProjectSection(SolutionItems) = preProject
146+
actions\diff-validate\action.yml = actions\diff-validate\action.yml
147+
EndProjectSection
148+
EndProject
144149
Global
145150
GlobalSection(SolutionConfigurationPlatforms) = preSolution
146151
Debug|Any CPU = Debug|Any CPU
@@ -287,5 +292,6 @@ Global
287292
{F30B90AD-1A01-4A6F-9699-809FA6875B22} = {B042CC78-5060-4091-B95A-79C71BA3908A}
288293
{AE3FC78E-167F-4B6E-88EC-84743EB748B7} = {B042CC78-5060-4091-B95A-79C71BA3908A}
289294
{C6A121C5-DEB1-4FCE-9140-AF144EA98EEE} = {B042CC78-5060-4091-B95A-79C71BA3908A}
295+
{E7C7A02B-9AB4-455A-9A64-3D326ED1A95A} = {245023D2-D3CA-47B9-831D-DAB91A2FFDC7}
290296
EndGlobalSection
291297
EndGlobal

src/tooling/docs-builder/Cli/DiffCommands.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,18 @@ public async Task<int> ValidateRedirects([Argument] string? path = null, Cancel
5757
}
5858

5959
IRepositoryTracker tracker = runningOnCi ? new IntegrationGitRepositoryTracker(path) : new LocalGitRepositoryTracker(collector, root, path);
60-
var changed = tracker.GetChangedFiles() as GitChange[] ?? [];
60+
var changed = tracker.GetChangedFiles();
6161

62-
if (changed.Length > 0)
63-
_log.LogInformation($"Found {changed.Length} changes to files related to documentation in the current branch.");
62+
if (changed.Any())
63+
_log.LogInformation("Found {Count} changes to files related to documentation in the current branch.", changed.Count());
6464

6565
foreach (var notFound in changed.DistinctBy(c => c.FilePath).Where(c => c.ChangeType is GitChangeType.Deleted or GitChangeType.Renamed
6666
&& !redirects.ContainsKey(c is RenamedGitChange renamed ? renamed.OldFilePath : c.FilePath)))
6767
{
6868
if (notFound is RenamedGitChange renamed)
6969
{
7070
collector.EmitError(redirectFileInfo.Name,
71-
runningOnCi
72-
? $"A file was renamed to '{renamed.NewFilePath}' but it has no redirect configuration set."
73-
: $"File '{renamed.OldFilePath}' was renamed to '{renamed.NewFilePath}' but it has no redirect configuration set.");
71+
$"File '{renamed.OldFilePath}' was renamed to '{renamed.NewFilePath}' but it has no redirect configuration set.");
7472
}
7573
else if (notFound.ChangeType is GitChangeType.Deleted)
7674
{

src/tooling/docs-builder/Tracking/IntegrationGitRepositoryTracker.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ public IEnumerable<GitChange> GetChangedFiles()
3333
var renamedFiles = Environment.GetEnvironmentVariable("RENAMED_FILES");
3434
if (!string.IsNullOrEmpty(renamedFiles))
3535
{
36-
foreach (var file in renamedFiles.Split(' ', StringSplitOptions.RemoveEmptyEntries).Where(f => f.StartsWith(LookupPath)))
37-
yield return new RenamedGitChange(string.Empty, file, GitChangeType.Renamed);
36+
foreach (var pair in renamedFiles.Split(' ', StringSplitOptions.RemoveEmptyEntries).Where(f => f.StartsWith(LookupPath)))
37+
{
38+
var parts = pair.Split(':');
39+
if (parts.Length == 2)
40+
yield return new RenamedGitChange(parts[0], parts[1], GitChangeType.Renamed);
41+
}
3842
}
3943
}
4044
}

0 commit comments

Comments
 (0)