@zgeoff/chex 0.8.7 → 0.8.8

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.
Files changed (50) hide show
  1. package/README.md +1 -1
  2. package/lefthook.yml +13 -0
  3. package/package.json +1 -1
  4. package/src/ci-plan/build-ci-plan-output.ts +1 -37
  5. package/src/ci-plan/collect-shared-checks.ts +1 -41
  6. package/src/ci-plan/find-chex-args.ts +40 -0
  7. package/src/ci-plan/parse-package-scripts.ts +36 -0
  8. package/src/workflows/collect-allowances.ts +101 -0
  9. package/src/workflows/collect-concurrency-findings.ts +1 -1
  10. package/src/workflows/collect-hook-findings.ts +13 -0
  11. package/src/workflows/collect-moved-repo-findings.ts +34 -0
  12. package/src/workflows/collect-run-commands.ts +18 -0
  13. package/src/workflows/collect-runner-labels.ts +8 -0
  14. package/src/workflows/collect-steps.ts +9 -0
  15. package/src/workflows/constants.ts +4 -0
  16. package/src/workflows/find-heavy-runner.ts +20 -0
  17. package/src/workflows/is-list.ts +4 -0
  18. package/src/workflows/parse-repo-slug.ts +7 -0
  19. package/src/workflows/pick-checked-paths.ts +33 -0
  20. package/src/workflows/pick-repo-move.ts +28 -0
  21. package/src/workflows/read-repo-slug.ts +12 -0
  22. package/src/workflows/read-repo-state.ts +57 -0
  23. package/src/workflows/rules/build-rule-finding.ts +10 -0
  24. package/src/workflows/rules/collect-condition-terms.ts +116 -0
  25. package/src/workflows/rules/collect-hook-check-findings.ts +84 -0
  26. package/src/workflows/rules/collect-main-only-job-findings.ts +123 -0
  27. package/src/workflows/rules/collect-main-run-concurrency-findings.ts +77 -0
  28. package/src/workflows/rules/collect-main-run-shape-findings.ts +161 -0
  29. package/src/workflows/rules/collect-needs.ts +13 -0
  30. package/src/workflows/rules/collect-path-filter-findings.ts +56 -0
  31. package/src/workflows/rules/collect-pr-gate-findings.ts +72 -0
  32. package/src/workflows/rules/collect-publish-findings.ts +83 -0
  33. package/src/workflows/rules/collect-release-jobs.ts +55 -0
  34. package/src/workflows/rules/collect-release-shape-findings.ts +67 -0
  35. package/src/workflows/rules/find-file-filter.ts +91 -0
  36. package/src/workflows/rules/find-image-build.ts +59 -0
  37. package/src/workflows/rules/find-job-environment.ts +9 -0
  38. package/src/workflows/rules/find-matrix-runner.ts +38 -0
  39. package/src/workflows/rules/find-shipped-build.ts +36 -0
  40. package/src/workflows/rules/is-arm-label.ts +5 -0
  41. package/src/workflows/rules/is-release-condition.ts +19 -0
  42. package/src/workflows/rules/is-shared-check-script.ts +22 -0
  43. package/src/workflows/rules/is-shared-release-workflow.ts +14 -0
  44. package/src/workflows/rules/is-workflow-call.ts +12 -0
  45. package/src/workflows/rules/types.ts +31 -0
  46. package/src/workflows/run-workflows-check.ts +60 -55
  47. package/src/workflows/to-unwrapped-command.ts +28 -0
  48. package/src/workflows/to-workflow-findings.ts +24 -0
  49. package/src/workflows/types.ts +68 -0
  50. package/src/workflows/workflow-context.ts +0 -24
@@ -0,0 +1,116 @@
1
+ // The terms of an `if` that GitHub runs only when every term holds, lower-cased and without the
2
+ // whitespace outside quoted values, or undefined when the condition is no plain conjunction: an
3
+ // `||` outside brackets lets a run through without its other terms.
4
+ export function collectConditionTerms(condition: unknown): string[] | undefined {
5
+ if (condition === undefined) {
6
+ return [];
7
+ }
8
+
9
+ if (typeof condition === 'boolean') {
10
+ return [String(condition)];
11
+ }
12
+
13
+ if (typeof condition !== 'string') {
14
+ return undefined;
15
+ }
16
+
17
+ const text = condition.trim();
18
+ const body = text.startsWith('${{') && text.endsWith('}}') ? text.slice(3, -2) : text;
19
+
20
+ return body.includes('${{') ? undefined : collectTerms(body);
21
+ }
22
+
23
+ function collectTerms(expression: string): string[] | undefined {
24
+ const text = toUnbracketed(expression.trim());
25
+
26
+ if (splitOutsideBrackets(text, '||').length > 1) {
27
+ return undefined;
28
+ }
29
+
30
+ const parts = splitOutsideBrackets(text, '&&');
31
+
32
+ if (parts.length === 1) {
33
+ return [toNormalizedTerm(text)];
34
+ }
35
+
36
+ const terms = parts.map((part) => collectTerms(part));
37
+
38
+ return terms.every((term) => term !== undefined) ? terms.flat() : undefined;
39
+ }
40
+
41
+ function toUnbracketed(text: string): string {
42
+ return text.startsWith('(') && isClosedAtEnd(text)
43
+ ? toUnbracketed(text.slice(1, -1).trim())
44
+ : text;
45
+ }
46
+
47
+ // Whether the bracket that opens the text closes at its last character.
48
+ function isClosedAtEnd(text: string): boolean {
49
+ let depth = 0;
50
+ let isInString = false;
51
+
52
+ // The brackets and quotes are ASCII, so a loop over UTF-16 code units finds them.
53
+ for (let index = 0; index < text.length; index += 1) {
54
+ const character = text[index];
55
+
56
+ if (character === "'") {
57
+ isInString = !isInString;
58
+ } else if (!isInString && (character === '(' || character === '[')) {
59
+ depth += 1;
60
+ } else if (!isInString && (character === ')' || character === ']')) {
61
+ depth -= 1;
62
+ }
63
+
64
+ if (depth === 0 && index < text.length - 1) {
65
+ return false;
66
+ }
67
+ }
68
+
69
+ return depth === 0;
70
+ }
71
+
72
+ function splitOutsideBrackets(text: string, separator: string): string[] {
73
+ const parts: string[] = [];
74
+ let depth = 0;
75
+ let isInString = false;
76
+ let start = 0;
77
+
78
+ for (let index = 0; index < text.length; index += 1) {
79
+ const character = text.charAt(index);
80
+
81
+ if (character === "'") {
82
+ isInString = !isInString;
83
+ } else if (!isInString && (character === '(' || character === '[')) {
84
+ depth += 1;
85
+ } else if (!isInString && (character === ')' || character === ']')) {
86
+ depth -= 1;
87
+ } else if (!isInString && depth === 0 && text.startsWith(separator, index)) {
88
+ parts.push(text.slice(start, index));
89
+
90
+ start = index + separator.length;
91
+ index += separator.length - 1;
92
+ }
93
+ }
94
+
95
+ parts.push(text.slice(start));
96
+
97
+ return parts;
98
+ }
99
+
100
+ // GitHub compares strings without regard to case, and a space inside a quoted value is part of it.
101
+ function toNormalizedTerm(text: string): string {
102
+ let isInString = false;
103
+ let term = '';
104
+
105
+ for (const character of text.toLowerCase()) {
106
+ if (character === "'") {
107
+ isInString = !isInString;
108
+ }
109
+
110
+ if (isInString || character === "'" || !/\s/u.test(character)) {
111
+ term += character;
112
+ }
113
+ }
114
+
115
+ return term;
116
+ }
@@ -0,0 +1,84 @@
1
+ import { findChexArgs } from '../../ci-plan/find-chex-args.ts';
2
+ import type { ShellWord } from '../../shell/parse-shell-words.ts';
3
+ import { collectCommandNames } from '../collect-command-names.ts';
4
+ import { collectRunCommands } from '../collect-run-commands.ts';
5
+ import { findMember } from '../find-member.ts';
6
+ import { isList } from '../is-list.ts';
7
+ import type { HookFile, MovedRepo } from '../types.ts';
8
+ import { buildRuleFinding } from './build-rule-finding.ts';
9
+ import { isSharedCheckScript } from './is-shared-check-script.ts';
10
+ import type { RuleFinding } from './types.ts';
11
+
12
+ // audit and check:docs are shared checks that every run makes.
13
+ const sharedScripts = new Set(['audit', 'check:docs']);
14
+
15
+ export function collectHookCheckFindings(hook: HookFile, repo: MovedRepo): RuleFinding[] {
16
+ if (repo.plan.kind !== 'planned') {
17
+ return [];
18
+ }
19
+
20
+ const listed = new Set(repo.plan.plan.scripts);
21
+
22
+ return collectPrePushRuns(findMember(hook.document, 'pre-push')).flatMap((run) => {
23
+ const line = Math.max(
24
+ hook.lines.findIndex((text) => text.includes(run.split('\n')[0] ?? run)) + 1,
25
+ 1,
26
+ );
27
+
28
+ return collectRunCommands(run).flatMap((words) => {
29
+ const script = findHookScript(words, repo.packageScripts);
30
+
31
+ if (
32
+ script === undefined ||
33
+ listed.has(script) ||
34
+ sharedScripts.has(script) ||
35
+ isSharedCheckScript(repo.packageScripts?.[script])
36
+ ) {
37
+ return [];
38
+ }
39
+
40
+ return [
41
+ {
42
+ ...buildRuleFinding(
43
+ 'hook-check-missing-in-ci',
44
+ line,
45
+ `the pre-push hook runs the script ${script}, which .github/ci.yml does not list and no shared check runs; add ${script} to scripts in .github/ci.yml, or remove it from the hook`,
46
+ [line],
47
+ ),
48
+ path: hook.path,
49
+ },
50
+ ];
51
+ });
52
+ });
53
+ }
54
+
55
+ function collectPrePushRuns(node: unknown): string[] {
56
+ if (isList(node)) {
57
+ return node.flatMap((member) => collectPrePushRuns(member));
58
+ }
59
+
60
+ if (typeof node !== 'object' || node === null) {
61
+ return [];
62
+ }
63
+
64
+ const run = findMember(node, 'run');
65
+ const nested = Object.values(node).flatMap((member: unknown) => collectPrePushRuns(member));
66
+
67
+ return typeof run === 'string' ? [run, ...nested] : nested;
68
+ }
69
+
70
+ // The package script of a `bun run <script>` or `bun <script>` command. A command that runs chex is
71
+ // one of the shared checks, and a file that bun runs is no package script.
72
+ function findHookScript(
73
+ words: readonly ShellWord[],
74
+ packageScripts: Readonly<Record<string, string>> | undefined,
75
+ ): string | undefined {
76
+ if (findChexArgs(words.map((word) => word.text)) !== undefined) {
77
+ return undefined;
78
+ }
79
+
80
+ const names = collectCommandNames(words);
81
+ const script = names?.length === 2 && names[0] === 'bun' ? names[1] : undefined;
82
+
83
+ return script !== undefined && packageScripts?.[script] !== undefined ? script : undefined;
84
+ }
@@ -0,0 +1,123 @@
1
+ import { laneNames } from '../../ci-plan/plan-check-scripts.ts';
2
+ import { collectRunCommands } from '../collect-run-commands.ts';
3
+ import { collectRunnerLabels } from '../collect-runner-labels.ts';
4
+ import { collectSteps } from '../collect-steps.ts';
5
+ import { expressionOpening } from '../constants.ts';
6
+ import { findHeavyRunner } from '../find-heavy-runner.ts';
7
+ import { findMember } from '../find-member.ts';
8
+ import { pullRequestTriggers } from '../pull-request-triggers.ts';
9
+ import { toUnwrappedCommand } from '../to-unwrapped-command.ts';
10
+ import type { Job, WorkflowContext } from '../types.ts';
11
+ import { buildRuleFinding } from './build-rule-finding.ts';
12
+ import { findImageBuild } from './find-image-build.ts';
13
+ import { findMatrixRunner } from './find-matrix-runner.ts';
14
+ import { isARMLabel } from './is-arm-label.ts';
15
+ import type { RuleFinding } from './types.ts';
16
+
17
+ export function collectMainOnlyJobFindings(workflow: WorkflowContext): RuleFinding[] {
18
+ const trigger = pullRequestTriggers.find((name) => workflow.triggers.has(name));
19
+
20
+ if (trigger === undefined) {
21
+ return [];
22
+ }
23
+
24
+ return workflow.jobs.flatMap((job) => {
25
+ const reason = findMainOnlyReason(job);
26
+
27
+ return reason === undefined
28
+ ? []
29
+ : [
30
+ buildRuleFinding(
31
+ 'main-only-job-in-pr',
32
+ job.line,
33
+ `job ${job.id} ${reason}, in a workflow that runs on ${trigger}; move it to main.yml, or keep the work inside a test script that holds the PR's 5 minutes`,
34
+ [job.line],
35
+ ),
36
+ ];
37
+ });
38
+ }
39
+
40
+ const kvmSetupCommands = new Set(['scripts/ci/check-kvm.sh', 'scripts/open-kvm.sh', 'ci:open-kvm']);
41
+
42
+ // These print their arguments, so a path or a command name after them runs nothing.
43
+ const textCommands = new Set(['echo', 'printf']);
44
+
45
+ const vmAndSystemCommandPattern =
46
+ /^(?:qemu(?:-.+)?|firecracker|virsh|vagrant|multipass|limactl|zfs|zpool|systemctl|systemd-.+|machinectl)$/u;
47
+
48
+ function findMainOnlyReason(job: Job): string | undefined {
49
+ const runsOn = findMember(job.definition, 'runs-on');
50
+ const runner = findHeavyRunner(runsOn) ?? findArmRunner(runsOn) ?? findMatrixRunner(job);
51
+
52
+ if (runner !== undefined) {
53
+ return `runs on ${runner}, which is not an ubuntu x64 runner`;
54
+ }
55
+
56
+ const build = findImageBuild(job);
57
+
58
+ if (build !== undefined) {
59
+ return `builds an image or binary with ${build}`;
60
+ }
61
+
62
+ const commands = collectSteps(job).flatMap((step) => {
63
+ const run = findMember(step, 'run');
64
+
65
+ return typeof run === 'string'
66
+ ? collectRunCommands(run).map((words) => toUnwrappedCommand(words.map((word) => word.text)))
67
+ : [];
68
+ });
69
+
70
+ const kvm = commands
71
+ .filter(([name]) => !textCommands.has(name ?? ''))
72
+ .flat()
73
+ .find((word) => word.includes('/dev/kvm') || kvmSetupCommands.has(word));
74
+
75
+ if (kvm !== undefined) {
76
+ return `uses ${kvm}`;
77
+ }
78
+
79
+ const system = commands.find(
80
+ ([name]) => name !== undefined && vmAndSystemCommandPattern.test(name),
81
+ );
82
+
83
+ if (system?.[0] !== undefined) {
84
+ return `runs ${system[0]}, which needs a VM, ZFS or systemd`;
85
+ }
86
+
87
+ return isLaneMatrix(job, commands) ? 'is a matrix whose entries run test lanes' : undefined;
88
+ }
89
+
90
+ function findArmRunner(runsOn: unknown): string | undefined {
91
+ const labels = collectRunnerLabels(runsOn);
92
+
93
+ return labels.some((label) => label.includes(expressionOpening))
94
+ ? undefined
95
+ : labels.find((label) => isARMLabel(label));
96
+ }
97
+
98
+ const laneScripts = new Set(laneNames.map((lane) => `test:${lane}`));
99
+
100
+ function isLaneMatrix(job: Job, commands: readonly (readonly string[])[]): boolean {
101
+ const matrix = findMember(findMember(job.definition, 'strategy'), 'matrix');
102
+
103
+ if (matrix === undefined) {
104
+ return false;
105
+ }
106
+
107
+ const values = collectStrings(matrix);
108
+
109
+ return (
110
+ commands.some((words) => words.some((word) => laneScripts.has(word))) ||
111
+ values.some((value) => laneScripts.has(value) || laneNames.includes(value))
112
+ );
113
+ }
114
+
115
+ function collectStrings(value: unknown): string[] {
116
+ if (typeof value === 'string') {
117
+ return [value];
118
+ }
119
+
120
+ return typeof value === 'object' && value !== null
121
+ ? Object.values(value).flatMap((member: unknown) => collectStrings(member))
122
+ : [];
123
+ }
@@ -0,0 +1,77 @@
1
+ import { findMember } from '../find-member.ts';
2
+ import { getTopLevelLine } from '../get-top-level-line.ts';
3
+ import type { WorkflowContext } from '../types.ts';
4
+ import { buildRuleFinding } from './build-rule-finding.ts';
5
+ import type { RuleFinding } from './types.ts';
6
+
7
+ const sharedGroup =
8
+ "github.event_name == 'push' && 'main-run-push' || format('main-run-{0}', github.run_id)";
9
+
10
+ export function collectMainRunConcurrencyFindings(workflow: WorkflowContext): RuleFinding[] {
11
+ if (!workflow.path.endsWith('/main.yml')) {
12
+ return [];
13
+ }
14
+
15
+ const concurrency = findMember(workflow.workflow, 'concurrency');
16
+ const onLine = getTopLevelLine(workflow.lines, 'on');
17
+
18
+ const concurrencyLine =
19
+ concurrency === undefined ? onLine : getTopLevelLine(workflow.lines, 'concurrency');
20
+
21
+ const allowAt = [onLine, concurrencyLine];
22
+ const group = typeof concurrency === 'string' ? concurrency : findMember(concurrency, 'group');
23
+ const queue = findMember(concurrency, 'queue');
24
+ const faults: string[] = [];
25
+
26
+ if (typeof group !== 'string' || !isSharedGroup(group)) {
27
+ faults.push(
28
+ `the group is not the shared expression; write \`group: \${{ ${sharedGroup} }}\`, so pushes queue in one group and each schedule or dispatch run gets its own`,
29
+ );
30
+ }
31
+
32
+ if (isCancelling(concurrency)) {
33
+ faults.push(
34
+ 'cancel-in-progress is not false; set it to false, since a main run is never cancelled',
35
+ );
36
+ }
37
+
38
+ if (queue === 'max') {
39
+ faults.push(
40
+ 'queue: max is set at the workflow level; remove it, since only the release job queues every run',
41
+ );
42
+ }
43
+
44
+ const workflowFindings = faults.map((fault) =>
45
+ buildRuleFinding('main-run-concurrency', concurrencyLine, fault, allowAt),
46
+ );
47
+
48
+ // A job's own group replaces the workflow's, so a job that cancels can stop a push run.
49
+ const jobFindings = workflow.jobs
50
+ .filter((job) => isCancelling(findMember(job.definition, 'concurrency')))
51
+ .map((job) =>
52
+ buildRuleFinding(
53
+ 'main-run-concurrency',
54
+ job.line,
55
+ `job ${job.id} sets a cancel-in-progress that is not false; set it to false, since a main run is never cancelled`,
56
+ [job.line],
57
+ ),
58
+ );
59
+
60
+ return [...workflowFindings, ...jobFindings];
61
+ }
62
+
63
+ const wholeExpressionPattern = /^\s*\$\{\{(?<body>.*)\}\}\s*$/su;
64
+
65
+ // A group with no `${{ }}` is text, which every event shares.
66
+ function isSharedGroup(group: string): boolean {
67
+ const body = wholeExpressionPattern.exec(group)?.groups?.['body'];
68
+
69
+ return body !== undefined && body.trim().replaceAll(/\s+/gu, ' ') === sharedGroup;
70
+ }
71
+
72
+ // A missing cancel-in-progress never cancels.
73
+ function isCancelling(concurrency: unknown): boolean {
74
+ const cancel = findMember(concurrency, 'cancel-in-progress');
75
+
76
+ return cancel !== undefined && cancel !== false && cancel !== 'false';
77
+ }
@@ -0,0 +1,161 @@
1
+ import { findMember } from '../find-member.ts';
2
+ import { getTopLevelLine } from '../get-top-level-line.ts';
3
+ import type { Job, MovedRepo, WorkflowContext } from '../types.ts';
4
+ import { buildRuleFinding } from './build-rule-finding.ts';
5
+ import { collectNeeds } from './collect-needs.ts';
6
+ import { collectReleaseJobs } from './collect-release-jobs.ts';
7
+ import { findShippedBuild } from './find-shipped-build.ts';
8
+ import { isWorkflowCall } from './is-workflow-call.ts';
9
+ import type { RuleFinding } from './types.ts';
10
+
11
+ const settingsFile = '.github/ci.yml';
12
+
13
+ export function collectMainRunShapeFindings(
14
+ workflow: WorkflowContext,
15
+ repo: MovedRepo,
16
+ ): RuleFinding[] {
17
+ if (!workflow.path.endsWith('/main.yml')) {
18
+ return [];
19
+ }
20
+
21
+ const jobsLine = getTopLevelLine(workflow.lines, 'jobs');
22
+ const nameLine = getTopLevelLine(workflow.lines, 'name');
23
+
24
+ const checksJobs = workflow.jobs.filter((job) =>
25
+ isWorkflowCall(findMember(job.definition, 'uses'), 'checks.yml', repo.move),
26
+ );
27
+
28
+ const pickJobs = workflow.jobs.filter((job) =>
29
+ isWorkflowCall(findMember(job.definition, 'uses'), 'pick-tests.yml', repo.move),
30
+ );
31
+
32
+ const slowTests = repo.plan.kind === 'planned' ? repo.plan.plan.slowTests : {};
33
+ const faults: RuleFinding[] = [];
34
+
35
+ if (findMember(workflow.workflow, 'name') !== 'Main') {
36
+ faults.push(
37
+ buildRuleFinding(
38
+ 'main-run-shape',
39
+ nameLine,
40
+ 'the workflow is not named `Main`; set `name: Main`, which audit-fix and repo sync match',
41
+ [nameLine],
42
+ ),
43
+ );
44
+ }
45
+
46
+ if (checksJobs.length === 0) {
47
+ faults.push(
48
+ buildRuleFinding(
49
+ 'main-run-shape',
50
+ jobsLine,
51
+ 'no job calls checks.yml; add a job that calls it, so every main run repeats the fast checks',
52
+ [jobsLine],
53
+ ),
54
+ );
55
+ }
56
+
57
+ if (pickJobs.length === 0) {
58
+ faults.push(
59
+ buildRuleFinding(
60
+ 'main-run-shape',
61
+ jobsLine,
62
+ 'no job calls pick-tests.yml; add a job that calls it, so each run picks its slow tests',
63
+ [jobsLine],
64
+ ),
65
+ );
66
+ }
67
+
68
+ if (repo.plan.kind === 'invalid') {
69
+ faults.push({
70
+ ...buildRuleFinding(
71
+ 'main-run-shape',
72
+ 1,
73
+ `${settingsFile} is invalid, so its slow-tests cannot be checked: ${repo.plan.errors.join(' ')}`,
74
+ [],
75
+ ),
76
+ path: settingsFile,
77
+ });
78
+
79
+ return faults;
80
+ }
81
+
82
+ const releaseJobs = collectReleaseJobs(workflow.jobs, true);
83
+ const gateIDs = [...checksJobs, ...pickJobs].map((job) => job.id);
84
+
85
+ const gates = new Set(gateIDs);
86
+
87
+ const slowJobs = workflow.jobs.filter((job) => !gates.has(job.id) && !releaseJobs.has(job.id));
88
+
89
+ for (const job of slowJobs) {
90
+ faults.push(...collectSlowJobFindings(job, gateIDs, slowTests));
91
+ }
92
+
93
+ const jobIDs = new Set(workflow.jobs.map((job) => job.id));
94
+
95
+ for (const name of Object.keys(slowTests).filter((entry) => !jobIDs.has(entry))) {
96
+ const line =
97
+ repo.planLines.findIndex((text) =>
98
+ new RegExp(`^\\s+${RegExp.escape(name)}:`, 'u').test(text),
99
+ ) + 1;
100
+
101
+ faults.push({
102
+ ...buildRuleFinding(
103
+ 'main-run-shape',
104
+ line || 1,
105
+ `the slow-tests entry "${name}" names no job of main.yml; add the job or remove the entry`,
106
+ [],
107
+ ),
108
+ path: settingsFile,
109
+ });
110
+ }
111
+
112
+ return faults;
113
+ }
114
+
115
+ function collectSlowJobFindings(
116
+ job: Job,
117
+ gateIDs: readonly string[],
118
+ slowTests: Readonly<Record<string, unknown>>,
119
+ ): RuleFinding[] {
120
+ const needs = collectNeeds(job);
121
+ const missing = gateIDs.filter((id) => !needs.includes(id));
122
+ const entry = slowTests[job.id];
123
+ const findings: RuleFinding[] = [];
124
+
125
+ if (missing.length > 0) {
126
+ findings.push(
127
+ buildRuleFinding(
128
+ 'main-run-shape',
129
+ job.line,
130
+ `slow test ${job.id} does not need ${missing.join(' and ')}; add ${missing.length === 1 ? 'it' : 'both'} to its needs itself, since GitHub exposes the outputs of a direct need only, so it runs after the fast checks and reads the picked tests`,
131
+ [job.line],
132
+ ),
133
+ );
134
+ }
135
+
136
+ if (entry === undefined) {
137
+ findings.push(
138
+ buildRuleFinding(
139
+ 'main-run-shape',
140
+ job.line,
141
+ `slow test ${job.id} has no entry in slow-tests of ${settingsFile}; add one, as always, daily or run-when-changed`,
142
+ [job.line],
143
+ ),
144
+ );
145
+ } else if (entry !== 'always') {
146
+ const build = findShippedBuild(job);
147
+
148
+ if (build !== undefined) {
149
+ findings.push(
150
+ buildRuleFinding(
151
+ 'main-run-shape',
152
+ job.line,
153
+ `job ${job.id} builds what ships, with ${build}, so its slow-tests entry must be always; change it, so every passed run has its artefact`,
154
+ [job.line],
155
+ ),
156
+ );
157
+ }
158
+ }
159
+
160
+ return findings;
161
+ }
@@ -0,0 +1,13 @@
1
+ import { findMember } from '../find-member.ts';
2
+ import { isList } from '../is-list.ts';
3
+ import type { Job } from '../types.ts';
4
+
5
+ export function collectNeeds(job: Job): string[] {
6
+ const needs = findMember(job.definition, 'needs');
7
+
8
+ if (typeof needs === 'string') {
9
+ return [needs];
10
+ }
11
+
12
+ return isList(needs) ? needs.filter((need): need is string => typeof need === 'string') : [];
13
+ }
@@ -0,0 +1,56 @@
1
+ import { findMember } from '../find-member.ts';
2
+ import { getTopLevelLine } from '../get-top-level-line.ts';
3
+ import type { MovedRepo, WorkflowContext } from '../types.ts';
4
+ import { buildRuleFinding } from './build-rule-finding.ts';
5
+ import { findFileFilter } from './find-file-filter.ts';
6
+ import type { RuleFinding } from './types.ts';
7
+
8
+ export function collectPathFilterFindings(
9
+ workflow: WorkflowContext,
10
+ repo: MovedRepo,
11
+ ): RuleFinding[] {
12
+ const isPR = workflow.path.endsWith('/pr.yml');
13
+
14
+ if (!isPR && !workflow.path.endsWith('/main.yml')) {
15
+ return [];
16
+ }
17
+
18
+ const onLine = getTopLevelLine(workflow.lines, 'on');
19
+ const on = findMember(workflow.workflow, 'on');
20
+
21
+ const triggerFindings = [...workflow.triggers].flatMap((event) => {
22
+ const filter = ['paths', 'paths-ignore'].find(
23
+ (key) => findMember(findMember(on, event), key) !== undefined,
24
+ );
25
+
26
+ return filter === undefined
27
+ ? []
28
+ : [
29
+ buildRuleFinding(
30
+ 'path-filter',
31
+ onLine,
32
+ `on.${event}.${filter} filters the workflow by files; remove it, and let paths-changed.yml or pick-tests.yml skip jobs by their files`,
33
+ [onLine],
34
+ ),
35
+ ];
36
+ });
37
+
38
+ const jobFindings = isPR
39
+ ? workflow.jobs.flatMap((job) => {
40
+ const filter = findFileFilter(job, repo.move);
41
+
42
+ return filter === undefined
43
+ ? []
44
+ : [
45
+ buildRuleFinding(
46
+ 'path-filter',
47
+ job.line,
48
+ `job ${job.id} skips on its files with ${filter}; call paths-changed.yml instead, so every repo skips the same way`,
49
+ [job.line],
50
+ ),
51
+ ];
52
+ })
53
+ : [];
54
+
55
+ return [...triggerFindings, ...jobFindings];
56
+ }