Skip to content

Commit 07607b8

Browse files
committed
Add "strict" mode to treat warnings as errors
This adds a "strict" input option to the publish action and CLI commands. When enabled, warnings are treated as errors, causing builds to fail on warnings. It's an optional setting for stricter validation during documentation generation.
1 parent a9425a9 commit 07607b8

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ inputs:
99
prefix:
1010
description: 'Path prefix for all urls'
1111
required: false
12+
strict:
13+
description: 'Treat warnings as errors'
14+
required: false
1215

1316
runs:
1417
using: 'docker'

actions/publish/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ outputs:
1010
description: "The github actions url"
1111
value: ${{steps.deployment.outputs.page_url}}
1212

13+
inputs:
14+
strict:
15+
description: 'Treat warnings as errors'
16+
required: false
17+
1318
runs:
1419
using: "composite"
1520
steps:
@@ -20,6 +25,7 @@ runs:
2025
uses: elastic/docs-builder@main
2126
with:
2227
prefix: '${{ steps.repo-basename.outputs.value }}'
28+
strict: ${{ inputs.strict }}
2329
- name: Setup Pages
2430
id: pages
2531
uses: actions/[email protected]

src/docs-builder/Cli/Commands.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public async Task Serve(string? path = null, Cancel ctx = default)
3939
/// <param name="output"> -o, Defaults to `.artifacts/html` </param>
4040
/// <param name="pathPrefix"> Specifies the path prefix for urls </param>
4141
/// <param name="force"> Force a full rebuild of the destination folder</param>
42+
/// <param name="strict"> Treat warnings as errors and fail the build on warnings</param>
4243
/// <param name="ctx"></param>
4344
[Command("generate")]
4445
[ConsoleAppFilter<StopwatchFilter>]
@@ -48,6 +49,7 @@ public async Task<int> Generate(
4849
string? output = null,
4950
string? pathPrefix = null,
5051
bool? force = null,
52+
bool? strict = null,
5153
Cancel ctx = default
5254
)
5355
{
@@ -62,7 +64,13 @@ public async Task<int> Generate(
6264
var set = new DocumentationSet(context);
6365
var generator = new DocumentationGenerator(set, logger);
6466
await generator.GenerateAll(ctx);
65-
return context.Collector.Errors + context.Collector.Warnings;
67+
68+
if (bool.TryParse(githubActionsService.GetInput("strict"), out var strictValue) && strictValue)
69+
strict ??= strictValue;
70+
71+
if (strict ?? false)
72+
return context.Collector.Errors + context.Collector.Warnings;
73+
return context.Collector.Errors;
6674
}
6775

6876
/// <summary>
@@ -72,6 +80,7 @@ public async Task<int> Generate(
7280
/// <param name="output"> -o, Defaults to `.artifacts/html` </param>
7381
/// <param name="pathPrefix"> Specifies the path prefix for urls </param>
7482
/// <param name="force"> Force a full rebuild of the destination folder</param>
83+
/// <param name="strict"> Treat warnings as errors and fail the build on warnings</param>
7584
/// <param name="ctx"></param>
7685
[Command("")]
7786
[ConsoleAppFilter<StopwatchFilter>]
@@ -81,7 +90,8 @@ public async Task<int> GenerateDefault(
8190
string? output = null,
8291
string? pathPrefix = null,
8392
bool? force = null,
93+
bool? strict = null,
8494
Cancel ctx = default
8595
) =>
86-
await Generate(path, output, pathPrefix, force, ctx);
96+
await Generate(path, output, pathPrefix, force, strict, ctx);
8797
}

0 commit comments

Comments
 (0)