Skip to content

Commit

Permalink
Workflow: Add steps to run tools/lint.mjs after spec is built (webmac…
Browse files Browse the repository at this point in the history
…hinelearning#728)

Help catch errors by running our bespoke lint tool after the normal
publish/deploy. Ideally, in the future this would be integrated into
spec-prod to avoid some duplicate work, and made more modular and
robust. But hopefully it's better than nothing!
  • Loading branch information
inexorabletash authored Jul 18, 2024
1 parent 92ff390 commit 9a80799
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/auto-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,21 @@ jobs:
W3C_BUILD_OVERRIDE: |
TR: https://www.w3.org/TR/webnn/
status: CRD
- name: WebNN - Lint Bikeshed Source and Generated HTML
id: webnn-lint
shell: bash
env:
BIKESHED_SOURCE: "index.bs"
GENERATED_HTML: "index.bs.built.html"
run: |
echo "::group::Install Lint Tool Dependencies"
cd tools
npm install
cd ..
echo "::endgroup::"
echo "::group::Generate Static HTML"
bikeshed --die-on=warning spec $BIKESHED_SOURCE $GENERATED_HTML
echo "::endgroup::"
echo "::group::Run Lint Tool"
node tools/lint.mjs --verbose --bikeshed $BIKESHED_SOURCE --html $GENERATED_HTML
echo "::endgroup::"
24 changes: 18 additions & 6 deletions tools/lint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
// Note that the '.mjs' extension is necessary for Node.js to treat the file as
// a module. There is an `--experimental-default-type=module` flag but
// specifying that in the #! line requires trickery that confuses some editors.

//
// Options:
// --verbose Log progress.
// --bikeshed PATH_TO_BS_FILE Bikeshed source path. (default: "index.bs")
// --html PATH_TO_HTML_FILE Generated HTML path. (default: "index.html")

'use strict';
import fs from 'node:fs/promises';
Expand All @@ -21,14 +25,20 @@ import {parse} from 'node-html-parser';

const options = {
verbose: false,
bikeshed: 'index.bs',
html: 'index.html',
};

// First two args are interpreter and script
globalThis.process.argv.slice(2).forEach(arg => {
globalThis.process.argv.slice(2).forEach((arg, index, array) => {
if (arg === '--verbose' || arg === '-v') {
options.verbose = true;
} else if (arg === '--bikeshed' && array.length > index + 1) {
options.bikeshed = array.splice(index + 1, 1)[0];
} else if (arg === '--html' && array.length > index + 1) {
options.html = array.splice(index + 1, 1)[0];
} else {
console.error(`Unknown argment: ${arg}`);
console.error(`Unknown or incomplete argument: ${arg}`);
globalThis.process.exit(1);
}
});
Expand All @@ -43,9 +53,11 @@ function log(string) {
// Load and parse file
// --------------------------------------------------

log('loading files...');
const source = await fs.readFile('index.bs', 'utf8');
let file = await fs.readFile('index.html', 'utf8');
log(`loading Bikeshed source "${options.bikeshed}"...`);
const source = await fs.readFile(options.bikeshed, 'utf8');

log(`loading generated HTML "${options.html}"...`);
let file = await fs.readFile(options.html, 'utf8');

log('massaging HTML...');
// node-html-parser doesn't understand that DT and DD are mutually self-closing;
Expand Down

0 comments on commit 9a80799

Please sign in to comment.