@dcaldeira/tooling 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +34 -3
- package/checks/a11y.mjs +206 -0
- package/checks/architecture.mjs +137 -0
- package/checks/audit.mjs +121 -0
- package/checks/bundle.mjs +126 -0
- package/checks/dependencies.mjs +277 -0
- package/checks/lint-scss.mjs +349 -0
- package/checks/package.mjs +30 -0
- package/checks/playwright-summary.mjs +53 -0
- package/checks/sass.mjs +67 -0
- package/checks/scan-secrets.mjs +58 -0
- package/checks/shared.mjs +86 -0
- package/checks/style-property-order.json +498 -0
- package/checks/translations.mjs +55 -0
- package/checks/visual-compare.mjs +148 -0
- package/checks/visual-report-html.mjs +470 -0
- package/checks/visual-report.mjs +13 -0
- package/config.schema.json +927 -0
- package/configs/eslint.mjs +27 -0
- package/configs/knip.json +11 -0
- package/configs/playwright.mjs +15 -0
- package/configs/prettier.mjs +1 -0
- package/configs/tsconfig.json +16 -0
- package/configs/vitest.mjs +16 -0
- package/package.json +105 -6
- package/release/evidence.mjs +62 -0
- package/release/finalize.mjs +65 -0
- package/release/gh.mjs +25 -0
- package/release/github.mjs +64 -0
- package/release/prepare.mjs +30 -0
- package/runner/browsers.mjs +73 -0
- package/runner/cache.mjs +121 -0
- package/runner/ci-plan.mjs +54 -0
- package/runner/cli.mjs +249 -0
- package/runner/config.mjs +148 -0
- package/runner/docs-install.mjs +93 -0
- package/runner/execute.mjs +286 -0
- package/runner/generate.mjs +122 -0
- package/runner/git.mjs +122 -0
- package/runner/graph.mjs +243 -0
- package/runner/index.mjs +4 -0
- package/runner/insights.mjs +313 -0
- package/runner/provision.mjs +53 -0
- package/runner/report.mjs +35 -0
- package/runner/serve-static.mjs +76 -0
- package/runner/setup.mjs +237 -0
- package/runner/summary.mjs +112 -0
- package/runner/watch.mjs +82 -0
- package/templates/ci.yml +25 -0
- package/templates/dependabot-merge.yml +13 -0
- package/templates/dependabot.yml +26 -0
- package/templates/pre-push +13 -0
- package/templates/release.yml +23 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createReadStream, realpathSync, statSync } from 'node:fs';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { extname, isAbsolute, relative, resolve } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const types = {
|
|
7
|
+
'.html': 'text/html; charset=utf-8',
|
|
8
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
9
|
+
'.mjs': 'text/javascript; charset=utf-8',
|
|
10
|
+
'.css': 'text/css; charset=utf-8',
|
|
11
|
+
'.json': 'application/json; charset=utf-8',
|
|
12
|
+
'.svg': 'image/svg+xml',
|
|
13
|
+
'.woff2': 'font/woff2',
|
|
14
|
+
'.woff': 'font/woff',
|
|
15
|
+
'.png': 'image/png',
|
|
16
|
+
'.webp': 'image/webp',
|
|
17
|
+
'.ico': 'image/x-icon',
|
|
18
|
+
'.wasm': 'application/wasm',
|
|
19
|
+
};
|
|
20
|
+
const contained = (root, target) => {
|
|
21
|
+
const path = relative(root, target);
|
|
22
|
+
return path !== '..' && !path.startsWith('../') && !path.startsWith('..\\') && !isAbsolute(path);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function staticServer(directory) {
|
|
26
|
+
const root = realpathSync(directory);
|
|
27
|
+
return createServer((request, response) => {
|
|
28
|
+
if (!['GET', 'HEAD'].includes(request.method)) {
|
|
29
|
+
response.writeHead(405, { Allow: 'GET, HEAD' }).end();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let path;
|
|
33
|
+
try {
|
|
34
|
+
path = decodeURIComponent(new URL(request.url ?? '/', 'http://localhost').pathname);
|
|
35
|
+
} catch {
|
|
36
|
+
response.writeHead(400).end();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
let target = resolve(root, '.' + path);
|
|
40
|
+
if (!contained(root, target)) {
|
|
41
|
+
response.writeHead(403).end();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
if (statSync(target).isDirectory()) target = resolve(target, 'index.html');
|
|
46
|
+
target = realpathSync(target);
|
|
47
|
+
if (!contained(root, target)) {
|
|
48
|
+
response.writeHead(403).end();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!statSync(target).isFile()) {
|
|
52
|
+
response.writeHead(404).end();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
response.writeHead(404).end();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
response.writeHead(200, { 'content-type': types[extname(target)] ?? 'application/octet-stream' });
|
|
60
|
+
if (request.method === 'HEAD') response.end();
|
|
61
|
+
else createReadStream(target).on('error', () => response.destroy()).pipe(response);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
66
|
+
const [directory, port = '6217', required = 'index.html'] = process.argv.slice(2);
|
|
67
|
+
if (!directory || process.argv.length > 5 || !/^\d+$/.test(port) || Number(port) < 1 || Number(port) > 65535)
|
|
68
|
+
throw new Error('Usage: serve-static.mjs <directory> [port] [required-file]');
|
|
69
|
+
const root = realpathSync(directory);
|
|
70
|
+
const entry = realpathSync(resolve(root, required));
|
|
71
|
+
if (!contained(root, entry) || !statSync(entry).isFile())
|
|
72
|
+
throw new Error('Required build entry is outside the served directory or is not a file');
|
|
73
|
+
staticServer(root).listen(Number(port), '127.0.0.1', () => {
|
|
74
|
+
console.log(`Serving ${root} on http://127.0.0.1:${port}`);
|
|
75
|
+
});
|
|
76
|
+
}
|
package/runner/setup.mjs
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { inside, loadConfig, validateConfig } from './config.mjs';
|
|
4
|
+
import { builtins, plan } from './graph.mjs';
|
|
5
|
+
import { executable, packageManifest } from './execute.mjs';
|
|
6
|
+
import { git } from './git.mjs';
|
|
7
|
+
|
|
8
|
+
const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
9
|
+
const readJSON = (path) => JSON.parse(readFileSync(path, 'utf8'));
|
|
10
|
+
const json = (value) => JSON.stringify(value, null, 2) + '\n';
|
|
11
|
+
|
|
12
|
+
export function starterConfig({ preset = 'react-vite', app = 'frontend', scripts = {} } = {}) {
|
|
13
|
+
if (!['react-vite', 'workspace'].includes(preset))
|
|
14
|
+
throw new Error('Preset must be react-vite or workspace');
|
|
15
|
+
if (!/^[\w-]+(?:\/[\w-]+)*$/.test(app))
|
|
16
|
+
throw new Error('App must be a repository-relative directory');
|
|
17
|
+
const workspace = preset === 'workspace';
|
|
18
|
+
const cwd = workspace ? app : '.';
|
|
19
|
+
const enabled = ['format', 'lint', 'types', 'unit', 'build'];
|
|
20
|
+
const checks = Object.fromEntries(
|
|
21
|
+
Object.keys(builtins).map((id) => [id, enabled.includes(id) ? {} : false]),
|
|
22
|
+
);
|
|
23
|
+
const adapters = { lint: 'lint', types: 'typecheck', unit: 'test:coverage', build: 'build' };
|
|
24
|
+
for (const id of ['lint', 'types', 'unit', 'build']) {
|
|
25
|
+
checks[id].cwd = cwd;
|
|
26
|
+
if (workspace) checks[id].workspaces = ['app'];
|
|
27
|
+
if (scripts[adapters[id]]) checks[id].command = ['npm', 'run', adapters[id]];
|
|
28
|
+
}
|
|
29
|
+
const config = {
|
|
30
|
+
$schema: './node_modules/@dcaldeira/tooling/config.schema.json',
|
|
31
|
+
schemaVersion: 1,
|
|
32
|
+
execution: { concurrency: 2 },
|
|
33
|
+
...(workspace
|
|
34
|
+
? {
|
|
35
|
+
paths: { app: [`${app}/src/**`, 'shared/src/**'] },
|
|
36
|
+
workspaces: {
|
|
37
|
+
app: { paths: [`${app}/**`], dependsOn: ['shared'] },
|
|
38
|
+
shared: { paths: ['shared/**'] },
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
: {}),
|
|
42
|
+
checks,
|
|
43
|
+
};
|
|
44
|
+
validateConfig(config);
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function initialize(root, { preset = 'react-vite', app = 'frontend', toolingSha } = {}) {
|
|
49
|
+
if (toolingSha && !/^[a-f\d]{40}$/.test(toolingSha))
|
|
50
|
+
throw new Error('--tooling-sha must be a full 40-character commit SHA');
|
|
51
|
+
const packagePath = join(root, 'package.json');
|
|
52
|
+
const pkg = readJSON(packagePath);
|
|
53
|
+
const appPackage =
|
|
54
|
+
preset === 'workspace' ? readJSON(join(inside(root, app), 'package.json')) : pkg;
|
|
55
|
+
const config = starterConfig({ preset, app, scripts: appPackage.scripts });
|
|
56
|
+
const aliases = {
|
|
57
|
+
'check:dev': 'tooling --profile=dev --changed',
|
|
58
|
+
'check:push': 'tooling --profile=push --changed --bail',
|
|
59
|
+
'ci:local': 'tooling --profile=ci --all',
|
|
60
|
+
};
|
|
61
|
+
for (const [key, value] of Object.entries(aliases)) {
|
|
62
|
+
if (pkg.scripts?.[key] && pkg.scripts[key] !== value)
|
|
63
|
+
throw new Error(`Existing script ${key}; adapt it before initializing`);
|
|
64
|
+
}
|
|
65
|
+
const files = new Map([['tooling.config.json', json(config)]]);
|
|
66
|
+
const template = (name) =>
|
|
67
|
+
readFileSync(new URL(`../templates/${name}`, import.meta.url), 'utf8').replaceAll(
|
|
68
|
+
'REPLACE_WITH_TOOLING_COMMIT_SHA',
|
|
69
|
+
toolingSha ?? 'REPLACE_WITH_TOOLING_COMMIT_SHA',
|
|
70
|
+
);
|
|
71
|
+
files.set('.github/workflows/ci.yml', template('ci.yml'));
|
|
72
|
+
files.set('.github/workflows/dependabot-merge.yml', template('dependabot-merge.yml'));
|
|
73
|
+
files.set('.github/dependabot.yml', template('dependabot.yml'));
|
|
74
|
+
files.set('.githooks/pre-push', template('pre-push'));
|
|
75
|
+
files.set(
|
|
76
|
+
'prettier.config.mjs',
|
|
77
|
+
"export { default } from '@dcaldeira/tooling/configs/prettier.mjs';\n",
|
|
78
|
+
);
|
|
79
|
+
files.set('.nvmrc', '22.23.1\n');
|
|
80
|
+
// Preserve existing formatter configuration and Node version files.
|
|
81
|
+
if (
|
|
82
|
+
[
|
|
83
|
+
'prettier.config.mjs',
|
|
84
|
+
'prettier.config.js',
|
|
85
|
+
'prettier.config.cjs',
|
|
86
|
+
'.prettierrc',
|
|
87
|
+
'.prettierrc.json',
|
|
88
|
+
'.prettierrc.yml',
|
|
89
|
+
'.prettierrc.yaml',
|
|
90
|
+
'.prettierrc.js',
|
|
91
|
+
'.prettierrc.cjs',
|
|
92
|
+
'.prettierrc.toml',
|
|
93
|
+
].some((name) => existsSync(join(root, name))) ||
|
|
94
|
+
pkg.prettier
|
|
95
|
+
)
|
|
96
|
+
files.delete('prettier.config.mjs');
|
|
97
|
+
if (files.has('prettier.config.mjs'))
|
|
98
|
+
files.set(
|
|
99
|
+
'.github/workflows/ci.yml',
|
|
100
|
+
files
|
|
101
|
+
.get('.github/workflows/ci.yml')
|
|
102
|
+
.replace(' with:\n', ' with:\n lightweight-docs: true\n'),
|
|
103
|
+
);
|
|
104
|
+
if (existsSync(join(root, '.nvmrc'))) files.delete('.nvmrc');
|
|
105
|
+
for (const path of files.keys())
|
|
106
|
+
if (existsSync(join(root, path))) throw new Error(`Refusing to overwrite ${path}`);
|
|
107
|
+
for (const name of ['.gitignore', '.prettierignore']) {
|
|
108
|
+
const path = join(root, name);
|
|
109
|
+
let text = existsSync(path) ? readFileSync(path, 'utf8') : '';
|
|
110
|
+
for (const entry of [
|
|
111
|
+
'node_modules/',
|
|
112
|
+
'debug.log',
|
|
113
|
+
'.tooling/',
|
|
114
|
+
'dist/',
|
|
115
|
+
'coverage/',
|
|
116
|
+
'playwright-report/',
|
|
117
|
+
'test-results/',
|
|
118
|
+
'*.tsbuildinfo',
|
|
119
|
+
]) {
|
|
120
|
+
if (!text.split(/\r?\n/).includes(entry))
|
|
121
|
+
text += `${text && !text.endsWith('\n') ? '\n' : ''}${entry}\n`;
|
|
122
|
+
}
|
|
123
|
+
files.set(name, text);
|
|
124
|
+
}
|
|
125
|
+
pkg.scripts = { ...pkg.scripts, ...aliases };
|
|
126
|
+
pkg.devDependencies = { ...pkg.devDependencies, [manifest.name]: manifest.version };
|
|
127
|
+
files.set('package.json', json(pkg));
|
|
128
|
+
for (const [path, text] of files) {
|
|
129
|
+
const target = join(root, path);
|
|
130
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
131
|
+
writeFileSync(target, text);
|
|
132
|
+
}
|
|
133
|
+
chmodSync(join(root, '.githooks/pre-push'), 0o755);
|
|
134
|
+
return [...files.keys()];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function diagnose(root, configPath) {
|
|
138
|
+
const findings = [];
|
|
139
|
+
const add = (status, message) => findings.push({ status, message });
|
|
140
|
+
let config;
|
|
141
|
+
try {
|
|
142
|
+
config = loadConfig(root, configPath).config;
|
|
143
|
+
add('passed', 'Configuration is valid');
|
|
144
|
+
} catch (error) {
|
|
145
|
+
add('failed', error.message);
|
|
146
|
+
return findings;
|
|
147
|
+
}
|
|
148
|
+
let selection;
|
|
149
|
+
try {
|
|
150
|
+
selection = plan(config, { profile: 'ci' });
|
|
151
|
+
add('passed', 'Check dependencies form a valid graph');
|
|
152
|
+
} catch (error) {
|
|
153
|
+
add('failed', error.message);
|
|
154
|
+
return findings;
|
|
155
|
+
}
|
|
156
|
+
if (!existsSync(join(root, 'package-lock.json')))
|
|
157
|
+
add('failed', 'Run npm install and commit package-lock.json');
|
|
158
|
+
if (!existsSync(join(root, '.nvmrc'))) add('failed', 'Add .nvmrc for the shared workflow');
|
|
159
|
+
try {
|
|
160
|
+
git(root, 'rev-parse', '--verify', 'HEAD');
|
|
161
|
+
if (git(root, 'config', '--get', 'core.hooksPath') !== '.githooks')
|
|
162
|
+
add('failed', 'Enable the hook: git config core.hooksPath .githooks');
|
|
163
|
+
} catch {
|
|
164
|
+
add('failed', 'Initialize Git, commit the project and enable .githooks');
|
|
165
|
+
}
|
|
166
|
+
for (const check of selection.checks) {
|
|
167
|
+
const cwd = inside(root, check.cwd ?? '.');
|
|
168
|
+
if (!existsSync(cwd)) {
|
|
169
|
+
add('failed', `${check.id}: missing directory ${check.cwd}`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const commands = [check.command, check.devCommand, check.devAllCommand].filter(Array.isArray);
|
|
173
|
+
const tools = new Set([...commands.map((command) => command[0]), ...(check.tools ?? [])]);
|
|
174
|
+
for (const tool of tools)
|
|
175
|
+
if (!executable(cwd, tool))
|
|
176
|
+
add('failed', `${check.id}: missing ${tool} in ${check.cwd ?? '.'}`);
|
|
177
|
+
for (const command of commands) {
|
|
178
|
+
if (
|
|
179
|
+
command[0] === 'node' &&
|
|
180
|
+
command[1]?.endsWith('.mjs') &&
|
|
181
|
+
!existsSync(join(cwd, command[1])) &&
|
|
182
|
+
!existsSync(command[1])
|
|
183
|
+
)
|
|
184
|
+
add('failed', `${check.id}: missing script ${command[1]}`);
|
|
185
|
+
if (command[0] === 'npm' && command[1] === 'run') {
|
|
186
|
+
const pkgPath = join(cwd, 'package.json');
|
|
187
|
+
if (!existsSync(pkgPath) || !readJSON(pkgPath).scripts?.[command[2]])
|
|
188
|
+
add('failed', `${check.id}: missing npm script ${command[2]}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (check.platforms && !check.platforms.includes(process.platform))
|
|
192
|
+
add('notice', `${check.id}: use ${check.platforms.join('/')} for canonical validation`);
|
|
193
|
+
if ((check.kind ?? check.id) === 'styles' && !packageManifest(root, 'postcss-scss'))
|
|
194
|
+
add('failed', 'styles: install postcss-scss and its postcss peer at the consumer root');
|
|
195
|
+
if (
|
|
196
|
+
['architecture', 'dependency-consistency'].includes(check.kind ?? check.id) &&
|
|
197
|
+
!packageManifest(cwd, 'typescript')
|
|
198
|
+
)
|
|
199
|
+
add('failed', `${check.id}: install TypeScript for import analysis`);
|
|
200
|
+
if ((check.kind ?? check.id) === 'a11y') {
|
|
201
|
+
if (!config.a11y?.routes?.length)
|
|
202
|
+
add('failed', `${check.id}: configure a11y.baseURL and routes`);
|
|
203
|
+
for (const name of ['@playwright/test', '@axe-core/playwright'])
|
|
204
|
+
if (!packageManifest(cwd, name)) add('failed', `${check.id}: install ${name}`);
|
|
205
|
+
}
|
|
206
|
+
if (
|
|
207
|
+
(check.kind ?? check.id) === 'unit' &&
|
|
208
|
+
commands.some((command) => command.includes('--coverage')) &&
|
|
209
|
+
!packageManifest(cwd, '@vitest/coverage-v8')
|
|
210
|
+
)
|
|
211
|
+
add('failed', 'unit: install @vitest/coverage-v8 matching your Vitest version');
|
|
212
|
+
}
|
|
213
|
+
for (const name of ['ci.yml', 'dependabot-merge.yml']) {
|
|
214
|
+
const path = join(root, '.github/workflows', name);
|
|
215
|
+
if (!existsSync(path)) add('failed', `Missing .github/workflows/${name}`);
|
|
216
|
+
else if (readFileSync(path, 'utf8').includes('REPLACE_WITH_TOOLING_COMMIT_SHA'))
|
|
217
|
+
add('failed', `Pin .github/workflows/${name} to the tooling commit SHA`);
|
|
218
|
+
}
|
|
219
|
+
return findings;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export async function setupCommand(command, root, options) {
|
|
223
|
+
if (command === 'init') {
|
|
224
|
+
const paths = initialize(root, {
|
|
225
|
+
preset: options.preset,
|
|
226
|
+
app: options.app,
|
|
227
|
+
toolingSha: options['tooling-sha'],
|
|
228
|
+
});
|
|
229
|
+
console.log(
|
|
230
|
+
`Created/adapted: ${paths.join(', ')}\nRun npm install, install the peer tools for your enabled checks, then tooling doctor.\nEnable the hook: git config core.hooksPath .githooks\nPin the workflow SHA if you did not pass --tooling-sha.`,
|
|
231
|
+
);
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
const findings = diagnose(root, options.config);
|
|
235
|
+
for (const finding of findings) console.log(`${finding.status}: ${finding.message}`);
|
|
236
|
+
return findings.some((finding) => finding.status === 'failed') ? 1 : 0;
|
|
237
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const text = (value) =>
|
|
6
|
+
String(value ?? '')
|
|
7
|
+
.replace(/[\r\n]+/g, ' ')
|
|
8
|
+
.replaceAll('&', '&')
|
|
9
|
+
.replaceAll('<', '<')
|
|
10
|
+
.replaceAll('>', '>')
|
|
11
|
+
.replaceAll('|', '|')
|
|
12
|
+
.replaceAll('`', '`')
|
|
13
|
+
.replace(/([\[\]()*_!\\])/g, '\\$1')
|
|
14
|
+
.slice(0, 600);
|
|
15
|
+
const seconds = (value) => `${((value ?? 0) / 1000).toFixed(2)}s`;
|
|
16
|
+
|
|
17
|
+
export function markdownSummary(report, { artifactURL } = {}) {
|
|
18
|
+
const lines = [
|
|
19
|
+
`## Validation ${report.complete ? 'passed' : 'incomplete or failed'}`,
|
|
20
|
+
'',
|
|
21
|
+
`Profile: **${text(report.profile)}** · Scope: ${report.groups.map(text).join(', ')} · Duration: ${seconds(report.wallMilliseconds)}`,
|
|
22
|
+
`Selected checks: **${report.results.length}** · Cache hits: **${report.results.filter((check) => check.cached).length}**`,
|
|
23
|
+
'',
|
|
24
|
+
];
|
|
25
|
+
if (report.affectedWorkspaces?.length)
|
|
26
|
+
lines.push(`Affected workspaces: ${report.affectedWorkspaces.map(text).join(', ')}`, '');
|
|
27
|
+
lines.push('| Check | Result | Reused | Time | Details |', '| --- | --- | --- | --- | --- |');
|
|
28
|
+
for (const check of report.results)
|
|
29
|
+
lines.push(
|
|
30
|
+
`| ${text(check.id)} | ${text(check.status)} | ${check.cached ? 'yes' : 'no'} | ${seconds(check.milliseconds)} | ${text(check.reason)} |`,
|
|
31
|
+
);
|
|
32
|
+
const metrics = report.metrics ?? {};
|
|
33
|
+
if (metrics.bundle)
|
|
34
|
+
lines.push(
|
|
35
|
+
'',
|
|
36
|
+
`Initial JavaScript: **${Number(metrics.bundle.initialKB).toFixed(1)} KB gzip**${report.performance?.bundleDeltaKB == null ? '' : ` (${report.performance.bundleDeltaKB >= 0 ? '+' : ''}${report.performance.bundleDeltaKB.toFixed(1)} KB against the previous comparable run)`}.`,
|
|
37
|
+
);
|
|
38
|
+
if (metrics.coverage)
|
|
39
|
+
lines.push(
|
|
40
|
+
'',
|
|
41
|
+
`Coverage: ${Object.entries(metrics.coverage)
|
|
42
|
+
.map(([key, value]) => `${text(key)} **${value.toFixed(1)}%**`)
|
|
43
|
+
.join(' · ')}.`,
|
|
44
|
+
);
|
|
45
|
+
if (metrics.browser)
|
|
46
|
+
lines.push(
|
|
47
|
+
'',
|
|
48
|
+
`Browser tests: ${metrics.browser.passed} passed · ${metrics.browser.failed} failed · ${metrics.browser.flaky} flaky · ${metrics.browser.skipped} skipped.`,
|
|
49
|
+
);
|
|
50
|
+
if (metrics.a11y)
|
|
51
|
+
lines.push(
|
|
52
|
+
'',
|
|
53
|
+
`Accessibility: ${metrics.a11y.pages} rendered pages · ${metrics.a11y.violations} blocking violations · ${metrics.a11y.errors} scan errors.`,
|
|
54
|
+
);
|
|
55
|
+
if (metrics.architecture)
|
|
56
|
+
lines.push(
|
|
57
|
+
'',
|
|
58
|
+
`Architecture: ${metrics.architecture.files} source files · ${metrics.architecture.issues} violations.`,
|
|
59
|
+
);
|
|
60
|
+
if (metrics.dependencies)
|
|
61
|
+
lines.push(
|
|
62
|
+
'',
|
|
63
|
+
`Dependencies: ${metrics.dependencies.packages} manifests · ${metrics.dependencies.issues} errors · ${metrics.dependencies.duplicates} duplicate-version notices.`,
|
|
64
|
+
);
|
|
65
|
+
if (report.performance?.previousMs !== null && report.performance?.previousMs !== undefined)
|
|
66
|
+
lines.push(
|
|
67
|
+
'',
|
|
68
|
+
`Previous comparable median: ${seconds(report.performance.previousMs)}. Current change: ${report.performance.deltaMs >= 0 ? '+' : ''}${seconds(report.performance.deltaMs)}.`,
|
|
69
|
+
);
|
|
70
|
+
for (const regression of report.performance?.regressions ?? [])
|
|
71
|
+
lines.push(
|
|
72
|
+
'',
|
|
73
|
+
`Slower check: **${text(regression.id)}**, ${seconds(regression.currentMs)} against ${seconds(regression.previousMs)} median.`,
|
|
74
|
+
);
|
|
75
|
+
if (metrics.slowTests?.length) {
|
|
76
|
+
lines.push('', '### Slowest reported tests', '', '| Test | Time |', '| --- | --- |');
|
|
77
|
+
for (const test of metrics.slowTests.slice(0, 10))
|
|
78
|
+
lines.push(`| ${text(test.name)} | ${seconds(test.milliseconds)} |`);
|
|
79
|
+
}
|
|
80
|
+
const visual = report.results.filter(
|
|
81
|
+
(check) =>
|
|
82
|
+
(check.kind ?? check.id) === 'visual' && !['excluded', 'unavailable'].includes(check.status),
|
|
83
|
+
);
|
|
84
|
+
if (visual.length)
|
|
85
|
+
lines.push(
|
|
86
|
+
'',
|
|
87
|
+
`Visual results: ${visual.map((check) => `${text(check.id)} (${text(check.status)})`).join(', ')}. Expected, actual and diff images are in the browser reports.`,
|
|
88
|
+
);
|
|
89
|
+
if (artifactURL) {
|
|
90
|
+
const url = new URL(artifactURL);
|
|
91
|
+
if (!['https:', 'http:'].includes(url.protocol))
|
|
92
|
+
throw new Error('Artifact URL must use HTTP or HTTPS');
|
|
93
|
+
lines.push('', `[Download validation reports and visual differences](<${url.href}>)`);
|
|
94
|
+
}
|
|
95
|
+
lines.push('', `Commit: ${text(report.commit)} · Tooling: ${text(report.version)}`, '');
|
|
96
|
+
return lines.join('\n');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
100
|
+
const directory = process.argv[2] ?? '.tooling/report';
|
|
101
|
+
const path = join(directory, 'summary.json');
|
|
102
|
+
const markdown = existsSync(path)
|
|
103
|
+
? markdownSummary(JSON.parse(readFileSync(path, 'utf8')), {
|
|
104
|
+
artifactURL: process.env.TOOLING_ARTIFACT_URL,
|
|
105
|
+
})
|
|
106
|
+
: process.env.TOOLING_EMPTY_PLAN === 'true'
|
|
107
|
+
? '## Validation passed\n\nNo checks apply to this change. Installation and validation were skipped.\n'
|
|
108
|
+
: '## Validation stopped before a report was produced\n\nSee the failed workflow step for the prerequisite or planning error.\n';
|
|
109
|
+
if (existsSync(directory)) writeFileSync(join(directory, 'summary.md'), markdown);
|
|
110
|
+
if (process.env.GITHUB_STEP_SUMMARY) appendFileSync(process.env.GITHUB_STEP_SUMMARY, markdown);
|
|
111
|
+
else console.log(markdown);
|
|
112
|
+
}
|
package/runner/watch.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { relative, resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
export function relevantChanges(root, files, inputs = []) {
|
|
6
|
+
const declared = new Set(
|
|
7
|
+
inputs.map((file) => relative(root, resolve(root, file)).replaceAll('\\', '/')),
|
|
8
|
+
);
|
|
9
|
+
const candidates = [...new Set(files.map((file) => file.replaceAll('\\', '/')))].filter(
|
|
10
|
+
(file) => {
|
|
11
|
+
if (declared.has(file)) return true;
|
|
12
|
+
if (file.startsWith('.git/')) return file === '.git/HEAD' || file.startsWith('.git/refs/');
|
|
13
|
+
return !file.split('/').some((part) => ['node_modules', '.tooling'].includes(part));
|
|
14
|
+
},
|
|
15
|
+
);
|
|
16
|
+
if (!candidates.length) return [];
|
|
17
|
+
let ignored = '';
|
|
18
|
+
try {
|
|
19
|
+
ignored = execFileSync('git', ['check-ignore', '-z', '--stdin'], {
|
|
20
|
+
cwd: root,
|
|
21
|
+
input: candidates.join('\0') + '\0',
|
|
22
|
+
encoding: 'utf8',
|
|
23
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
24
|
+
});
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error.status !== 1) throw error;
|
|
27
|
+
ignored = error.stdout ?? '';
|
|
28
|
+
}
|
|
29
|
+
const excluded = new Set(ignored.split('\0'));
|
|
30
|
+
return candidates.filter(
|
|
31
|
+
(file) => declared.has(file) || file.startsWith('.git/') || !excluded.has(file),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Only validate after filesystem events; snapshots remain authoritative inside each validation.
|
|
36
|
+
export function watchChanges(root, run, { inputs = () => [], signal, debounce = 350 } = {}) {
|
|
37
|
+
return new Promise((resolveDone, reject) => {
|
|
38
|
+
let timer,
|
|
39
|
+
active,
|
|
40
|
+
closed = false;
|
|
41
|
+
const pending = new Set();
|
|
42
|
+
const finish = (error) => {
|
|
43
|
+
if (closed) return;
|
|
44
|
+
closed = true;
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
watcher.close();
|
|
47
|
+
signal?.removeEventListener('abort', abort);
|
|
48
|
+
Promise.resolve(active).then(() => (error ? reject(error) : resolveDone()), reject);
|
|
49
|
+
};
|
|
50
|
+
const schedule = () => {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
if (!closed) timer = setTimeout(drain, debounce);
|
|
53
|
+
};
|
|
54
|
+
const drain = async () => {
|
|
55
|
+
if (closed || active) return;
|
|
56
|
+
try {
|
|
57
|
+
const files = [...pending];
|
|
58
|
+
pending.clear();
|
|
59
|
+
if (!files.includes('*') && !relevantChanges(root, files, inputs()).length) return;
|
|
60
|
+
active = Promise.resolve().then(run);
|
|
61
|
+
await active;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
finish(error);
|
|
64
|
+
} finally {
|
|
65
|
+
active = undefined;
|
|
66
|
+
if (pending.size) schedule();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const watcher = watch(root, { recursive: true }, (_event, filename) => {
|
|
70
|
+
pending.add(filename?.toString() ?? '*');
|
|
71
|
+
schedule();
|
|
72
|
+
});
|
|
73
|
+
watcher.on('error', finish);
|
|
74
|
+
const abort = () => finish();
|
|
75
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
76
|
+
if (signal?.aborted) finish();
|
|
77
|
+
else {
|
|
78
|
+
pending.add('*');
|
|
79
|
+
schedule();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
package/templates/ci.yml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
types: [opened, synchronize, reopened, ready_for_review, edited]
|
|
5
|
+
schedule:
|
|
6
|
+
- cron: '0 8 * * 1'
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
inputs:
|
|
9
|
+
pull-request-number:
|
|
10
|
+
description: Release PR to route after trusted generation
|
|
11
|
+
type: string
|
|
12
|
+
default: ''
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
pull-requests: read
|
|
16
|
+
actions: read
|
|
17
|
+
concurrency:
|
|
18
|
+
group: ci-${{ github.event.pull_request.number || inputs.pull-request-number || github.ref }}
|
|
19
|
+
cancel-in-progress: true
|
|
20
|
+
jobs:
|
|
21
|
+
CI:
|
|
22
|
+
uses: DuarteCaldeira/tooling/.github/workflows/ci.yml@REPLACE_WITH_TOOLING_COMMIT_SHA
|
|
23
|
+
with:
|
|
24
|
+
tooling-sha: REPLACE_WITH_TOOLING_COMMIT_SHA
|
|
25
|
+
pull-request-number: ${{ inputs.pull-request-number || '' }}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
name: Dependabot merge
|
|
2
|
+
on:
|
|
3
|
+
workflow_run:
|
|
4
|
+
workflows: [CI]
|
|
5
|
+
types: [completed]
|
|
6
|
+
permissions:
|
|
7
|
+
contents: write
|
|
8
|
+
pull-requests: write
|
|
9
|
+
actions: read
|
|
10
|
+
checks: read
|
|
11
|
+
jobs:
|
|
12
|
+
merge:
|
|
13
|
+
uses: DuarteCaldeira/tooling/.github/workflows/dependabot-merge.yml@REPLACE_WITH_TOOLING_COMMIT_SHA
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
multi-ecosystem-groups:
|
|
3
|
+
all-dependencies:
|
|
4
|
+
schedule:
|
|
5
|
+
interval: weekly
|
|
6
|
+
day: monday
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: npm
|
|
9
|
+
directory: /
|
|
10
|
+
patterns: ['*']
|
|
11
|
+
multi-ecosystem-group: all-dependencies
|
|
12
|
+
ignore:
|
|
13
|
+
- dependency-name: eslint
|
|
14
|
+
update-types: [version-update:semver-major]
|
|
15
|
+
- dependency-name: '@eslint/js'
|
|
16
|
+
update-types: [version-update:semver-major]
|
|
17
|
+
- dependency-name: typescript
|
|
18
|
+
update-types: [version-update:semver-major]
|
|
19
|
+
groups:
|
|
20
|
+
security:
|
|
21
|
+
applies-to: security-updates
|
|
22
|
+
patterns: ['*']
|
|
23
|
+
- package-ecosystem: github-actions
|
|
24
|
+
directory: /
|
|
25
|
+
patterns: ['*']
|
|
26
|
+
multi-ecosystem-group: all-dependencies
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -eu
|
|
3
|
+
validate=0
|
|
4
|
+
while read -r local_ref local_sha remote_ref remote_sha; do
|
|
5
|
+
case "$local_sha" in 0000000000000000000000000000000000000000) continue ;; esac
|
|
6
|
+
if [ "$(git rev-parse "$local_sha^{commit}")" != "$(git rev-parse HEAD)" ]; then
|
|
7
|
+
echo "Push refused: validate this ref from its own checkout first." >&2
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
validate=1
|
|
11
|
+
done
|
|
12
|
+
[ "$validate" -eq 0 ] && exit 0
|
|
13
|
+
exec npm run check:push
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
on:
|
|
3
|
+
workflow_dispatch:
|
|
4
|
+
inputs:
|
|
5
|
+
level:
|
|
6
|
+
type: choice
|
|
7
|
+
options: [patch, minor, major]
|
|
8
|
+
default: patch
|
|
9
|
+
permissions:
|
|
10
|
+
contents: write
|
|
11
|
+
pull-requests: write
|
|
12
|
+
actions: write
|
|
13
|
+
concurrency:
|
|
14
|
+
group: release
|
|
15
|
+
cancel-in-progress: false
|
|
16
|
+
jobs:
|
|
17
|
+
release:
|
|
18
|
+
uses: DuarteCaldeira/tooling/.github/workflows/release-validation.yml@REPLACE_WITH_TOOLING_COMMIT_SHA
|
|
19
|
+
with:
|
|
20
|
+
tooling-sha: REPLACE_WITH_TOOLING_COMMIT_SHA
|
|
21
|
+
level: ${{ inputs.level }}
|
|
22
|
+
secrets:
|
|
23
|
+
RELEASE_SIGNING_KEY: ${{ secrets.TOOLING_RELEASE_SIGNING_KEY }}
|