@ankhorage/devtools 2.3.47 → 2.4.1
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 +1 -1
- package/dist/owner/synchronizeRenovateOwnerAsync.js +4 -0
- package/dist/tools/workflows/files/ci-impact.d.ts +25 -0
- package/dist/tools/workflows/files/ci-impact.js +157 -0
- package/dist/tools/workflows/files/files/ci-impact.ts +234 -0
- package/dist/tools/workflows/files/{ci.yml → files/ci.yml} +17 -7
- package/dist/tools/workflows/index.js +4 -0
- package/package.json +3 -3
- /package/dist/tools/workflows/files/{release.yml → files/release.yml} +0 -0
- /package/dist/tools/workflows/files/{renovate.json5 → files/renovate.json5} +0 -0
- /package/dist/tools/workflows/files/{renovate.yml → files/renovate.yml} +0 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# @ankhorage/devtools
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Shared tooling, repository automation, and agent standards for Ankhorage TypeScript projects
|
|
9
9
|
|
|
@@ -45,6 +45,10 @@ async function createManagedDefinitionsAsync(targetDirectory) {
|
|
|
45
45
|
relativePath: '.github/workflows/ci.yml',
|
|
46
46
|
contents: await renderWorkflowAsync(new URL('../tools/workflows/files/ci.yml', import.meta.url), workflowPolicy),
|
|
47
47
|
},
|
|
48
|
+
{
|
|
49
|
+
relativePath: '.github/scripts/ci-impact.ts',
|
|
50
|
+
contents: await readFile(new URL('../tools/workflows/files/ci-impact.ts', import.meta.url), 'utf8'),
|
|
51
|
+
},
|
|
48
52
|
{
|
|
49
53
|
relativePath: '.github/workflows/release.yml',
|
|
50
54
|
contents: await renderWorkflowAsync(new URL('../tools/workflows/files/release.yml', import.meta.url), workflowPolicy),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type Kind = 'e2e' | 'smoke';
|
|
2
|
+
type Mode = 'skip' | 'full' | 'changed' | 'scoped';
|
|
3
|
+
interface Selection {
|
|
4
|
+
readonly mode: Mode;
|
|
5
|
+
readonly scripts: readonly string[];
|
|
6
|
+
readonly reason: string;
|
|
7
|
+
}
|
|
8
|
+
interface Plan {
|
|
9
|
+
readonly base: string;
|
|
10
|
+
readonly unit: Selection;
|
|
11
|
+
readonly e2e: Selection;
|
|
12
|
+
readonly smoke: Selection;
|
|
13
|
+
}
|
|
14
|
+
interface Scope {
|
|
15
|
+
readonly kind: Kind;
|
|
16
|
+
readonly script: string;
|
|
17
|
+
readonly paths: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
interface Configuration {
|
|
20
|
+
readonly complete?: Partial<Record<Kind, boolean>>;
|
|
21
|
+
readonly suites?: readonly Scope[];
|
|
22
|
+
}
|
|
23
|
+
/*** Select safe CI checks, using explicit suite ownership and Bun's dependency graph. */
|
|
24
|
+
export declare function planCiImpact(files: readonly string[] | null, scripts: Readonly<Record<string, string>>, configuration: Configuration | undefined, base: string): Plan;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { appendFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
/*** Select safe CI checks, using explicit suite ownership and Bun's dependency graph. */
|
|
5
|
+
export function planCiImpact(files, scripts, configuration, base) {
|
|
6
|
+
const full = files === null || files.some(isUnsafeChange);
|
|
7
|
+
const docs = files !== null && files.every(isDocumentation);
|
|
8
|
+
const baseSelection = {
|
|
9
|
+
mode: full ? 'full' : 'skip',
|
|
10
|
+
scripts: [],
|
|
11
|
+
reason: full ? 'Unsafe or unavailable diff' : 'Documentation only',
|
|
12
|
+
};
|
|
13
|
+
const unit = scripts.test === undefined
|
|
14
|
+
? { mode: 'skip', scripts: [], reason: 'No test script' }
|
|
15
|
+
: full
|
|
16
|
+
? { mode: 'full', scripts: ['test'], reason: 'Unsafe or unavailable diff' }
|
|
17
|
+
: docs
|
|
18
|
+
? baseSelection
|
|
19
|
+
: scripts.test.trim() === 'bun test'
|
|
20
|
+
? { mode: 'changed', scripts: ['test'], reason: 'Bun transitive import graph' }
|
|
21
|
+
: { mode: 'full', scripts: ['test'], reason: 'Unrecognized test runner' };
|
|
22
|
+
return {
|
|
23
|
+
base,
|
|
24
|
+
unit,
|
|
25
|
+
e2e: selectSuites('e2e', files, scripts, configuration, full, docs),
|
|
26
|
+
smoke: selectSuites('smoke', files, scripts, configuration, full, docs),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/*** Select scoped suites only when an exhaustive repository declaration is valid. */
|
|
30
|
+
function selectSuites(kind, files, scripts, configuration, full, docs) {
|
|
31
|
+
const defaults = (kind === 'e2e' ? ['test:e2e'] : ['test:smoke', 'test:standalone']).filter((name) => scripts[name] !== undefined);
|
|
32
|
+
const suites = configuration?.suites?.filter((suite) => suite.kind === kind) ?? [];
|
|
33
|
+
const validSuites = suites.length > 0 &&
|
|
34
|
+
suites.every((suite) => typeof scripts[suite.script] === 'string' &&
|
|
35
|
+
suite.paths.length > 0 &&
|
|
36
|
+
suite.paths.every((path) => typeof path === 'string' && isSafePattern(path)));
|
|
37
|
+
const fallbackScripts = defaults.length > 0
|
|
38
|
+
? defaults
|
|
39
|
+
: suites.map((suite) => suite.script).filter((script) => scripts[script] !== undefined);
|
|
40
|
+
if (fallbackScripts.length === 0)
|
|
41
|
+
return { mode: 'skip', scripts: [], reason: 'No suite scripts' };
|
|
42
|
+
if (docs)
|
|
43
|
+
return { mode: 'skip', scripts: [], reason: 'Documentation only' };
|
|
44
|
+
if (full || files === null)
|
|
45
|
+
return { mode: 'full', scripts: fallbackScripts, reason: 'Unsafe or unavailable diff' };
|
|
46
|
+
if (configuration?.complete?.[kind] !== true || !validSuites) {
|
|
47
|
+
return { mode: 'full', scripts: fallbackScripts, reason: 'No complete suite mapping' };
|
|
48
|
+
}
|
|
49
|
+
const matches = files.map((file) => suites.filter((suite) => suite.paths.some((pattern) => matchesPath(file, pattern))));
|
|
50
|
+
if (matches.some((found) => found.length === 0)) {
|
|
51
|
+
return { mode: 'full', scripts: fallbackScripts, reason: 'Unmapped changed file' };
|
|
52
|
+
}
|
|
53
|
+
const selected = [...new Set(matches.flat().map((suite) => suite.script))];
|
|
54
|
+
return { mode: 'scoped', scripts: selected, reason: 'Explicit complete suite mapping' };
|
|
55
|
+
}
|
|
56
|
+
/*** Conservatively identify changes that invalidate impact pruning. */
|
|
57
|
+
function isUnsafeChange(file) {
|
|
58
|
+
return (/^(?:\.github\/|\.agents\/|scripts\/|test\/|tests\/|config\/)/u.test(file) ||
|
|
59
|
+
/^(?:package\.json|bun\.lock|bunfig\.toml|AGENTS\.md|tsconfig[^/]*|playwright\.config\.[^/]+|vitest\.config\.[^/]+|jest\.config\.[^/]+|eslint\.config\.[^/]+|\.env[^/]*)$/u.test(file));
|
|
60
|
+
}
|
|
61
|
+
/*** Classify files whose changes cannot influence runtime test execution. */
|
|
62
|
+
function isDocumentation(file) {
|
|
63
|
+
return (file.startsWith('docs/') ||
|
|
64
|
+
file.startsWith('.changeset/') ||
|
|
65
|
+
(/\.(?:md|mdx)$/u.test(file) && !isUnsafeChange(file)) ||
|
|
66
|
+
file === 'LICENSE');
|
|
67
|
+
}
|
|
68
|
+
/*** Keep mapping syntax deliberately restricted to exact paths and directory descendants. */
|
|
69
|
+
function isSafePattern(pattern) {
|
|
70
|
+
return (!pattern.startsWith('/') &&
|
|
71
|
+
!pattern.includes('..') &&
|
|
72
|
+
/^(?:[a-zA-Z0-9_.@-]+\/)*[a-zA-Z0-9_.@*-]+$/u.test(pattern) &&
|
|
73
|
+
(!pattern.includes('*') || pattern.endsWith('/**')));
|
|
74
|
+
}
|
|
75
|
+
/*** Match one declared path or its explicit recursive directory ownership. */
|
|
76
|
+
function matchesPath(file, pattern) {
|
|
77
|
+
return pattern.endsWith('/**') ? file.startsWith(pattern.slice(0, -2)) : file === pattern;
|
|
78
|
+
}
|
|
79
|
+
/*** Read Git's binary-safe status output, failing closed for removals and invalid refs. */
|
|
80
|
+
function readChangedFiles(base) {
|
|
81
|
+
if (!/^[a-f0-9]{40}$/u.test(base))
|
|
82
|
+
return null;
|
|
83
|
+
try {
|
|
84
|
+
execFileSync('git', ['cat-file', '-e', base + '^{commit}'], { stdio: 'ignore' });
|
|
85
|
+
const output = execFileSync('git', ['diff', '--name-status', '--no-renames', '-z', base, 'HEAD', '--'], { encoding: 'utf8' });
|
|
86
|
+
const items = output.split('\0').filter(Boolean);
|
|
87
|
+
if (items.length % 2 !== 0)
|
|
88
|
+
return null;
|
|
89
|
+
const changes = Array.from({ length: items.length / 2 }, (_, index) => ({
|
|
90
|
+
status: items[index * 2],
|
|
91
|
+
path: items[index * 2 + 1],
|
|
92
|
+
}));
|
|
93
|
+
return changes.every((item) => /^[AMT]$/u.test(item.status) && !item.path.includes('\n'))
|
|
94
|
+
? changes.map((item) => item.path)
|
|
95
|
+
: null;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/*** Produce a full plan when the workflow cannot prove a trustworthy PR delta. */
|
|
102
|
+
function createPlan() {
|
|
103
|
+
const manifest = JSON.parse(readFileSync('package.json', 'utf8'));
|
|
104
|
+
const base = process.env.GITHUB_EVENT_NAME === 'pull_request' ? (process.env.ANKH_CI_BASE_SHA ?? '') : '';
|
|
105
|
+
const files = base ? readChangedFiles(base) : null;
|
|
106
|
+
return planCiImpact(files, manifest.scripts ?? {}, manifest.ankh?.ciImpact, base);
|
|
107
|
+
}
|
|
108
|
+
/*** Execute an already saved CI plan without shell interpolation. */
|
|
109
|
+
function runPlan(plan, kind) {
|
|
110
|
+
const selection = plan[kind];
|
|
111
|
+
if (selection.mode === 'skip')
|
|
112
|
+
return;
|
|
113
|
+
if (kind === 'unit' && selection.mode === 'changed') {
|
|
114
|
+
execFileSync('bun', ['test', '--changed=' + plan.base], { stdio: 'inherit' });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
for (const script of selection.scripts) {
|
|
118
|
+
execFileSync('bun', ['run', script], { stdio: 'inherit' });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/*** Expose test decisions in GitHub outputs and a human-readable step summary. */
|
|
122
|
+
function main() {
|
|
123
|
+
const operation = process.argv[2];
|
|
124
|
+
const planPath = join(process.env.RUNNER_TEMP ?? '.', 'ankh-ci-impact-plan.json');
|
|
125
|
+
if (operation === 'plan') {
|
|
126
|
+
const plan = createPlan();
|
|
127
|
+
writeFileSync(planPath, JSON.stringify(plan));
|
|
128
|
+
if (process.env.GITHUB_OUTPUT) {
|
|
129
|
+
appendFileSync(process.env.GITHUB_OUTPUT, ['unit=' + plan.unit.mode, 'e2e=' + plan.e2e.mode, 'smoke=' + plan.smoke.mode].join('\n') +
|
|
130
|
+
'\n');
|
|
131
|
+
}
|
|
132
|
+
console.log(JSON.stringify(plan, null, 2));
|
|
133
|
+
if (process.env.GITHUB_STEP_SUMMARY) {
|
|
134
|
+
appendFileSync(process.env.GITHUB_STEP_SUMMARY, '### CI impact\n\n| Suite | Mode | Reason | Scripts |\n| --- | --- | --- | --- |\n' +
|
|
135
|
+
['unit', 'e2e', 'smoke']
|
|
136
|
+
.map((kind) => '| ' +
|
|
137
|
+
kind +
|
|
138
|
+
' | ' +
|
|
139
|
+
plan[kind].mode +
|
|
140
|
+
' | ' +
|
|
141
|
+
plan[kind].reason +
|
|
142
|
+
' | ' +
|
|
143
|
+
(plan[kind].scripts.join(', ') || '—') +
|
|
144
|
+
' |')
|
|
145
|
+
.join('\n') +
|
|
146
|
+
'\n');
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (operation !== 'unit' && operation !== 'e2e' && operation !== 'smoke') {
|
|
151
|
+
throw new Error('Expected plan, unit, e2e, or smoke');
|
|
152
|
+
}
|
|
153
|
+
const plan = JSON.parse(readFileSync(planPath, 'utf8'));
|
|
154
|
+
runPlan(plan, operation);
|
|
155
|
+
}
|
|
156
|
+
if (import.meta.main)
|
|
157
|
+
main();
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { appendFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
type Kind = 'e2e' | 'smoke';
|
|
6
|
+
type Mode = 'skip' | 'full' | 'changed' | 'scoped';
|
|
7
|
+
interface Selection {
|
|
8
|
+
readonly mode: Mode;
|
|
9
|
+
readonly scripts: readonly string[];
|
|
10
|
+
readonly reason: string;
|
|
11
|
+
}
|
|
12
|
+
interface Plan {
|
|
13
|
+
readonly base: string;
|
|
14
|
+
readonly unit: Selection;
|
|
15
|
+
readonly e2e: Selection;
|
|
16
|
+
readonly smoke: Selection;
|
|
17
|
+
}
|
|
18
|
+
interface Scope {
|
|
19
|
+
readonly kind: Kind;
|
|
20
|
+
readonly script: string;
|
|
21
|
+
readonly paths: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
interface Configuration {
|
|
24
|
+
readonly complete?: Partial<Record<Kind, boolean>>;
|
|
25
|
+
readonly suites?: readonly Scope[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/*** Select safe CI checks, using explicit suite ownership and Bun's dependency graph. */
|
|
29
|
+
export function planCiImpact(
|
|
30
|
+
files: readonly string[] | null,
|
|
31
|
+
scripts: Readonly<Record<string, string>>,
|
|
32
|
+
configuration: Configuration | undefined,
|
|
33
|
+
base: string,
|
|
34
|
+
): Plan {
|
|
35
|
+
const full = files === null || files.some(isUnsafeChange);
|
|
36
|
+
const docs = files !== null && files.every(isDocumentation);
|
|
37
|
+
const baseSelection: Selection = {
|
|
38
|
+
mode: full ? 'full' : 'skip',
|
|
39
|
+
scripts: [],
|
|
40
|
+
reason: full ? 'Unsafe or unavailable diff' : 'Documentation only',
|
|
41
|
+
};
|
|
42
|
+
const unit: Selection =
|
|
43
|
+
scripts.test === undefined
|
|
44
|
+
? { mode: 'skip', scripts: [], reason: 'No test script' }
|
|
45
|
+
: full
|
|
46
|
+
? { mode: 'full', scripts: ['test'], reason: 'Unsafe or unavailable diff' }
|
|
47
|
+
: docs
|
|
48
|
+
? baseSelection
|
|
49
|
+
: scripts.test.trim() === 'bun test'
|
|
50
|
+
? { mode: 'changed', scripts: ['test'], reason: 'Bun transitive import graph' }
|
|
51
|
+
: { mode: 'full', scripts: ['test'], reason: 'Unrecognized test runner' };
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
base,
|
|
55
|
+
unit,
|
|
56
|
+
e2e: selectSuites('e2e', files, scripts, configuration, full, docs),
|
|
57
|
+
smoke: selectSuites('smoke', files, scripts, configuration, full, docs),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/*** Select scoped suites only when an exhaustive repository declaration is valid. */
|
|
62
|
+
function selectSuites(
|
|
63
|
+
kind: Kind,
|
|
64
|
+
files: readonly string[] | null,
|
|
65
|
+
scripts: Readonly<Record<string, string>>,
|
|
66
|
+
configuration: Configuration | undefined,
|
|
67
|
+
full: boolean,
|
|
68
|
+
docs: boolean,
|
|
69
|
+
): Selection {
|
|
70
|
+
const defaults = (kind === 'e2e' ? ['test:e2e'] : ['test:smoke', 'test:standalone']).filter(
|
|
71
|
+
(name) => scripts[name] !== undefined,
|
|
72
|
+
);
|
|
73
|
+
const suites = configuration?.suites?.filter((suite) => suite.kind === kind) ?? [];
|
|
74
|
+
const validSuites =
|
|
75
|
+
suites.length > 0 &&
|
|
76
|
+
suites.every(
|
|
77
|
+
(suite) =>
|
|
78
|
+
typeof scripts[suite.script] === 'string' &&
|
|
79
|
+
suite.paths.length > 0 &&
|
|
80
|
+
suite.paths.every((path) => typeof path === 'string' && isSafePattern(path)),
|
|
81
|
+
);
|
|
82
|
+
const fallbackScripts =
|
|
83
|
+
defaults.length > 0
|
|
84
|
+
? defaults
|
|
85
|
+
: suites.map((suite) => suite.script).filter((script) => scripts[script] !== undefined);
|
|
86
|
+
|
|
87
|
+
if (fallbackScripts.length === 0)
|
|
88
|
+
return { mode: 'skip', scripts: [], reason: 'No suite scripts' };
|
|
89
|
+
if (docs) return { mode: 'skip', scripts: [], reason: 'Documentation only' };
|
|
90
|
+
if (full || files === null)
|
|
91
|
+
return { mode: 'full', scripts: fallbackScripts, reason: 'Unsafe or unavailable diff' };
|
|
92
|
+
if (configuration?.complete?.[kind] !== true || !validSuites) {
|
|
93
|
+
return { mode: 'full', scripts: fallbackScripts, reason: 'No complete suite mapping' };
|
|
94
|
+
}
|
|
95
|
+
const matches = files.map((file) =>
|
|
96
|
+
suites.filter((suite) => suite.paths.some((pattern) => matchesPath(file, pattern))),
|
|
97
|
+
);
|
|
98
|
+
if (matches.some((found) => found.length === 0)) {
|
|
99
|
+
return { mode: 'full', scripts: fallbackScripts, reason: 'Unmapped changed file' };
|
|
100
|
+
}
|
|
101
|
+
const selected = [...new Set(matches.flat().map((suite) => suite.script))];
|
|
102
|
+
return { mode: 'scoped', scripts: selected, reason: 'Explicit complete suite mapping' };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/*** Conservatively identify changes that invalidate impact pruning. */
|
|
106
|
+
function isUnsafeChange(file: string): boolean {
|
|
107
|
+
return (
|
|
108
|
+
/^(?:\.github\/|\.agents\/|scripts\/|test\/|tests\/|config\/)/u.test(file) ||
|
|
109
|
+
/^(?:package\.json|bun\.lock|bunfig\.toml|AGENTS\.md|tsconfig[^/]*|playwright\.config\.[^/]+|vitest\.config\.[^/]+|jest\.config\.[^/]+|eslint\.config\.[^/]+|\.env[^/]*)$/u.test(
|
|
110
|
+
file,
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/*** Classify files whose changes cannot influence runtime test execution. */
|
|
116
|
+
function isDocumentation(file: string): boolean {
|
|
117
|
+
return (
|
|
118
|
+
file.startsWith('docs/') ||
|
|
119
|
+
file.startsWith('.changeset/') ||
|
|
120
|
+
(/\.(?:md|mdx)$/u.test(file) && !isUnsafeChange(file)) ||
|
|
121
|
+
file === 'LICENSE'
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/*** Keep mapping syntax deliberately restricted to exact paths and directory descendants. */
|
|
126
|
+
function isSafePattern(pattern: string): boolean {
|
|
127
|
+
return (
|
|
128
|
+
!pattern.startsWith('/') &&
|
|
129
|
+
!pattern.includes('..') &&
|
|
130
|
+
/^(?:[a-zA-Z0-9_.@-]+\/)*[a-zA-Z0-9_.@*-]+$/u.test(pattern) &&
|
|
131
|
+
(!pattern.includes('*') || pattern.endsWith('/**'))
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/*** Match one declared path or its explicit recursive directory ownership. */
|
|
136
|
+
function matchesPath(file: string, pattern: string): boolean {
|
|
137
|
+
return pattern.endsWith('/**') ? file.startsWith(pattern.slice(0, -2)) : file === pattern;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/*** Read Git's binary-safe status output, failing closed for removals and invalid refs. */
|
|
141
|
+
function readChangedFiles(base: string): readonly string[] | null {
|
|
142
|
+
if (!/^[a-f0-9]{40}$/u.test(base)) return null;
|
|
143
|
+
try {
|
|
144
|
+
execFileSync('git', ['cat-file', '-e', base + '^{commit}'], { stdio: 'ignore' });
|
|
145
|
+
const output = execFileSync(
|
|
146
|
+
'git',
|
|
147
|
+
['diff', '--name-status', '--no-renames', '-z', base, 'HEAD', '--'],
|
|
148
|
+
{ encoding: 'utf8' },
|
|
149
|
+
);
|
|
150
|
+
const items = output.split('\0').filter(Boolean);
|
|
151
|
+
if (items.length % 2 !== 0) return null;
|
|
152
|
+
const changes = Array.from({ length: items.length / 2 }, (_, index) => ({
|
|
153
|
+
status: items[index * 2],
|
|
154
|
+
path: items[index * 2 + 1],
|
|
155
|
+
}));
|
|
156
|
+
return changes.every((item) => /^[AMT]$/u.test(item.status) && !item.path.includes('\n'))
|
|
157
|
+
? changes.map((item) => item.path)
|
|
158
|
+
: null;
|
|
159
|
+
} catch {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/*** Produce a full plan when the workflow cannot prove a trustworthy PR delta. */
|
|
165
|
+
function createPlan(): Plan {
|
|
166
|
+
const manifest = JSON.parse(readFileSync('package.json', 'utf8')) as {
|
|
167
|
+
scripts?: Record<string, string>;
|
|
168
|
+
ankh?: { ciImpact?: Configuration };
|
|
169
|
+
};
|
|
170
|
+
const base =
|
|
171
|
+
process.env.GITHUB_EVENT_NAME === 'pull_request' ? (process.env.ANKH_CI_BASE_SHA ?? '') : '';
|
|
172
|
+
const files = base ? readChangedFiles(base) : null;
|
|
173
|
+
return planCiImpact(files, manifest.scripts ?? {}, manifest.ankh?.ciImpact, base);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/*** Execute an already saved CI plan without shell interpolation. */
|
|
177
|
+
function runPlan(plan: Plan, kind: 'unit' | Kind): void {
|
|
178
|
+
const selection = plan[kind];
|
|
179
|
+
if (selection.mode === 'skip') return;
|
|
180
|
+
if (kind === 'unit' && selection.mode === 'changed') {
|
|
181
|
+
execFileSync('bun', ['test', '--changed=' + plan.base], { stdio: 'inherit' });
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
for (const script of selection.scripts) {
|
|
185
|
+
execFileSync('bun', ['run', script], { stdio: 'inherit' });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/*** Expose test decisions in GitHub outputs and a human-readable step summary. */
|
|
190
|
+
function main(): void {
|
|
191
|
+
const operation = process.argv[2];
|
|
192
|
+
const planPath = join(process.env.RUNNER_TEMP ?? '.', 'ankh-ci-impact-plan.json');
|
|
193
|
+
if (operation === 'plan') {
|
|
194
|
+
const plan = createPlan();
|
|
195
|
+
writeFileSync(planPath, JSON.stringify(plan));
|
|
196
|
+
if (process.env.GITHUB_OUTPUT) {
|
|
197
|
+
appendFileSync(
|
|
198
|
+
process.env.GITHUB_OUTPUT,
|
|
199
|
+
['unit=' + plan.unit.mode, 'e2e=' + plan.e2e.mode, 'smoke=' + plan.smoke.mode].join('\n') +
|
|
200
|
+
'\n',
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
console.log(JSON.stringify(plan, null, 2));
|
|
204
|
+
if (process.env.GITHUB_STEP_SUMMARY) {
|
|
205
|
+
appendFileSync(
|
|
206
|
+
process.env.GITHUB_STEP_SUMMARY,
|
|
207
|
+
'### CI impact\n\n| Suite | Mode | Reason | Scripts |\n| --- | --- | --- | --- |\n' +
|
|
208
|
+
(['unit', 'e2e', 'smoke'] as const)
|
|
209
|
+
.map(
|
|
210
|
+
(kind) =>
|
|
211
|
+
'| ' +
|
|
212
|
+
kind +
|
|
213
|
+
' | ' +
|
|
214
|
+
plan[kind].mode +
|
|
215
|
+
' | ' +
|
|
216
|
+
plan[kind].reason +
|
|
217
|
+
' | ' +
|
|
218
|
+
(plan[kind].scripts.join(', ') || '—') +
|
|
219
|
+
' |',
|
|
220
|
+
)
|
|
221
|
+
.join('\n') +
|
|
222
|
+
'\n',
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (operation !== 'unit' && operation !== 'e2e' && operation !== 'smoke') {
|
|
228
|
+
throw new Error('Expected plan, unit, e2e, or smoke');
|
|
229
|
+
}
|
|
230
|
+
const plan = JSON.parse(readFileSync(planPath, 'utf8')) as Plan;
|
|
231
|
+
runPlan(plan, operation);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (import.meta.main) main();
|
|
@@ -100,13 +100,23 @@ jobs:
|
|
|
100
100
|
echo "No knip:check script found; skipping."
|
|
101
101
|
fi
|
|
102
102
|
|
|
103
|
-
- name:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
- name: Analyze test impact
|
|
104
|
+
id: impact
|
|
105
|
+
env:
|
|
106
|
+
ANKH_CI_BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
|
107
|
+
run: bun .github/scripts/ci-impact.ts plan
|
|
108
|
+
|
|
109
|
+
- name: Run unit tests
|
|
110
|
+
if: steps.impact.outputs.unit != 'skip'
|
|
111
|
+
run: bun .github/scripts/ci-impact.ts unit
|
|
112
|
+
|
|
113
|
+
- name: Run E2E tests
|
|
114
|
+
if: steps.impact.outputs.e2e != 'skip'
|
|
115
|
+
run: bun .github/scripts/ci-impact.ts e2e
|
|
116
|
+
|
|
117
|
+
- name: Run Smoke tests
|
|
118
|
+
if: steps.impact.outputs.smoke != 'skip'
|
|
119
|
+
run: bun .github/scripts/ci-impact.ts smoke
|
|
110
120
|
|
|
111
121
|
- name: Run typecheck
|
|
112
122
|
run: |
|
|
@@ -25,6 +25,10 @@ export const workflowManagedFiles = [
|
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
createRenovateWorkflowDefinition(),
|
|
28
|
+
{
|
|
29
|
+
relativePath: '.github/scripts/ci-impact.ts',
|
|
30
|
+
sourceUrl: new URL('./files/ci-impact.ts', import.meta.url),
|
|
31
|
+
},
|
|
28
32
|
{
|
|
29
33
|
relativePath: 'renovate.json5',
|
|
30
34
|
render: renderRenovateConfigAsync,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/devtools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Shared tooling, repository automation, and agent standards for Ankhorage TypeScript projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/ankhorage/devtools#readme",
|
|
@@ -492,7 +492,7 @@
|
|
|
492
492
|
"dependencies": {
|
|
493
493
|
"@ankhorage/apm": "^0.8.15",
|
|
494
494
|
"@ankhorage/capability": "^0.2.2",
|
|
495
|
-
"@ankhorage/contracts": "^26.
|
|
495
|
+
"@ankhorage/contracts": "^26.4.0",
|
|
496
496
|
"@ankhorage/project-detector": "^0.3.5",
|
|
497
497
|
"@ankhorage/rules-repository": "0.2.3",
|
|
498
498
|
"@ankhorage/utility": "^0.5.5",
|
|
@@ -518,7 +518,7 @@
|
|
|
518
518
|
"devDependencies": {
|
|
519
519
|
"@ankhorage/paradox": "^0.3.6",
|
|
520
520
|
"@ankhorage/ankh": "^0.13.3",
|
|
521
|
-
"@ankhorage/doctor": "0.14.
|
|
521
|
+
"@ankhorage/doctor": "0.14.30",
|
|
522
522
|
"@techstark/opencv-js": "^5.0.0-release.1",
|
|
523
523
|
"@types/bun": "^1.4.2",
|
|
524
524
|
"@types/node": "^26.6.6",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|