Skip to content

Commit b4c88de

Browse files
committed
Fail the build on CI if new cachable SVG files are discovered
1 parent 4e3a416 commit b4c88de

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/Elastic.Documentation.Configuration/Diagram/DiagramRegistry.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Collections.Concurrent;
66
using System.IO.Abstractions;
7+
using Elastic.Documentation.Diagnostics;
78
using Elastic.Documentation.Extensions;
89
using Microsoft.Extensions.Logging;
910

@@ -70,6 +71,13 @@ public async Task<int> CreateDiagramCachedFiles(Cancel ctx)
7071
if (_readFileSystem.File.Exists(diagramInfo.OutputFile.FullName))
7172
return;
7273

74+
// If we are running on CI, and we are creating cached files we should fail the build and alert the user to create them
75+
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI")))
76+
{
77+
context.Collector.EmitGlobalError($"Discovered new diagram SVG '{localPath}' please run `docs-builder --force` to ensure a cached version is generated");
78+
return;
79+
}
80+
7381
// Create the directory if needed
7482
var directory = _writeFileSystem.Path.GetDirectoryName(diagramInfo.OutputFile.FullName);
7583
if (directory != null && !_writeFileSystem.Directory.Exists(directory))

src/Elastic.Documentation/Diagnostics/IDiagnosticsCollector.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,3 @@ public static void EmitGlobalWarning(this IDiagnosticsCollector collector, strin
5353
public static void EmitGlobalHint(this IDiagnosticsCollector collector, string message) =>
5454
collector.EmitHint(string.Empty, message);
5555
}
56-
57-

src/Elastic.Markdown/DocumentationGenerator.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ public async Task CreateDiagramCachedFiles(Cancel ctx)
161161
{
162162
var downloadedCount = await DocumentationSet.DiagramRegistry.CreateDiagramCachedFiles(ctx);
163163
if (downloadedCount > 0)
164-
{
165164
_logger.LogInformation("Downloaded {DownloadedCount} diagram files from Kroki", downloadedCount);
166-
}
167165
}
168166

169167
/// <summary>

src/tooling/docs-builder/Http/DocumentationWebHost.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,12 @@ private static async Task<IResult> ServeDocumentationFile(ReloadableGeneratorSta
193193
var generator = holder.Generator;
194194
const string navPartialSuffix = ".nav.html";
195195

196-
// Check if the original request is asking for LLM-rendered markdown
196+
// Check if the original request is asking for LLM-rendered Markdown
197197
var requestLlmMarkdown = slug.EndsWith(".md");
198-
var originalSlug = slug;
199198

200199
// If requesting .md output, remove the .md extension to find the source file
201200
if (requestLlmMarkdown)
202-
{
203201
slug = slug[..^3]; // Remove ".md" extension
204-
}
205202

206203
if (slug.EndsWith(navPartialSuffix))
207204
{
@@ -258,9 +255,7 @@ private static async Task<IResult> ServeDocumentationFile(ReloadableGeneratorSta
258255
{
259256
var svgPath = Path.Combine(generator.DocumentationSet.OutputDirectory.FullName, slug.TrimStart('/'));
260257
if (File.Exists(svgPath))
261-
{
262258
return Results.File(svgPath, "image/svg+xml");
263-
}
264259
}
265260

266261
if (!generator.DocumentationSet.FlatMappedFiles.TryGetValue("404.md", out var notFoundDocumentationFile))

0 commit comments

Comments
 (0)