Skip to content

Commit

Permalink
ci: optimize ci time with some perks 😈 (#2865)
Browse files Browse the repository at this point in the history
<img width="219" alt="image" src="https://github.com/dailydotdev/apps/assets/1993245/5e738ae8-b09d-451f-a76c-0ade3671b01b">

* I managed to reduce CI time by 73% to a ridicules time of 2.5min! âš¡ 
* Thanks to @rebelchris I learned about the ["Rerun failed tests"](https://circleci.com/docs/rerun-failed-tests/) feature. So you can rerun only failed tests now if needed 🤩 
* Parallel support in case we get more tests per project, we can easily spool up more workers per project

The essence of the change is that each package's CI now runs independently. In addition since the shared package lint takes time, I moved it to its own process to run it in parallel with the tests.

It's about time we get a better feedback loop. Enjoy!

eslint timing breakdown:
![image](https://github.com/dailydotdev/apps/assets/1993245/ee85d3ed-1b82-4451-b3df-c70fc0bbf5f9)
  • Loading branch information
idoshamun committed Mar 27, 2024
1 parent afaf52a commit 932be03
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 27 deletions.
108 changes: 87 additions & 21 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
version: 2.1

jobs:
build:
install_deps:
docker:
- image: cimg/node:18.16.0
resource_class: medium+
steps:
- checkout
- run:
Expand All @@ -27,45 +26,112 @@ jobs:
- ./packages/shared/node_modules
- ./packages/webapp/node_modules
- ./packages/extension/node_modules
build:
docker:
- image: cimg/node:18.16.0
resource_class: medium+
steps:
- checkout
- restore_cache:
keys:
- deps-v6-{{ checksum "pnpm-lock.yaml" }}
- deps-v6-{{ .Branch }}
- run:
name: Build
command: npm run build:chrome
working_directory: packages/extension
test:
test_extension:
docker:
- image: cimg/node:18.16.0
resource_class: medium+
parallelism: 1
steps:
- checkout
- restore_cache:
keys:
- deps-v6-{{ checksum "pnpm-lock.yaml" }}
- deps-v6-{{ .Branch }}
- run:
name: Install pnpm
command: npm i --prefix=$HOME/.local -g pnpm
name: Test
command: |
npm run pretest
TEST=$(./node_modules/.bin/jest --listTests)
echo $TEST | circleci tests run --command="xargs ./node_modules/.bin/jest --ci --runInBand --reporters=default --reporters=jest-junit --" --split-by=timings
environment:
JEST_JUNIT_OUTPUT_DIR: ../../test-results
working_directory: packages/extension
- store_test_results:
path: ./test-results
test_webapp:
docker:
- image: cimg/node:18.16.0
parallelism: 1
steps:
- checkout
- restore_cache:
keys:
- deps-v6-{{ checksum "pnpm-lock.yaml" }}
- deps-v6-{{ .Branch }}
- run:
name: Install dependencies
command: pnpm install
- save_cache:
key: deps-v6-{{ checksum "pnpm-lock.yaml" }}
paths:
- ./node_modules
- ./packages/eslint-config/node_modules
- ./packages/eslint-rules/node_modules
- ./packages/prettier-config/node_modules
- ./packages/shared/node_modules
- ./packages/webapp/node_modules
- ./packages/extension/node_modules
name: Test
command: |
npm run pretest
TEST=$(./node_modules/.bin/jest --listTests)
echo $TEST | circleci tests run --command="xargs ./node_modules/.bin/jest --ci --runInBand --reporters=default --reporters=jest-junit --" --split-by=timings
environment:
JEST_JUNIT_OUTPUT_DIR: ../../test-results
working_directory: packages/webapp
- store_test_results:
path: ./test-results
lint_shared:
docker:
- image: cimg/node:18.16.0
resource_class: large
steps:
- checkout
- restore_cache:
keys:
- deps-v6-{{ checksum "pnpm-lock.yaml" }}
- deps-v6-{{ .Branch }}
- run:
name: Lint
command: npm run pretest
working_directory: packages/shared
test_shared:
docker:
- image: cimg/node:18.16.0
parallelism: 1
steps:
- checkout
- restore_cache:
keys:
- deps-v6-{{ checksum "pnpm-lock.yaml" }}
- deps-v6-{{ .Branch }}
- run:
name: Test
command: pnpm run -r test:ci
command: |
TEST=$(./node_modules/.bin/jest --listTests)
echo $TEST | circleci tests run --command="xargs ./node_modules/.bin/jest --ci --runInBand --reporters=default --reporters=jest-junit --" --split-by=timings
environment:
JEST_JUNIT_OUTPUT_DIR: ../../test-results
working_directory: packages/shared
- store_test_results:
path: ./test-results
workflows:
build:
jobs:
- build
- test
- install_deps
- build:
requires:
- install_deps
- test_extension:
requires:
- install_deps
- test_webapp:
requires:
- install_deps
- lint_shared:
requires:
- install_deps
- test_shared:
requires:
- install_deps
1 change: 1 addition & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
},
rules: {
curly: ['error', 'all'],
'import/no-cycle': ['error', {ignoreExternal: false, maxDepth: 3}],
'react/prop-types': 0,
'react/require-default-props': 0,
'react/no-unused-prop-types': 0,
Expand Down
3 changes: 1 addition & 2 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0 --fix",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0",
"pretest": "npm run lint",
"test": "node --expose-gc ./node_modules/jest/bin/jest.js --logHeapUsage",
"test:ci": "JEST_JUNIT_OUTPUT_NAME=extension.xml npm run test -- --ci --reporters=default --reporters=jest-junit --runInBand"
"test": "jest --runInBand"
},
"prettier": "@dailydotdev/prettier-config",
"dependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix --max-warnings 0",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0",
"pretest": "npm run lint",
"test": "node --expose-gc ./node_modules/jest/bin/jest.js --logHeapUsage",
"test:ci": "JEST_JUNIT_OUTPUT_NAME=shared.xml npm run test -- --ci --reporters=default --reporters=jest-junit --runInBand"
"test": "jest --runInBand"
},
"prettier": "@dailydotdev/prettier-config",
"peerDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0 --fix",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0",
"pretest": "npm run lint",
"test": "node --expose-gc ./node_modules/jest/bin/jest.js --logHeapUsage",
"test:ci": "JEST_JUNIT_OUTPUT_NAME=webapp.xml npm run test -- --ci --reporters=default --reporters=jest-junit --runInBand",
"test": "jest --runInBand",
"deploy": "vercel"
},
"prettier": "@dailydotdev/prettier-config",
Expand Down

0 comments on commit 932be03

Please sign in to comment.