@dcaldeira/tooling 0.1.0 → 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/README.md +34 -34
- package/checks/a11y.mjs +206 -206
- package/checks/architecture.mjs +137 -137
- package/checks/audit.mjs +121 -121
- package/checks/bundle.mjs +126 -126
- package/checks/dependencies.mjs +277 -277
- package/checks/duplication.mjs +135 -0
- package/checks/lint-scss.mjs +363 -349
- package/checks/package.mjs +30 -30
- package/checks/playwright-summary.mjs +53 -53
- package/checks/sass.mjs +67 -67
- package/checks/scan-secrets.mjs +58 -58
- package/checks/shared.mjs +86 -86
- package/checks/translations.mjs +55 -55
- package/checks/visual-compare.mjs +148 -148
- package/checks/visual-report-html.mjs +470 -470
- package/checks/visual-report.mjs +13 -13
- package/config.schema.json +977 -927
- package/configs/eslint.mjs +27 -27
- package/configs/knip.json +11 -11
- package/configs/playwright.mjs +15 -15
- package/configs/vitest.mjs +16 -16
- package/package.json +105 -105
- package/release/finalize.mjs +65 -65
- package/release/github.mjs +64 -64
- package/release/prepare.mjs +30 -30
- package/runner/browsers.mjs +73 -73
- package/runner/cache.mjs +121 -121
- package/runner/ci-plan.mjs +54 -54
- package/runner/cli.mjs +250 -248
- package/runner/config.mjs +148 -148
- package/runner/docs-install.mjs +93 -93
- package/runner/execute.mjs +298 -286
- package/runner/generate.mjs +122 -122
- package/runner/git.mjs +122 -122
- package/runner/graph.mjs +250 -243
- package/runner/insights.mjs +313 -313
- package/runner/provision.mjs +53 -53
- package/runner/repo-standard.mjs +104 -0
- package/runner/report.mjs +35 -35
- package/runner/serve-static.mjs +76 -76
- package/runner/setup.mjs +241 -237
- package/runner/summary.mjs +112 -112
- package/runner/watch.mjs +82 -82
- package/templates/ci.yml +25 -25
- package/templates/dependabot-merge.yml +13 -13
- package/templates/dependabot.yml +26 -26
- package/templates/pre-push +13 -13
- package/templates/release.yml +23 -23
package/configs/eslint.mjs
CHANGED
|
@@ -1,27 +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
|
-
);
|
|
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
|
+
);
|
package/configs/knip.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://unpkg.com/knip@6/schema.json",
|
|
3
|
-
"ignore": [
|
|
4
|
-
"**/coverage/**",
|
|
5
|
-
"**/dist/**",
|
|
6
|
-
"**/playwright-report/**",
|
|
7
|
-
"**/test-results/**",
|
|
8
|
-
"**/.tooling/**"
|
|
9
|
-
],
|
|
10
|
-
"entry": ["src/main.{ts,tsx}", "scripts/*.mjs"]
|
|
11
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/knip@6/schema.json",
|
|
3
|
+
"ignore": [
|
|
4
|
+
"**/coverage/**",
|
|
5
|
+
"**/dist/**",
|
|
6
|
+
"**/playwright-report/**",
|
|
7
|
+
"**/test-results/**",
|
|
8
|
+
"**/.tooling/**"
|
|
9
|
+
],
|
|
10
|
+
"entry": ["src/main.{ts,tsx}", "scripts/*.mjs"]
|
|
11
|
+
}
|
package/configs/playwright.mjs
CHANGED
|
@@ -1,15 +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
|
-
};
|
|
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
|
+
};
|
package/configs/vitest.mjs
CHANGED
|
@@ -1,16 +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
|
-
};
|
|
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,105 +1,105 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@dcaldeira/tooling",
|
|
3
|
-
"version": "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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcaldeira/tooling",
|
|
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
|
+
}
|
package/release/finalize.mjs
CHANGED
|
@@ -1,65 +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}`);
|
|
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/github.mjs
CHANGED
|
@@ -1,64 +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
|
-
}
|
|
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
|
+
}
|