Repository navigation
ci(a11y): the contract job also runs the specs of components that import a touched module from Core's hooks/ or utils/ #14261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
01934eb
8694e65
41f4e25
938488c
f4de90f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,12 +43,14 @@ | |
| * | ||
| * `--changed-only <specs> --changed-files <files> --owned-by <components> | ||
| * [--dependents-of <folders>]` (the default check of the components a pull | ||
| * request touches, a wide change included): run the browser specs the pull | ||
| * request touches, a wide change included; `--shared-modules <files>` adds the | ||
| * touched shared hooks and utils, `SHARED_MODULE`): run the browser specs the pull | ||
| * request adds or modifies, listed one per line in <specs>, then the `scoped` | ||
| * and `release-only` specs that the comma-separated touched components own | ||
| * (`ownedSpecs`; <files> lists every changed path, one per line, for the | ||
| * folder-change rule), then the `scoped` and `release-only` specs of the | ||
| * component folders that render a touched folder (`dependentSpecs`, nearest | ||
| * component folders that render a touched folder or import a touched shared | ||
| * module (`dependentSpecs`, nearest | ||
| * first), in the time left. It reads no title and runs no component audit; a | ||
| * changed `audit` spec still waits for its audit pull request. To stay inside the job's 15-minute budget | ||
| * it takes at most CHANGED_SPEC_LIMIT changed files, starts each file only | ||
|
|
@@ -604,26 +606,74 @@ export function importerGraph(root) { | |
| } | ||
|
|
||
| /** | ||
| * The component folders that render a touched folder, nearest first, then in | ||
| * path order. A step from one component folder into another counts one; | ||
| * steps inside a folder or through shared files count none. | ||
| * The component folders that render a touched folder, or that import a | ||
| * touched shared module (a hook or util, `SHARED_MODULE`), nearest first, then | ||
| * in path order. A step from one component folder into another, or from a | ||
| * shared module into a component folder, counts one; steps inside a folder or | ||
| * through shared files count none. `via` says which seed reached the folder at | ||
| * its depth: `component` before `shared` when both do. | ||
| * @param {Map<string, Set<string>>} importers | ||
| * @param {string[]} touched `<pkg>/<Folder>` | ||
| * @returns {{folder: string, depth: number}[]} | ||
| * @param {string[]} [shared] touched shared module files | ||
| * @returns {{folder: string, depth: number, via: 'component' | 'shared'}[]} | ||
| */ | ||
| export function renderingFolders(importers, touched) { | ||
| export function renderingFolders(importers, touched, shared = []) { | ||
| const byComponent = seededFolders(importers, touched, null); | ||
| const byShared = | ||
| shared.length > 0 | ||
| ? seededFolders(importers, touched, new Set(shared)) | ||
| : new Map(); | ||
| const folders = new Map(); | ||
| for (const [folder, d] of byComponent) | ||
| folders.set(folder, {folder, depth: d, via: 'component'}); | ||
| for (const [folder, d] of byShared) | ||
| if (!folders.has(folder) || folders.get(folder).depth > d) | ||
| folders.set(folder, {folder, depth: d, via: 'shared'}); | ||
| return [...folders.values()].sort( | ||
| (a, b) => a.depth - b.depth || a.folder.localeCompare(b.folder), | ||
| ); | ||
| } | ||
|
|
||
| /** A changed file that is a shared hook or util Core's components import. */ | ||
| export const SHARED_MODULE = /^packages\/core\/src\/(?:hooks|utils)\//; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rule takes only |
||
|
|
||
| /** | ||
| * The changed shared hooks and utils (`SHARED_MODULE`) that can put code on a | ||
| * page: never a test, story, doc, spec or type declaration. The touched step | ||
| * reads it for its `contract_shared` output, and `--shared-modules` keeps only | ||
| * these. | ||
| * @param {string[]} files | ||
| */ | ||
| export function sharedModules(files) { | ||
| return files.filter( | ||
| file => SHARED_MODULE.test(file) && isRenderedSource(file), | ||
|
astracat-bot[bot] marked this conversation as resolved.
Resolved
|
||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Each component folder outside `touched` that the seeds reach, at its least | ||
| * depth. The seeds are the files of the touched folders, or, with `seeds`, | ||
| * those files only. | ||
| * @param {Map<string, Set<string>>} importers | ||
| * @param {string[]} touched | ||
| * @param {Set<string> | null} seeds | ||
| * @returns {Map<string, number>} | ||
| */ | ||
| function seededFolders(importers, touched, seeds) { | ||
| const touchedSet = new Set(touched); | ||
| const isSeed = file => | ||
| seeds ? seeds.has(file) : touchedSet.has(componentFolderOf(file)); | ||
| const depth = new Map(); | ||
| const deque = []; | ||
| for (const file of importers.keys()) { | ||
| if (touchedSet.has(componentFolderOf(file))) { | ||
| if (isSeed(file)) { | ||
| depth.set(file, 0); | ||
| deque.push(file); | ||
| } | ||
| } | ||
| for (const [, set] of importers) { | ||
| for (const file of set) { | ||
| if (touchedSet.has(componentFolderOf(file)) && !depth.has(file)) { | ||
| if (isSeed(file) && !depth.has(file)) { | ||
| depth.set(file, 0); | ||
| deque.push(file); | ||
| } | ||
|
|
@@ -650,9 +700,7 @@ export function renderingFolders(importers, touched) { | |
| if (!folder || touchedSet.has(folder)) continue; | ||
| if (!folders.has(folder) || folders.get(folder) > d) folders.set(folder, d); | ||
| } | ||
| return [...folders] | ||
| .map(([folder, d]) => ({folder, depth: d})) | ||
| .sort((a, b) => a.depth - b.depth || a.folder.localeCompare(b.folder)); | ||
| return folders; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -754,6 +802,7 @@ export function proofImporters({ | |
| */ | ||
| export function dependentSpecs(specs, rendering, planned) { | ||
| const depthOf = new Map(rendering.map(({folder, depth}) => [folder, depth])); | ||
| const viaOf = new Map(rendering.map(({folder, via}) => [folder, via])); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: the JSDoc above (797-800) still says "the component folders that render a touched folder" and types |
||
| const folderOf = file => { | ||
| const match = /^packages\/([^/]+)\/src\/([^/]+)\//.exec(file); | ||
| return match ? `${match[1]}/${match[2]}` : null; | ||
|
|
@@ -765,11 +814,15 @@ export function dependentSpecs(specs, rendering, planned) { | |
| !planned.has(file) && | ||
| depthOf.has(folderOf(file)), | ||
| ) | ||
| .map(({file}) => ({file, depth: depthOf.get(folderOf(file))})) | ||
| .map(({file}) => ({ | ||
| file, | ||
| depth: depthOf.get(folderOf(file)), | ||
| via: viaOf.get(folderOf(file)), | ||
| })) | ||
| .sort((a, b) => a.depth - b.depth || a.file.localeCompare(b.file)) | ||
| .map(({file, depth}) => ({ | ||
| .map(({file, depth, via}) => ({ | ||
| file, | ||
| reason: `renders a touched component${depth > 1 ? ` (${depth} folders away)` : ''}`, | ||
| reason: `${via === 'shared' ? 'imports a touched shared hook or util' : 'renders a touched component'}${depth > 1 ? ` (${depth} folders away)` : ''}`, | ||
| })); | ||
| } | ||
|
|
||
|
|
@@ -939,7 +992,7 @@ export function planDefaultCheck({ | |
| withFile => | ||
| projectedMs(withFile, msOf, workers) - beforeDependents <= | ||
| dependentShareMs, | ||
| `${dependentShareMs / 60000}-minute share for folders that render a touched component`, | ||
| `${dependentShareMs / 60000}-minute share for folders that render a touched component or import a touched shared hook or util`, | ||
| ); | ||
| } | ||
| return {run, notRun}; | ||
|
|
@@ -965,7 +1018,7 @@ export function summaryMarkdown({ | |
| if (rendering.length) { | ||
| lines.push( | ||
| '', | ||
| `Folders that render a touched component: ${rendering.length}; their specs run, nearest first, within ${DEPENDENT_SHARE_MS === 60 * 1000 ? 'one minute' : `${DEPENDENT_SHARE_MS / 60000} minutes`} of the time left.`, | ||
| `Folders that render a touched component or import a touched shared hook or util: ${rendering.length}; their specs run, nearest first, within ${DEPENDENT_SHARE_MS === 60 * 1000 ? 'one minute' : `${DEPENDENT_SHARE_MS / 60000} minutes`} of the time left.`, | ||
| ); | ||
| } | ||
| lines.push(''); | ||
|
|
@@ -1220,6 +1273,10 @@ function main() { | |
| const ownedBy = (ownedByValue ?? '').split(',').filter(Boolean); | ||
| const dependentsOfValue = flagValue(argv, '--dependents-of'); | ||
| const dependentsOf = (dependentsOfValue ?? '').split(',').filter(Boolean); | ||
| const sharedModulesValue = flagValue(argv, '--shared-modules'); | ||
| const sharedModuleFiles = sharedModules( | ||
| (sharedModulesValue ?? '').split(',').filter(Boolean), | ||
| ); | ||
| const countLegsValue = flagValue(argv, '--count-legs'); | ||
| const legValue = flagValue(argv, '--leg'); | ||
| const ofValue = flagValue(argv, '--of'); | ||
|
|
@@ -1234,11 +1291,12 @@ function main() { | |
| if ( | ||
| (ownedByValue != null || | ||
| changedFilesFile != null || | ||
| dependentsOfValue != null) && | ||
| dependentsOfValue != null || | ||
| sharedModulesValue != null) && | ||
| changedOnlyFile == null | ||
| ) { | ||
| throw new Error( | ||
| '--owned-by, --changed-files and --dependents-of need --changed-only', | ||
| '--owned-by, --changed-files, --dependents-of and --shared-modules need --changed-only', | ||
| ); | ||
| } | ||
| // Without every changed path the folder rule selects nothing, and the | ||
|
|
@@ -1253,6 +1311,7 @@ function main() { | |
| changedFilesFile, | ||
| ownedByValue, | ||
| dependentsOfValue, | ||
| sharedModulesValue, | ||
| countLegsValue, | ||
| legValue, | ||
| ofValue, | ||
|
|
@@ -1290,8 +1349,9 @@ function main() { | |
| title, | ||
| }); | ||
| const rendering = | ||
| changedOnlyFile != null && dependentsOf.length > 0 | ||
| ? renderingFolders(importerGraph(root), dependentsOf) | ||
| changedOnlyFile != null && | ||
| (dependentsOf.length > 0 || sharedModuleFiles.length > 0) | ||
| ? renderingFolders(importerGraph(root), dependentsOf, sharedModuleFiles) | ||
| : []; | ||
| const budgeted = (() => { | ||
| if (changedOnlyFile == null) return {run: routed, notRun: []}; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.