Skip to content

Commit 51c5df4

Browse files
authored
ci(docgen): docs now warn/throw on missing descriptions again (#289)
and because we now build those in the tests, it tells us BEFORE the PR is merged
1 parent fbd75e6 commit 51c5df4

File tree

5 files changed

+61
-23
lines changed

5 files changed

+61
-23
lines changed

ci/docs/default.nix

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let
1616
descriptionStartsOpen ? null,
1717
descriptionIncluded ? null,
1818
moduleStartsOpen ? null,
19+
warningsAreErrors ? true,
1920
}:
2021
name: module:
2122
(if title != null then "# ${title}\n\n" else "# `${prefix}${name}`\n\n")
@@ -29,7 +30,7 @@ let
2930
}
3031
]
3132
// {
32-
inherit includeCore;
33+
inherit includeCore warningsAreErrors;
3334
${if descriptionStartsOpen != null then "descriptionStartsOpen" else null} = descriptionStartsOpen;
3435
${if descriptionIncluded != null then "descriptionIncluded" else null} = descriptionIncluded;
3536
${if moduleStartsOpen != null then "moduleStartsOpen" else null} = moduleStartsOpen;
@@ -42,13 +43,18 @@ in
4243
wlib.wrapperModules.mdbook
4344
./redirects.nix
4445
];
45-
mainBook = "nix-wrapper-modules";
46-
outputs = [
46+
config.mainBook = "nix-wrapper-modules";
47+
config.outputs = [
4748
"out"
4849
"generated"
4950
];
50-
drv.unsafeDiscardReferences.generated = true;
51-
drv.preBuild = ''
51+
options.warningsAreErrors = lib.mkOption {
52+
type = lib.types.bool;
53+
default = true;
54+
description = "Whether warnings in the docgen should be treated as errors (i.e. missing descriptions)";
55+
};
56+
config.drv.unsafeDiscardReferences.generated = true;
57+
config.drv.preBuild = ''
5258
mkdir -p "$generated/wrapper_docs"
5359
jq -r '.wrapper_docs | to_entries[] | @base64' "$NIX_ATTRS_JSON_FILE" | while read -r entry; do
5460
# decode base64 to get JSON safely
@@ -61,10 +67,11 @@ in
6167
echo "$(echo "$decoded" | jq -r '.value')" > "$generated/module_docs/$(echo "$decoded" | jq -r '.key').md"
6268
done
6369
'';
64-
drv.module_docs = builtins.mapAttrs (buildModuleDocs {
70+
config.drv.module_docs = builtins.mapAttrs (buildModuleDocs {
6571
prefix = "wlib.modules.";
6672
package = pkgs.hello;
6773
includeCore = false;
74+
inherit (config) warningsAreErrors;
6875
moduleStartsOpen = _: _: true;
6976
descriptionStartsOpen =
7077
_: _: _:
@@ -73,14 +80,16 @@ in
7380
_: _: _:
7481
true;
7582
}) wlib.modules;
76-
drv.wrapper_docs = builtins.mapAttrs (buildModuleDocs {
83+
config.drv.wrapper_docs = builtins.mapAttrs (buildModuleDocs {
7784
prefix = "wlib.wrapperModules.";
85+
inherit (config) warningsAreErrors;
7886
}) wlib.wrapperModules;
79-
drv.core_docs = buildModuleDocs {
87+
config.drv.core_docs = buildModuleDocs {
8088
package = pkgs.hello;
89+
inherit (config) warningsAreErrors;
8190
title = "Core (builtin) Options set";
8291
} "core" { };
83-
books.nix-wrapper-modules = {
92+
config.books.nix-wrapper-modules = {
8493
book = {
8594
book = {
8695
src = "src";

ci/docs/per-mod/default.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ rec {
6969
builtins.unsafeDiscardStringContext
7070
];
7171

72-
# TODO: should have a warning for missing descriptions
73-
# and also a warnings as errors setting
7472
wrapperModuleMD = import ./rendermd.nix {
7573
inherit
7674
wlib

ci/docs/per-mod/rendermd.nix

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
includeCore ? true,
1212
transform ? null,
1313
prefix ? false,
14+
warningsAreErrors ? true,
1415
nameFromModule ?
1516
{ file, ... }:
1617
lib.removeSuffix "/module.nix" (lib.removePrefix "${wlib.modulesPath}/" (toString file)),
@@ -65,20 +66,33 @@ let
6566
lib.optionalString (opt ? "${n}" && lib.isStringLike opt.${n}) (
6667
lib.optionalString (desc != "") "${desc}\n" + "${opt.${n}}\n\n"
6768
);
68-
renderOption = opt: ''
69-
## `${lib.options.showOption (opt.loc or [ ])}`
69+
mkWarn = opt: "nix-wrapper-modules docgen warning: Option ${opt.name} has no description";
70+
renderOption =
71+
opt:
72+
# TODO: This should probably collect all the warnings until the end
73+
# so it says everything which is missing a description
74+
# rather than just the first one even if warningsAreErrors is true.
75+
# For now, one can run it with warningsAreErrors = false to see them all.
76+
(
77+
if opt.description or "" == "" || opt.description or null == null then
78+
if warningsAreErrors == true then throw (mkWarn opt) else lib.warn (mkWarn opt)
79+
else
80+
(v: v)
81+
)
82+
''
83+
## `${lib.options.showOption (opt.loc or [ ])}`
7084
71-
${mkOptField opt "description" ""}${mkOptField opt "relatedPackages" "Related packages:\n"}${
72-
mkOptField opt "type" "Type:${lib.optionalString (opt.readOnly or false == true) " (read-only)"}"
73-
}${mkOptField opt "default" "Default:"}${mkOptField opt "example" "Example:"}${
74-
lib.optionalString (opt.declarations or [ ] != [ ]) ''
75-
Declared by:
85+
${mkOptField opt "description" ""}${mkOptField opt "relatedPackages" "Related packages:\n"}${
86+
mkOptField opt "type" "Type:${lib.optionalString (opt.readOnly or false == true) " (read-only)"}"
87+
}${mkOptField opt "default" "Default:"}${mkOptField opt "example" "Example:"}${
88+
lib.optionalString (opt.declarations or [ ] != [ ]) ''
89+
Declared by:
7690
77-
${declaredBy opt}
91+
${declaredBy opt}
7892
79-
''
80-
}
81-
'';
93+
''
94+
}
95+
'';
8296
renderModule =
8397
i: mod:
8498
let

ci/flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@
5858
system: (wlib-flake (import nixpkgs { inherit system; })).formatter.${system}
5959
);
6060
packages = forAllSystems (system: {
61-
default = self.packages.${system}.docs;
61+
default = self.packages.${system}.docs.wrap { warningsAreErrors = true; };
6262
docs = wlib.evalPackage [
6363
./docs
6464
{
65+
warningsAreErrors = false;
6566
pkgs = import nixpkgs {
6667
inherit system;
6768
config = {

wrapperModules/m/mdbook/module.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@ in
209209
'';
210210
};
211211
books = lib.mkOption {
212+
description = ''
213+
A set of books to generate along with the mdbook derivation.
214+
215+
It will also create a build script for each one.
216+
217+
That build script will be a wrapped mdbook executable.
218+
219+
It will run something like the following:
220+
221+
`mdbook build -d $firstArg "''${otherArgs[@]}" <generated-book-subdir>`
222+
223+
You could modify it further with the `wrapperVariants` attribute of the same name,
224+
for example to add a `-o` flag.
225+
226+
Or use it as the main command for running via `nix run` in a build pipeline using `mainBook = "this_book";`
227+
'';
212228
default = { };
213229
type = lib.types.attrsOf (
214230
lib.types.submodule (

0 commit comments

Comments
 (0)