@dcaldeira/tooling 0.0.0-stage → 0.2.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 +33 -2
- 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/duplication.mjs +135 -0
- package/checks/lint-scss.mjs +363 -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 +977 -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 +103 -4
- 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 +251 -0
- package/runner/config.mjs +148 -0
- package/runner/docs-install.mjs +93 -0
- package/runner/execute.mjs +298 -0
- package/runner/generate.mjs +122 -0
- package/runner/git.mjs +122 -0
- package/runner/graph.mjs +250 -0
- package/runner/index.mjs +4 -0
- package/runner/insights.mjs +313 -0
- package/runner/provision.mjs +53 -0
- package/runner/repo-standard.mjs +104 -0
- package/runner/report.mjs +35 -0
- package/runner/serve-static.mjs +76 -0
- package/runner/setup.mjs +241 -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,27 @@
|
|
|
1
|
+
import eslint from '@eslint/js';
|
|
2
|
+
import tseslint from 'typescript-eslint';
|
|
3
|
+
import jsxA11y from 'eslint-plugin-jsx-a11y';
|
|
4
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
5
|
+
import globals from 'globals';
|
|
6
|
+
|
|
7
|
+
export default tseslint.config(
|
|
8
|
+
{
|
|
9
|
+
ignores: [
|
|
10
|
+
'**/.tooling/**',
|
|
11
|
+
'**/dist/**',
|
|
12
|
+
'**/node_modules/**',
|
|
13
|
+
'**/coverage/**',
|
|
14
|
+
'**/playwright-report/**',
|
|
15
|
+
'**/test-results/**',
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
eslint.configs.recommended,
|
|
19
|
+
...tseslint.configs.recommended,
|
|
20
|
+
{ files: ['**/*.mjs'], languageOptions: { globals: globals.node } },
|
|
21
|
+
{ files: ['**/*.{ts,tsx}'], languageOptions: { globals: globals.browser } },
|
|
22
|
+
{
|
|
23
|
+
files: ['**/*.tsx'],
|
|
24
|
+
plugins: { 'jsx-a11y': jsxA11y, 'react-hooks': reactHooks },
|
|
25
|
+
rules: { ...jsxA11y.configs.recommended.rules, ...reactHooks.configs.recommended.rules },
|
|
26
|
+
},
|
|
27
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
outputDir: process.env.TOOLING_TEST_OUTPUT_DIR ?? 'test-results',
|
|
3
|
+
forbidOnly: Boolean(process.env.CI),
|
|
4
|
+
retries: 1,
|
|
5
|
+
reporter: [
|
|
6
|
+
['list'],
|
|
7
|
+
['html', { open: 'never' }],
|
|
8
|
+
[
|
|
9
|
+
'json',
|
|
10
|
+
{ outputFile: `${process.env.TOOLING_TEST_OUTPUT_DIR ?? 'test-results'}/results.json` },
|
|
11
|
+
],
|
|
12
|
+
],
|
|
13
|
+
use: { trace: 'retain-on-failure', screenshot: 'only-on-failure', serviceWorkers: 'allow' },
|
|
14
|
+
expect: { toHaveScreenshot: { maxDiffPixelRatio: 0.01 } },
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { singleQuote: true, printWidth: 100 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"verbatimModuleSyntax": true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { configDefaults } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
test: {
|
|
5
|
+
exclude: [...configDefaults.exclude, '**/.tooling/**'],
|
|
6
|
+
reporters: ['default', 'json'],
|
|
7
|
+
outputFile: { json: `${process.env.TOOLING_UNIT_OUTPUT_DIR ?? 'test-results'}/vitest.json` },
|
|
8
|
+
coverage: {
|
|
9
|
+
provider: 'v8',
|
|
10
|
+
reporter: ['text-summary', 'html', 'lcov', 'json-summary'],
|
|
11
|
+
reportsDirectory: `${process.env.TOOLING_UNIT_OUTPUT_DIR ?? 'test-results'}/coverage`,
|
|
12
|
+
},
|
|
13
|
+
clearMocks: false,
|
|
14
|
+
restoreMocks: false,
|
|
15
|
+
},
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,105 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcaldeira/tooling",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared checks and change detection for local development and GitHub Actions",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/DuarteCaldeira/tooling.git",
|
|
10
|
+
"directory": "packages/tooling"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"tooling": "runner/cli.mjs"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./runner/index.mjs",
|
|
17
|
+
"./configs/*": "./configs/*",
|
|
18
|
+
"./checks/*": "./checks/*",
|
|
19
|
+
"./release": "./release/evidence.mjs",
|
|
20
|
+
"./schema": "./config.schema.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"configs",
|
|
24
|
+
"checks",
|
|
25
|
+
"runner",
|
|
26
|
+
"release",
|
|
27
|
+
"templates",
|
|
28
|
+
"config.schema.json"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.13.0"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"provenance": true
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"prettier": ">=3 <4",
|
|
39
|
+
"eslint": ">=9 <11",
|
|
40
|
+
"typescript-eslint": ">=8 <9",
|
|
41
|
+
"@eslint/js": ">=9 <11",
|
|
42
|
+
"eslint-plugin-jsx-a11y": ">=6 <7",
|
|
43
|
+
"eslint-plugin-react-hooks": ">=7 <8",
|
|
44
|
+
"globals": ">=16 <18",
|
|
45
|
+
"postcss-scss": ">=4 <5",
|
|
46
|
+
"vitest": ">=3 <6",
|
|
47
|
+
"@playwright/test": ">=1.50 <2",
|
|
48
|
+
"knip": ">=5 <7",
|
|
49
|
+
"postcss": ">=8 <9",
|
|
50
|
+
"typescript": ">=5 <7",
|
|
51
|
+
"@axe-core/playwright": ">=4 <5",
|
|
52
|
+
"sass": ">=1 <2"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"prettier": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"eslint": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"typescript-eslint": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"@eslint/js": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"eslint-plugin-jsx-a11y": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"eslint-plugin-react-hooks": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"globals": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"postcss-scss": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"vitest": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"@playwright/test": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"knip": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
88
|
+
"postcss": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
91
|
+
"typescript": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
94
|
+
"@axe-core/playwright": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"sass": {
|
|
98
|
+
"optional": true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"dependencies": {
|
|
102
|
+
"es-module-lexer": "2.3.2",
|
|
103
|
+
"semver": "7.8.6"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { sign, verify, createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
export const digest = (value) => createHash('sha256').update(value).digest('hex');
|
|
4
|
+
const sha = /^[a-f0-9]{40}$/;
|
|
5
|
+
|
|
6
|
+
export function createEvidence(
|
|
7
|
+
{ report, source, head, tree, repository, workflow, runId, configHash },
|
|
8
|
+
privateKey,
|
|
9
|
+
) {
|
|
10
|
+
if (
|
|
11
|
+
!report.complete ||
|
|
12
|
+
report.profile !== 'ci' ||
|
|
13
|
+
!report.groups.includes('all') ||
|
|
14
|
+
report.results.some((r) => r.status !== 'passed')
|
|
15
|
+
)
|
|
16
|
+
throw new Error('Full CI validation must pass before release preparation can be certified');
|
|
17
|
+
if (
|
|
18
|
+
report.commit !== head ||
|
|
19
|
+
report.tree !== tree ||
|
|
20
|
+
![source, head, tree].every((s) => sha.test(s))
|
|
21
|
+
)
|
|
22
|
+
throw new Error('Validation does not match the prepared release');
|
|
23
|
+
const payload = {
|
|
24
|
+
schemaVersion: 1,
|
|
25
|
+
repository,
|
|
26
|
+
workflow,
|
|
27
|
+
runId,
|
|
28
|
+
source,
|
|
29
|
+
head,
|
|
30
|
+
tree,
|
|
31
|
+
toolingVersion: report.version,
|
|
32
|
+
configHash,
|
|
33
|
+
validatedAt: report.finishedAt,
|
|
34
|
+
};
|
|
35
|
+
const data = Buffer.from(JSON.stringify(payload));
|
|
36
|
+
return {
|
|
37
|
+
payload: data.toString('base64'),
|
|
38
|
+
signature: sign(null, data, privateKey).toString('base64'),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function verifyEvidence(envelope, publicKey, expected) {
|
|
43
|
+
try {
|
|
44
|
+
const data = Buffer.from(envelope.payload, 'base64');
|
|
45
|
+
if (!verify(null, data, publicKey, Buffer.from(envelope.signature, 'base64'))) return false;
|
|
46
|
+
const payload = JSON.parse(data);
|
|
47
|
+
if (
|
|
48
|
+
payload.schemaVersion !== 1 ||
|
|
49
|
+
!['source', 'head', 'tree'].every((key) => sha.test(payload[key]))
|
|
50
|
+
)
|
|
51
|
+
return false;
|
|
52
|
+
if (
|
|
53
|
+
!['repository', 'workflow', 'source', 'head', 'tree', 'toolingVersion', 'configHash'].every(
|
|
54
|
+
(key) => typeof expected[key] === 'string' && payload[key] === expected[key],
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
return false;
|
|
58
|
+
return expected.generator === 'github-actions[bot]' && expected.generatorId === 41898282;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { verifyPullRequest } from './github.mjs';
|
|
4
|
+
import { gh, github } from './gh.mjs';
|
|
5
|
+
|
|
6
|
+
const [number] = process.argv.slice(2);
|
|
7
|
+
if (!/^\d+$/.test(number ?? '')) throw new Error('Usage: finalize.mjs <release-pr-number>');
|
|
8
|
+
const { nameWithOwner } = JSON.parse(gh('repo', 'view', '--json', 'nameWithOwner'));
|
|
9
|
+
const [owner, repo] = nameWithOwner.split('/');
|
|
10
|
+
const publicKey =
|
|
11
|
+
process.env.TOOLING_RELEASE_PUBLIC_KEY ||
|
|
12
|
+
gh(
|
|
13
|
+
'api',
|
|
14
|
+
`repos/${owner}/${repo}/actions/variables/TOOLING_RELEASE_PUBLIC_KEY`,
|
|
15
|
+
'--jq',
|
|
16
|
+
'.value',
|
|
17
|
+
);
|
|
18
|
+
const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
19
|
+
if (
|
|
20
|
+
!(await verifyPullRequest({
|
|
21
|
+
github,
|
|
22
|
+
owner,
|
|
23
|
+
repo,
|
|
24
|
+
number,
|
|
25
|
+
publicKey,
|
|
26
|
+
workflow: '.github/workflows/release.yml',
|
|
27
|
+
version,
|
|
28
|
+
}))
|
|
29
|
+
)
|
|
30
|
+
throw new Error('Release evidence is missing, stale or untrusted; regenerate the release');
|
|
31
|
+
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: number });
|
|
32
|
+
const { data: prepared } = await github.rest.git.getCommit({
|
|
33
|
+
owner,
|
|
34
|
+
repo,
|
|
35
|
+
commit_sha: pr.head.sha,
|
|
36
|
+
});
|
|
37
|
+
gh('pr', 'merge', number, '--squash', '--match-head-commit', pr.head.sha);
|
|
38
|
+
const merged = JSON.parse(gh('api', `repos/${owner}/${repo}/pulls/${number}`));
|
|
39
|
+
if (!merged.merged) throw new Error('PR was not merged; no tag or release created');
|
|
40
|
+
const { data: commit } = await github.rest.git.getCommit({
|
|
41
|
+
owner,
|
|
42
|
+
repo,
|
|
43
|
+
commit_sha: merged.merge_commit_sha,
|
|
44
|
+
});
|
|
45
|
+
if (commit.tree.sha !== prepared.tree.sha)
|
|
46
|
+
throw new Error('Merged tree differs from the validated tree; publishing refused');
|
|
47
|
+
const manifest = JSON.parse(
|
|
48
|
+
gh('api', `repos/${owner}/${repo}/contents/package.json?ref=${merged.merge_commit_sha}`),
|
|
49
|
+
);
|
|
50
|
+
const releaseVersion = JSON.parse(Buffer.from(manifest.content, 'base64')).version;
|
|
51
|
+
if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(releaseVersion))
|
|
52
|
+
throw new Error('Invalid release version');
|
|
53
|
+
const tag = `v${releaseVersion}`;
|
|
54
|
+
gh(
|
|
55
|
+
'api',
|
|
56
|
+
'--method',
|
|
57
|
+
'POST',
|
|
58
|
+
`repos/${owner}/${repo}/git/refs`,
|
|
59
|
+
'-f',
|
|
60
|
+
`ref=refs/tags/${tag}`,
|
|
61
|
+
'-f',
|
|
62
|
+
`sha=${merged.merge_commit_sha}`,
|
|
63
|
+
);
|
|
64
|
+
gh('release', 'create', tag, '--verify-tag', '--generate-notes', '--title', tag);
|
|
65
|
+
console.log(`Published ${tag} from validated tree ${commit.tree.sha}`);
|
package/release/gh.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
|
|
3
|
+
export const gh = (...args) =>
|
|
4
|
+
execFileSync('gh', args, { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 }).trim();
|
|
5
|
+
const get = (path) => Promise.resolve({ data: JSON.parse(gh('api', path)) });
|
|
6
|
+
export const github = {
|
|
7
|
+
rest: {
|
|
8
|
+
pulls: {
|
|
9
|
+
get: ({ owner, repo, pull_number }) => get(`repos/${owner}/${repo}/pulls/${pull_number}`),
|
|
10
|
+
},
|
|
11
|
+
git: {
|
|
12
|
+
getCommit: ({ owner, repo, commit_sha }) =>
|
|
13
|
+
get(`repos/${owner}/${repo}/git/commits/${commit_sha}`),
|
|
14
|
+
getRef: ({ owner, repo, ref }) => get(`repos/${owner}/${repo}/git/ref/${ref}`),
|
|
15
|
+
},
|
|
16
|
+
repos: {
|
|
17
|
+
getContent: ({ owner, repo, path, ref }) =>
|
|
18
|
+
get(`repos/${owner}/${repo}/contents/${path}?ref=${encodeURIComponent(ref)}`),
|
|
19
|
+
},
|
|
20
|
+
actions: {
|
|
21
|
+
getWorkflowRun: ({ owner, repo, run_id }) =>
|
|
22
|
+
get(`repos/${owner}/${repo}/actions/runs/${run_id}`),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { verifyEvidence, digest } from './evidence.mjs';
|
|
2
|
+
|
|
3
|
+
export async function verifyPullRequest({
|
|
4
|
+
github,
|
|
5
|
+
owner,
|
|
6
|
+
repo,
|
|
7
|
+
number,
|
|
8
|
+
publicKey,
|
|
9
|
+
workflow,
|
|
10
|
+
version,
|
|
11
|
+
configPath = 'tooling.config.json',
|
|
12
|
+
}) {
|
|
13
|
+
if (!publicKey) return false;
|
|
14
|
+
try {
|
|
15
|
+
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: Number(number) });
|
|
16
|
+
if (pr.state !== 'open' || pr.head.repo.full_name !== `${owner}/${repo}`) return false;
|
|
17
|
+
const marker = pr.body?.match(/<!-- tooling-evidence:([A-Za-z0-9+/=]+) -->/);
|
|
18
|
+
if (!marker) return false;
|
|
19
|
+
const envelope = JSON.parse(Buffer.from(marker[1], 'base64'));
|
|
20
|
+
const { data: head } = await github.rest.git.getCommit({
|
|
21
|
+
owner,
|
|
22
|
+
repo,
|
|
23
|
+
commit_sha: pr.head.sha,
|
|
24
|
+
});
|
|
25
|
+
const { data: base } = await github.rest.git.getRef({
|
|
26
|
+
owner,
|
|
27
|
+
repo,
|
|
28
|
+
ref: `heads/${pr.base.ref}`,
|
|
29
|
+
});
|
|
30
|
+
const { data: config } = await github.rest.repos.getContent({
|
|
31
|
+
owner,
|
|
32
|
+
repo,
|
|
33
|
+
path: configPath,
|
|
34
|
+
ref: pr.head.sha,
|
|
35
|
+
});
|
|
36
|
+
const expected = {
|
|
37
|
+
repository: `${owner}/${repo}`,
|
|
38
|
+
workflow,
|
|
39
|
+
source: base.object.sha,
|
|
40
|
+
head: pr.head.sha,
|
|
41
|
+
tree: head.tree.sha,
|
|
42
|
+
toolingVersion: version,
|
|
43
|
+
configHash: digest(Buffer.from(config.content, 'base64')),
|
|
44
|
+
generator: pr.user.login,
|
|
45
|
+
generatorId: pr.user.id,
|
|
46
|
+
};
|
|
47
|
+
if (!verifyEvidence(envelope, publicKey, expected)) return false;
|
|
48
|
+
const payload = JSON.parse(Buffer.from(envelope.payload, 'base64'));
|
|
49
|
+
const { data: run } = await github.rest.actions.getWorkflowRun({
|
|
50
|
+
owner,
|
|
51
|
+
repo,
|
|
52
|
+
run_id: Number(payload.runId),
|
|
53
|
+
});
|
|
54
|
+
return (
|
|
55
|
+
(!run.conclusion || run.conclusion === 'success') &&
|
|
56
|
+
run.path === workflow &&
|
|
57
|
+
run.event === 'workflow_dispatch' &&
|
|
58
|
+
run.head_sha === expected.source &&
|
|
59
|
+
run.repository.full_name === expected.repository
|
|
60
|
+
);
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdirSync, writeFileSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { loadConfig } from '../runner/config.mjs';
|
|
4
|
+
import { git, clean } from '../runner/git.mjs';
|
|
5
|
+
import { invoke } from '../runner/execute.mjs';
|
|
6
|
+
|
|
7
|
+
const root = process.cwd();
|
|
8
|
+
const { config } = loadConfig(root);
|
|
9
|
+
if (!clean(root)) throw new Error('Commit all files before preparing a release');
|
|
10
|
+
if (!config.release?.prepare) throw new Error('Configure release.prepare');
|
|
11
|
+
const source = git(root, 'rev-parse', 'HEAD');
|
|
12
|
+
const level = process.argv[2] ?? process.env.RELEASE_LEVEL;
|
|
13
|
+
if (process.argv.length > 3 || !['major', 'minor', 'patch'].includes(level))
|
|
14
|
+
throw new Error('Usage: prepare.mjs <patch|minor|major> or set RELEASE_LEVEL');
|
|
15
|
+
mkdirSync('.tooling', { recursive: true });
|
|
16
|
+
const result = await invoke(config.release.prepare, root, { extra: [level] });
|
|
17
|
+
if (result.status !== 'passed') throw new Error('Release preparation failed');
|
|
18
|
+
git(root, 'add', '--', ...config.release.files);
|
|
19
|
+
git(root, 'commit', '-m', `Release ${JSON.parse(readFileSync('package.json', 'utf8')).version}`);
|
|
20
|
+
if (!clean(root)) throw new Error('Release preparation modified files outside release.files');
|
|
21
|
+
const candidate = {
|
|
22
|
+
source,
|
|
23
|
+
head: git(root, 'rev-parse', 'HEAD'),
|
|
24
|
+
tree: git(root, 'rev-parse', 'HEAD^{tree}'),
|
|
25
|
+
};
|
|
26
|
+
writeFileSync('.tooling/candidate.json', JSON.stringify(candidate));
|
|
27
|
+
if (process.env.GITHUB_OUTPUT)
|
|
28
|
+
writeFileSync(process.env.GITHUB_OUTPUT, `head=${candidate.head}\nsource=${source}\n`, {
|
|
29
|
+
flag: 'a',
|
|
30
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { appendFileSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { executable, invoke, packageManifest } from './execute.mjs';
|
|
5
|
+
import { inside } from './config.mjs';
|
|
6
|
+
|
|
7
|
+
export function browserChecks(selection) {
|
|
8
|
+
return selection.checks.filter(
|
|
9
|
+
(check) =>
|
|
10
|
+
!check.excluded && ['e2e', 'visual', 'a11y', 'lighthouse'].includes(check.kind ?? check.id),
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function provisionBrowsers(
|
|
15
|
+
root,
|
|
16
|
+
selection,
|
|
17
|
+
{
|
|
18
|
+
run = invoke,
|
|
19
|
+
find = executable,
|
|
20
|
+
manifest = packageManifest,
|
|
21
|
+
load = (path) => createRequire(path)('@playwright/test'),
|
|
22
|
+
env = process.env,
|
|
23
|
+
} = {},
|
|
24
|
+
) {
|
|
25
|
+
const checks = browserChecks(selection);
|
|
26
|
+
if (!checks.length) return {};
|
|
27
|
+
const installed = new Set();
|
|
28
|
+
let playwrightChrome;
|
|
29
|
+
for (const check of checks.filter((check) =>
|
|
30
|
+
['e2e', 'visual', 'a11y'].includes(check.kind ?? check.id),
|
|
31
|
+
)) {
|
|
32
|
+
const cwd = inside(root, check.cwd ?? '.');
|
|
33
|
+
const packagePath = manifest(cwd, '@playwright/test');
|
|
34
|
+
if (!packagePath)
|
|
35
|
+
throw new Error(`${check.id}: install a locked @playwright/test in ${check.cwd ?? '.'}`);
|
|
36
|
+
if (!installed.has(packagePath)) {
|
|
37
|
+
const result = await run(['playwright', 'install', '--with-deps', 'chromium'], root, { cwd });
|
|
38
|
+
if (result.status !== 'passed') throw new Error(`${check.id}: Chromium installation failed`);
|
|
39
|
+
installed.add(packagePath);
|
|
40
|
+
}
|
|
41
|
+
playwrightChrome = load(packagePath).chromium.executablePath();
|
|
42
|
+
}
|
|
43
|
+
if (!checks.some((check) => (check.kind ?? check.id) === 'lighthouse')) return {};
|
|
44
|
+
// Lighthouse-only projects can use the runner's native Chrome without installing Playwright.
|
|
45
|
+
const native =
|
|
46
|
+
env.CHROME_PATH ||
|
|
47
|
+
['google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser']
|
|
48
|
+
.map((name) => find(root, name)?.[0])
|
|
49
|
+
.find(Boolean);
|
|
50
|
+
if (native) return { CHROME_PATH: native };
|
|
51
|
+
if (playwrightChrome) return { CHROME_PATH: playwrightChrome };
|
|
52
|
+
const cwd = inside(
|
|
53
|
+
root,
|
|
54
|
+
checks.find((check) => (check.kind ?? check.id) === 'lighthouse').cwd ?? '.',
|
|
55
|
+
);
|
|
56
|
+
const packagePath = manifest(cwd, '@playwright/test');
|
|
57
|
+
if (!packagePath)
|
|
58
|
+
throw new Error(
|
|
59
|
+
'Lighthouse requires CHROME_PATH, a native Chrome installation, or locked @playwright/test for Chromium provisioning',
|
|
60
|
+
);
|
|
61
|
+
const result = await run(['playwright', 'install', '--with-deps', 'chromium'], root, { cwd });
|
|
62
|
+
if (result.status !== 'passed') throw new Error('Lighthouse Chromium installation failed');
|
|
63
|
+
return { CHROME_PATH: load(packagePath).chromium.executablePath() };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
67
|
+
const selection = JSON.parse(readFileSync(process.argv[2], 'utf8'));
|
|
68
|
+
const variables = await provisionBrowsers(process.cwd(), selection);
|
|
69
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
70
|
+
if (/[\r\n]/.test(value)) throw new Error(`Invalid ${key}`);
|
|
71
|
+
if (process.env.GITHUB_ENV) appendFileSync(process.env.GITHUB_ENV, `${key}=${value}\n`);
|
|
72
|
+
}
|
|
73
|
+
}
|
package/runner/cache.mjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync, renameSync } from 'node:fs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { builtins, classify, matches, workspaceFiles } from './graph.mjs';
|
|
5
|
+
|
|
6
|
+
const diagnostics = new Set(['format', 'lint', 'styles', 'translations', 'deadcode', 'workflows']);
|
|
7
|
+
const fresh = new Set([
|
|
8
|
+
'security',
|
|
9
|
+
'build',
|
|
10
|
+
'size',
|
|
11
|
+
'unit',
|
|
12
|
+
'e2e',
|
|
13
|
+
'visual',
|
|
14
|
+
'lighthouse',
|
|
15
|
+
'database',
|
|
16
|
+
'a11y',
|
|
17
|
+
'dependency-consistency',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export function checkCache(root, config, selection, state, { disabled = false } = {}) {
|
|
21
|
+
const pending = new Map();
|
|
22
|
+
const directory = join(root, '.tooling/state/checks');
|
|
23
|
+
function eligible(check) {
|
|
24
|
+
const kind = check.kind ?? check.id;
|
|
25
|
+
if (
|
|
26
|
+
disabled ||
|
|
27
|
+
config.execution?.checkCache === false ||
|
|
28
|
+
fresh.has(kind) ||
|
|
29
|
+
check.dependsOn?.length ||
|
|
30
|
+
check.cache === false
|
|
31
|
+
)
|
|
32
|
+
return false;
|
|
33
|
+
const overrides = config.checks?.[check.id];
|
|
34
|
+
if (
|
|
35
|
+
!check.cache &&
|
|
36
|
+
(!diagnostics.has(kind) ||
|
|
37
|
+
['command', 'devCommand', 'devAllCommand'].some((name) => overrides?.[name] !== undefined))
|
|
38
|
+
)
|
|
39
|
+
return false;
|
|
40
|
+
return Boolean(check.cache || builtins[kind]);
|
|
41
|
+
}
|
|
42
|
+
function key(check, command, files) {
|
|
43
|
+
if (!eligible(check)) return null;
|
|
44
|
+
const all = Object.keys(state.files);
|
|
45
|
+
const scoped = new Set(workspaceFiles(config, check.workspaces, all));
|
|
46
|
+
const patterns = typeof check.cache === 'object' ? check.cache.inputs : null;
|
|
47
|
+
const input = all
|
|
48
|
+
.filter((file) => {
|
|
49
|
+
// Config, lockfiles and unknown paths always invalidate, even for narrowed input sets.
|
|
50
|
+
const global = classify([file], config).some((group) =>
|
|
51
|
+
['tooling', 'dependencies', 'unknown'].includes(group),
|
|
52
|
+
);
|
|
53
|
+
return (
|
|
54
|
+
global ||
|
|
55
|
+
(patterns ? patterns.some((pattern) => matches(file, pattern)) : scoped.has(file))
|
|
56
|
+
);
|
|
57
|
+
})
|
|
58
|
+
.sort()
|
|
59
|
+
.map((file) => [file, state.files[file]]);
|
|
60
|
+
const tools = new Set([
|
|
61
|
+
...(check.tools ?? []),
|
|
62
|
+
...(Array.isArray(command) ? [command[0]] : []),
|
|
63
|
+
]);
|
|
64
|
+
const identities = state.tools.filter(
|
|
65
|
+
(tool) => tools.has(tool.name) && tool.cwd === resolve(root, check.cwd ?? '.'),
|
|
66
|
+
);
|
|
67
|
+
const { files: _selection, ...definition } = check;
|
|
68
|
+
return createHash('sha256')
|
|
69
|
+
.update(
|
|
70
|
+
JSON.stringify({
|
|
71
|
+
schemaVersion: 1,
|
|
72
|
+
context: state.context,
|
|
73
|
+
check: definition,
|
|
74
|
+
command,
|
|
75
|
+
profile: selection.profile,
|
|
76
|
+
files,
|
|
77
|
+
input,
|
|
78
|
+
tools: identities,
|
|
79
|
+
}),
|
|
80
|
+
)
|
|
81
|
+
.digest('hex');
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
reusablePass: selection.checks.every(eligible),
|
|
85
|
+
get(check, command, files) {
|
|
86
|
+
const fingerprint = key(check, command, files);
|
|
87
|
+
if (!fingerprint) return null;
|
|
88
|
+
pending.set(check.id, fingerprint);
|
|
89
|
+
try {
|
|
90
|
+
const record = JSON.parse(readFileSync(join(directory, `${fingerprint}.json`), 'utf8'));
|
|
91
|
+
if (
|
|
92
|
+
record.schemaVersion === 1 &&
|
|
93
|
+
record.fingerprint === fingerprint &&
|
|
94
|
+
record.id === check.id &&
|
|
95
|
+
record.status === 'passed'
|
|
96
|
+
)
|
|
97
|
+
return {
|
|
98
|
+
status: 'passed',
|
|
99
|
+
cached: true,
|
|
100
|
+
milliseconds: 0,
|
|
101
|
+
reason: 'Matching deterministic check inputs',
|
|
102
|
+
};
|
|
103
|
+
} catch {}
|
|
104
|
+
return null;
|
|
105
|
+
},
|
|
106
|
+
commit(results) {
|
|
107
|
+
for (const result of results) {
|
|
108
|
+
const fingerprint = pending.get(result.id);
|
|
109
|
+
if (!fingerprint || result.status !== 'passed' || result.cached) continue;
|
|
110
|
+
mkdirSync(directory, { recursive: true });
|
|
111
|
+
const target = join(directory, `${fingerprint}.json`);
|
|
112
|
+
const temporary = `${target}.${randomUUID()}.tmp`;
|
|
113
|
+
writeFileSync(
|
|
114
|
+
temporary,
|
|
115
|
+
JSON.stringify({ schemaVersion: 1, id: result.id, fingerprint, status: 'passed' }),
|
|
116
|
+
);
|
|
117
|
+
renameSync(temporary, target);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|