Skip to content

Commit 5f92101

Browse files
committed
Also write the used link-index to the filesystem and add it as part of the new CheckoutResult record
1 parent c73a00a commit 5f92101

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

src/tooling/docs-assembler/Cli/RepositoryCommands.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Documentation.Assembler.Navigation;
1919
using Documentation.Assembler.Sourcing;
2020
using Elastic.Documentation.Configuration.Assembler;
21+
using Elastic.Documentation.Links;
2122
using Elastic.Documentation.Tooling.Diagnostics.Console;
2223
using Elastic.Markdown;
2324
using Elastic.Markdown.Exporters;
@@ -106,7 +107,9 @@ public async Task<int> BuildAll(
106107
}
107108

108109
var cloner = new AssemblerRepositorySourcer(logger, assembleContext);
109-
var checkouts = cloner.GetAll().ToArray();
110+
var checkoutResult = cloner.GetAll();
111+
var checkouts = checkoutResult.Checkouts.ToArray();
112+
110113
if (checkouts.Length == 0)
111114
throw new Exception("No checkouts found");
112115

@@ -123,6 +126,15 @@ public async Task<int> BuildAll(
123126
var builder = new AssemblerBuilder(logger, assembleContext, navigation, htmlWriter, pathProvider, historyMapper);
124127
await builder.BuildAllAsync(assembleSources.AssembleSets, ctx);
125128

129+
if (checkoutResult.LinkRegistrySnapshot is { } linkRegistry)
130+
{
131+
await File.WriteAllTextAsync(
132+
Path.Combine(assembleContext.OutputDirectory.FullName, "docs", CheckoutResult.LinkRegistrySnapshotFileName),
133+
LinkRegistry.Serialize(linkRegistry),
134+
ctx
135+
);
136+
}
137+
126138
var sitemapBuilder = new SitemapBuilder(navigation.NavigationItems, assembleContext.WriteFileSystem, assembleContext.OutputDirectory);
127139
sitemapBuilder.Generate();
128140

src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Elastic.Documentation.Configuration.Assembler;
1010
using Elastic.Documentation.Diagnostics;
1111
using Elastic.Documentation.LinkIndex;
12+
using Elastic.Documentation.Links;
1213
using Elastic.Markdown.IO;
1314
using Microsoft.Extensions.Logging;
1415
using ProcNet;
@@ -25,7 +26,7 @@ public class AssemblerRepositorySourcer(ILoggerFactory logger, AssembleContext c
2526

2627
private RepositorySourcer RepositorySourcer => new(logger, context.CheckoutDirectory, context.ReadFileSystem, context.Collector);
2728

28-
public IReadOnlyCollection<Checkout> GetAll()
29+
public CheckoutResult GetAll()
2930
{
3031
var fs = context.ReadFileSystem;
3132
var repositories = Configuration.ReferenceRepositories.Values.Concat<Repository>([Configuration.Narrative]);
@@ -43,11 +44,19 @@ public IReadOnlyCollection<Checkout> GetAll()
4344
};
4445
checkouts.Add(checkout);
4546
}
46-
47-
return checkouts;
47+
var linkRegistrySnapshotPath = Path.Combine(context.CheckoutDirectory.FullName, CheckoutResult.LinkRegistrySnapshotFileName);
48+
if (!fs.File.Exists(linkRegistrySnapshotPath))
49+
throw new FileNotFoundException("Link-index snapshot not found. Run the clone-all command first.", linkRegistrySnapshotPath);
50+
var linkRegistrySnapshotStr = File.ReadAllText(linkRegistrySnapshotPath);
51+
var linkRegistry = LinkRegistry.Deserialize(linkRegistrySnapshotStr);
52+
return new CheckoutResult
53+
{
54+
Checkouts = checkouts,
55+
LinkRegistrySnapshot = linkRegistry
56+
};
4857
}
4958

50-
public async Task<IReadOnlyCollection<Checkout>> CloneAll(bool fetchLatest, Cancel ctx = default)
59+
public async Task<CheckoutResult> CloneAll(bool fetchLatest, Cancel ctx = default)
5160
{
5261
_logger.LogInformation("Cloning all repositories for environment {EnvironmentName} using '{ContentSourceStrategy}' content sourcing strategy",
5362
PublishEnvironment.Name,
@@ -91,7 +100,16 @@ await Task.Run(() =>
91100
checkouts.Add(RepositorySourcer.CloneRef(repo.Value, gitRef, fetchLatest));
92101
}, c);
93102
}).ConfigureAwait(false);
94-
return checkouts;
103+
await File.WriteAllTextAsync(
104+
Path.Combine(context.CheckoutDirectory.FullName, CheckoutResult.LinkRegistrySnapshotFileName),
105+
LinkRegistry.Serialize(linkRegistry),
106+
ctx
107+
);
108+
return new CheckoutResult
109+
{
110+
Checkouts = checkouts,
111+
LinkRegistrySnapshot = linkRegistry
112+
};
95113
}
96114
}
97115

@@ -272,3 +290,10 @@ public void Write(Exception e) { }
272290

273291
public void Write(ConsoleOut consoleOut) { }
274292
}
293+
294+
public record CheckoutResult
295+
{
296+
public static string LinkRegistrySnapshotFileName => "link-index.snapshot.json";
297+
public required LinkRegistry LinkRegistrySnapshot { get; init; }
298+
public required IReadOnlyCollection<Checkout> Checkouts { get; init; }
299+
}

0 commit comments

Comments
 (0)