alveifbklsiu259 opened a new pull request, #32323:
URL: https://github.com/apache/superset/pull/32323
ci(type-checking): run type-checking-frontend hook sequentially
### SUMMARY
Run `type-checking-frontend` hook sequentially by setting `require_serial:
true`.
By default, pre-commit runs each hook in parallel with different set of
matched files:
`pre-commit-config.yaml`
```yaml
- id: type-checking-frontend
name: Type-Checking (Frontend)
entry: ./scripts/check-type.js
language: node
files: ^superset-frontend\/.*\.(js|jsx|ts|tsx)$
exclude: ^superset-frontend/cypress-base\/
```
`check-type.js`
```js
void (async () => {
const args = process.argv.slice(2);
console.log("the script is run with the args:", args);
exit(1);
}
```
```shell
git status
On branch ci/type-checking
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: .pre-commit-config.yaml
modified: scripts/check-type.js
modified: superset-frontend/package-lock.json
modified: superset-frontend/src/dashboard/actions/dashboardInfo.ts
modified: superset-frontend/src/dashboard/actions/datasources.ts
modified: superset-frontend/src/dashboard/actions/nativeFilters.ts
modified: superset-frontend/src/dashboard/actions/sliceEntities.ts
modified:
superset-frontend/src/dashboard/components/AddSliceCard/AddSliceCard.test.tsx
modified:
superset-frontend/src/dashboard/components/AddSliceCard/AddSliceCard.tsx
modified:
superset-frontend/src/dashboard/components/AddSliceCard/index.ts
modified:
superset-frontend/src/dashboard/components/AnchorLink/AnchorLink.stories.tsx
modified:
superset-frontend/src/dashboard/components/AnchorLink/AnchorLink.test.tsx
modified:
superset-frontend/src/dashboard/components/AnchorLink/index.tsx
modified:
superset-frontend/src/dashboard/components/BuilderComponentPane/BuilderComponentPane.test.tsx
modified:
superset-frontend/src/dashboard/components/BuilderComponentPane/index.tsx
modified:
superset-frontend/src/dashboard/components/CssEditor/index.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardContainer.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardWrapper.test.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardWrapper.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/state.ts
modified:
superset-frontend/src/explore/actions/datasourcesActions.ts
modified:
superset-frontend/src/explore/components/controls/ViewQuery.tsx
new file: superset-frontend/src/types/jest-styled-components.d.ts
modified: superset-frontend/tsconfig.json
```
The script is run **6** times. Which means that `tsc` will be run 6 times.
```shell
pre-commit run type-checking-frontend
run type-checking-frontend
Type-Checking
(Frontend).................................................Failed
- hook id: type-checking-frontend
- exit code: 1
the script is run with the args: [
'superset-frontend/src/dashboard/components/AddSliceCard/AddSliceCard.test.tsx',
'superset-frontend/src/dashboard/components/AddSliceCard/AddSliceCard.tsx',
'superset-frontend/src/dashboard/components/AnchorLink/AnchorLink.stories.tsx',
'superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx'
]
the script is run with the args: [
'superset-frontend/src/dashboard/components/CssEditor/index.tsx',
'superset-frontend/src/dashboard/actions/dashboardInfo.ts',
'superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx',
'superset-frontend/src/dashboard/components/BuilderComponentPane/index.tsx'
]
the script is run with the args: [
'superset-frontend/src/dashboard/components/AnchorLink/index.tsx',
'superset-frontend/src/dashboard/actions/datasources.ts',
'superset-frontend/src/types/jest-styled-components.d.ts',
'superset-frontend/src/dashboard/components/DashboardBuilder/DashboardWrapper.test.tsx'
]
the script is run with the args: [
'superset-frontend/src/dashboard/actions/nativeFilters.ts',
'superset-frontend/src/dashboard/components/AnchorLink/AnchorLink.test.tsx',
'superset-frontend/src/dashboard/actions/sliceEntities.ts',
'superset-frontend/src/explore/components/controls/ViewQuery.tsx'
]
the script is run with the args: [
'superset-frontend/src/dashboard/components/DashboardBuilder/DashboardWrapper.tsx',
'superset-frontend/src/dashboard/components/BuilderComponentPane/BuilderComponentPane.test.tsx',
'superset-frontend/src/dashboard/components/AddSliceCard/index.ts',
'superset-frontend/src/explore/actions/datasourcesActions.ts'
]
the script is run with the args: [
'superset-frontend/src/dashboard/components/DashboardBuilder/DashboardContainer.tsx',
'superset-frontend/src/dashboard/components/DashboardBuilder/state.ts'
]
```
**Potential issues**:
- Each invocation of `tsc` incurs a startup overhead. Running `tsc` with
different set of files multiple times in parallel may actually be slower than
running it once with all the files.
- Running `tsc` multiple times in parallel may show the same error multiple
times in the console.
`pre-commit-config.yaml`
```yaml
- id: type-checking-frontend
name: Type-Checking (Frontend)
entry: ./scripts/check-type.js
args: [package=superset-frontend, excludeDeclarationDir=cypress-base]
language: node
files: ^superset-frontend\/.*\.(js|jsx|ts|tsx)$
exclude: ^superset-frontend/cypress-base\/
```
```shell
git status
On branch ci/type-checking
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: superset-frontend/package-lock.json
modified: superset-frontend/src/dashboard/actions/dashboardInfo.ts
modified: superset-frontend/src/dashboard/actions/datasources.ts
modified: superset-frontend/src/dashboard/actions/nativeFilters.ts
modified: superset-frontend/src/dashboard/actions/sliceEntities.ts
modified:
superset-frontend/src/dashboard/components/AddSliceCard/AddSliceCard.test.tsx
modified:
superset-frontend/src/dashboard/components/AddSliceCard/AddSliceCard.tsx
modified:
superset-frontend/src/dashboard/components/AddSliceCard/index.ts
modified:
superset-frontend/src/dashboard/components/AnchorLink/AnchorLink.stories.tsx
modified:
superset-frontend/src/dashboard/components/AnchorLink/AnchorLink.test.tsx
modified:
superset-frontend/src/dashboard/components/AnchorLink/index.tsx
modified:
superset-frontend/src/dashboard/components/BuilderComponentPane/BuilderComponentPane.test.tsx
modified:
superset-frontend/src/dashboard/components/BuilderComponentPane/index.tsx
modified:
superset-frontend/src/dashboard/components/CssEditor/index.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardContainer.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardWrapper.test.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardWrapper.tsx
modified:
superset-frontend/src/dashboard/components/DashboardBuilder/state.ts
modified:
superset-frontend/src/explore/actions/datasourcesActions.ts
modified:
superset-frontend/src/explore/components/controls/ViewQuery.tsx
new file: superset-frontend/src/types/jest-styled-components.d.ts
modified: superset-frontend/tsconfig.json
```
In parallel:

Sequential:
add `require_serial: true` to `type-checking-frontend` hook

#### NOTES
- Running `pre-commit run type-checking-frontend --all-files` is slower than
running `npm run type`.


This is expected, due to command line length limits, it's not feasible to
pass all files to a single command invocation. Instead, pre-commit splits the
files into manageable chunks and processes them. (mentioned in this
[issue](https://github.com/pre-commit/pre-commit/issues/691#issuecomment-360172836))
And `superset-frontend` has over 2,000 files, running all files will cause
the hook to split the files into two chunks(according to test), and run
sequentially, which makes sense if you compare the time (1 minute and 30
seconds)
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
<!--- Skip this if not applicable -->
### TESTING INSTRUCTIONS
<!--- Required! What steps can be taken to manually verify the changes? -->
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]