Skip to content

Commit

Permalink
feat(validate/input-markup): add option to validate input markup (#157)
Browse files Browse the repository at this point in the history
Co-authored-by: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com>
  • Loading branch information
dontcallmedom and sidvishnoi committed Apr 10, 2024
1 parent 91a0055 commit f3998bb
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 3 deletions.
13 changes: 13 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ inputs:
BUILD_FAIL_ON:
description: Exit behaviour on errors.
default: fatal
VALIDATE_INPUT_MARKUP:
description: Validate input markup
default: "false"
VALIDATE_LINKS:
description: Validate hyperlinks
default: "false"
Expand Down Expand Up @@ -93,6 +96,16 @@ runs:
env:
INPUTS_TOOLCHAIN: ${{ steps.prepare.outputs.build && fromJson(steps.prepare.outputs.build).toolchain }}

- name: Validate input markup
run: |
echo "::group::Validate input markup"
node --enable-source-maps ${{ github.action_path }}/src/validate-input-markup.js
echo "::endgroup::"
shell: bash
env:
INPUTS_VALIDATE_INPUT_MARKUP: ${{ steps.prepare.outputs.validate && fromJson(steps.prepare.outputs.validate).input_markup }}
INPUTS_BUILD: ${{ steps.prepare.outputs.build && toJSON(fromJson(steps.prepare.outputs.build)) }}

- name: Generate Static HTML
id: build
run: |
Expand Down
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
specs.
</li>
<li>
Validate generated document's markup and check for broken hyperlinks.
Validate input/generated document's markup and check for broken
hyperlinks.
</li>
<li>
Publish generated spec to GitHub Pages and/or w3.org (using Echidna).
Expand Down
10 changes: 9 additions & 1 deletion docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ The Action will try to make use of metadata/config from previously published ver
# respec -s index.html?specStatus=WD&shortName=my-custom-shortname… -o OUTPUT
```

## `VALIDATE_INPUT_MARKUP`

Whether or not to validate the markup of the input document using the [Nu Html Checker](https://github.com/validator/validator). This option is unlikely to be useful for Bikeshed documents, or for ReSpec documents based on markdown.

**Possible values:** true, false

**Default:** false

## `VALIDATE_WEBIDL`

Whether or not to validate the Web IDL that the spec may define.
Expand All @@ -122,7 +130,7 @@ Whether or not to check for broken hyperlinks.

## `VALIDATE_MARKUP`

Whether or not to validate markup using the [Nu Html Checker](https://github.com/validator/validator).
Whether or not to validate markup of the generated document using the [Nu Html Checker](https://github.com/validator/validator).

**Possible values:** true, false

Expand Down
3 changes: 2 additions & 1 deletion src/prepare-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { yesOrNo, exit } from "./utils.js";
import { Inputs } from "./prepare.js";

export function validation(inputs: Inputs) {
const input_markup = yesOrNo(inputs.VALIDATE_INPUT_MARKUP) || false;
const links = yesOrNo(inputs.VALIDATE_LINKS) || false;
const markup = yesOrNo(inputs.VALIDATE_MARKUP) || false;
const pubrules = yesOrNo(inputs.VALIDATE_PUBRULES) || false;
if (pubrules && !inputs.W3C_API_KEY) {
exit("The W3C_API_KEY input is required with VALIDATE_PUBRULES");
}
const webidl = yesOrNo(inputs.VALIDATE_WEBIDL) || false;
return { links, markup, pubrules, webidl };
return { input_markup, links, markup, pubrules, webidl };
}
1 change: 1 addition & 0 deletions src/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Inputs {
DESTINATION: string;
BUILD_FAIL_ON: string;
VALIDATE_LINKS: string;
VALIDATE_INPUT_MARKUP: string;
VALIDATE_MARKUP: string;
VALIDATE_PUBRULES: string;
VALIDATE_WEBIDL: string;
Expand Down
28 changes: 28 additions & 0 deletions src/validate-input-markup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { env, exit, install, sh, yesOrNo } from "./utils.js";

import { ProcessedInput } from "./prepare.js";
type Input = Pick<ProcessedInput["build"], "source">;

if (module === require.main) {
if (yesOrNo(env("INPUTS_VALIDATE_INPUT_MARKUP")) === false) {
exit("Skipped", 0);
}

const input: Input = JSON.parse(env("INPUTS_BUILD"));
main(input).catch(err => exit(err.message || "Failed", err.code));
}

export default async function main({ source }: Input) {
console.log(`Validating ${source}...`);
await install("vnu-jar");
const vnuJar = require("vnu-jar");

try {
await sh(`java -jar "${vnuJar}" ${source}`, {
output: "stream",
});
exit("✅ Looks good! No HTML validation errors!", 0);
} catch {
exit("❌ Not so good... please fix the issues above.");
}
}
1 change: 1 addition & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const run = (fn: AsyncFn) => async () => {
Promise.resolve()
.then(run(require("./prepare.test.js").default))
.then(run(require("./setup.test.js").default))
.then(run(require("./validate-input-markup.test.js").default))
.then(run(require("./build.test.js").default))
.then(run(require("./validate-links.test.js").default))
.then(run(require("./validate-markup.test.js").default))
Expand Down
14 changes: 14 additions & 0 deletions test/validate-input-markup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import main from "../src/validate-input-markup.js";
import { Outputs } from "./index.test.js";

export default async function validateInputMarkup(outputs: Outputs) {
const { input_markup: shouldValidate = false } =
outputs?.prepare?.validate || {};
if (shouldValidate === false) {
return;
}

const { source } = outputs?.prepare?.build || { source: "index.html" };

return await main({ source });
}

0 comments on commit f3998bb

Please sign in to comment.