Skip to content

Commit 47157a3

Browse files
committed
Add ConfigurationExporter to export all congigurations to a central location.
In preparation of separating configuration from releases.
1 parent 6684cf2 commit 47157a3

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

src/tooling/docs-assembler/Building/AssemblerBuilder.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public enum ExportOption
2020
{
2121
Html = 0,
2222
LLMText = 1,
23-
Elasticsearch = 2
23+
Elasticsearch = 2,
24+
Configuration = 3
2425
}
2526

2627
public class AssemblerBuilder(
@@ -55,9 +56,11 @@ public async Task BuildAllAsync(FrozenDictionary<string, AssemblerDocumentationS
5556
var markdownExporters = new List<IMarkdownExporter>(3);
5657
if (exportOptions.Contains(ExportOption.LLMText))
5758
markdownExporters.Add(new LLMTextExporter());
59+
if (exportOptions.Contains(ExportOption.Configuration))
60+
markdownExporters.Add(new ConfigurationExporter(logFactory, context));
5861
if (exportOptions.Contains(ExportOption.Elasticsearch) && esExporter is { })
5962
markdownExporters.Add(esExporter);
60-
var noopBuild = !exportOptions.Contains(ExportOption.Html);
63+
var noHtmlOutput = !exportOptions.Contains(ExportOption.Html);
6164

6265
var tasks = markdownExporters.Select(async e => await e.StartAsync(ctx));
6366
await Task.WhenAll(tasks);
@@ -73,7 +76,7 @@ public async Task BuildAllAsync(FrozenDictionary<string, AssemblerDocumentationS
7376

7477
try
7578
{
76-
var result = await BuildAsync(set, noopBuild, markdownExporters.ToArray(), ctx);
79+
var result = await BuildAsync(set, noHtmlOutput, markdownExporters.ToArray(), ctx);
7780
CollectRedirects(redirects, result.Redirects, checkout.Repository.Name, set.DocumentationSet.LinkResolver);
7881
}
7982
catch (Exception e) when (e.Message.Contains("Can not locate docset.yml file in"))

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public async Task<int> BuildAll(
8585
[ExporterParser] IReadOnlySet<ExportOption>? exporters = null,
8686
Cancel ctx = default)
8787
{
88-
exporters ??= new HashSet<ExportOption>([ExportOption.Html]);
88+
exporters ??= new HashSet<ExportOption>([ExportOption.Html, ExportOption.Configuration]);
8989

9090
AssignOutputLogger();
9191
var githubEnvironmentInput = githubActionsService.GetInput("environment");
@@ -223,7 +223,7 @@ public class ExporterParserAttribute : Attribute, IArgumentParser<IReadOnlySet<E
223223
{
224224
public static bool TryParse(ReadOnlySpan<char> s, out IReadOnlySet<ExportOption> result)
225225
{
226-
result = new HashSet<ExportOption>([ExportOption.Html]);
226+
result = new HashSet<ExportOption>([ExportOption.Html, ExportOption.Configuration]);
227227
var set = new HashSet<ExportOption>();
228228
var ranges = s.Split(',');
229229
foreach (var range in ranges)
@@ -235,6 +235,7 @@ public static bool TryParse(ReadOnlySpan<char> s, out IReadOnlySet<ExportOption>
235235
"es" => ExportOption.Elasticsearch,
236236
"elasticsearch" => ExportOption.Elasticsearch,
237237
"html" => ExportOption.Html,
238+
"config" => ExportOption.Configuration,
238239
_ => null
239240
};
240241
if (export.HasValue)

src/tooling/docs-assembler/Exporters/ElasticsearchMarkdownExporter.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,43 @@
1616

1717
namespace Documentation.Assembler.Exporters;
1818

19+
public class ConfigurationExporter(ILoggerFactory logFactory, AssembleContext context) : IMarkdownExporter
20+
{
21+
private readonly ILogger<ConfigurationExporter> _logger = logFactory.CreateLogger<ConfigurationExporter>();
22+
23+
/// <inheritdoc />
24+
public ValueTask StartAsync(CancellationToken ctx = default) => default;
25+
26+
/// <inheritdoc />
27+
public ValueTask StopAsync(CancellationToken ctx = default) => default;
28+
29+
/// <inheritdoc />
30+
public ValueTask<bool> ExportAsync(MarkdownExportFileContext fileContext, CancellationToken ctx) => default;
31+
32+
/// <inheritdoc />
33+
public ValueTask<bool> FinishExportAsync(IDirectoryInfo outputFolder, CancellationToken ctx)
34+
{
35+
_logger.LogInformation("Exporting configuration");
36+
var config = context.ConfigurationPath;
37+
var fs = context.WriteFileSystem;
38+
var configFolder = fs.DirectoryInfo.New(Path.Combine(context.OutputDirectory.FullName, "config"));
39+
if (!configFolder.Exists)
40+
configFolder.Create();
41+
42+
_logger.LogInformation("Exporting {Name} to {ConfigFolder}", config.Name, configFolder.FullName);
43+
context.WriteFileSystem.File.Copy(config.FullName, Path.Combine(configFolder.FullName, config.Name), true);
44+
45+
_logger.LogInformation("Exporting {Name} to {ConfigFolder}", context.NavigationPath.Name, configFolder.FullName);
46+
context.WriteFileSystem.File.Copy(context.NavigationPath.FullName, Path.Combine(configFolder.FullName, context.NavigationPath.Name), true);
47+
48+
_logger.LogInformation("Exporting {Name} to {ConfigFolder}", context.HistoryMappingPath.Name, configFolder.FullName);
49+
context.WriteFileSystem.File.Copy(context.HistoryMappingPath.FullName, Path.Combine(configFolder.FullName, context.HistoryMappingPath.Name), true);
50+
51+
52+
return default;
53+
}
54+
}
55+
1956
public class ElasticsearchMarkdownExporter : IMarkdownExporter, IDisposable
2057
{
2158
private readonly DiagnosticsCollector _collector;

0 commit comments

Comments
 (0)