From 2f665683fc9295c7fb98d2ba3807e489b33f83d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Tue, 7 Nov 2023 14:19:39 +0100 Subject: [PATCH] ci: Improve CI performance (no-changelog) (#7637) 1. Split backend and frontend tests to avoid them running in parallel 2. Enable coverage only on `master` --- .github/workflows/ci-master.yml | 3 +- .github/workflows/units-tests-reusable.yml | 14 ++++++-- jest.config.js | 2 +- package.json | 4 +++ packages/design-system/package.json | 2 +- packages/design-system/vite.config.ts | 41 ++++++++++++---------- packages/editor-ui/package.json | 2 +- packages/editor-ui/vite.config.ts | 22 ++---------- 8 files changed, 46 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml index 1c76725066..1bbdd4df1a 100644 --- a/.github/workflows/ci-master.yml +++ b/.github/workflows/ci-master.yml @@ -48,7 +48,8 @@ jobs: with: ref: ${{ inputs.branch }} nodeVersion: ${{ matrix.node-version }} - cacheKey: ${{ github.sha }}-base:${{ matrix.node-version }}-test-lint + cacheKey: ${{ github.sha }}-base:${{ matrix.node-version }}-test-lint + collectCoverage: true lint: name: Lint changes diff --git a/.github/workflows/units-tests-reusable.yml b/.github/workflows/units-tests-reusable.yml index 508ec7d019..eb180f65cb 100644 --- a/.github/workflows/units-tests-reusable.yml +++ b/.github/workflows/units-tests-reusable.yml @@ -18,11 +18,17 @@ on: required: false default: '' type: string + collectCoverage: + required: false + default: 'false' + type: string jobs: unit-test: name: Unit tests runs-on: ubuntu-latest + env: + COVERAGE_ENABLED: ${{ inputs.collectCoverage }} steps: - uses: actions/checkout@v3.5.3 with: @@ -51,10 +57,14 @@ jobs: path: ./packages/**/dist key: ${{ inputs.cacheKey }} - - name: Test - run: pnpm test + - name: Test Backend + run: pnpm test:backend + + - name: Test Frontend + run: pnpm test:frontend - name: Upload coverage to Codecov + if: ${{ inputs.collectCoverage == 'true' }} uses: codecov/codecov-action@v3 with: files: packages/@n8n/client-oauth2/coverage/cobertura-coverage.xml,packages/cli/coverage/cobertura-coverage.xml,packages/core/coverage/cobertura-coverage.xml,packages/design-system/coverage/cobertura-coverage.xml,packages/editor-ui/coverage/cobertura-coverage.xml,packages/nodes-base/coverage/cobertura-coverage.xml,packages/workflow/coverage/cobertura-coverage.xml diff --git a/jest.config.js b/jest.config.js index a4c416f152..26cb6e53bd 100644 --- a/jest.config.js +++ b/jest.config.js @@ -30,7 +30,7 @@ const config = { return acc; }, {}), setupFilesAfterEnv: ['jest-expect-message'], - collectCoverage: true, + collectCoverage: process.env.COVERAGE_ENABLED === 'true', coverageReporters: [process.env.COVERAGE_REPORT === 'true' ? 'text' : 'text-summary'], collectCoverageFrom: ['src/**/*.ts'], }; diff --git a/package.json b/package.json index fe47fc2f70..a30b9f9b11 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ "scripts": { "preinstall": "node scripts/block-npm-install.js", "build": "turbo run build", + "build:backend": "pnpm --filter=!n8n-design-system --filter=!n8n-editor-ui build", + "build:frontend": "pnpm --filter=n8n-design-system --filter=n8n-editor-ui build", "typecheck": "turbo run typecheck", "dev": "turbo run dev --parallel", "clean": "turbo run clean --parallel", @@ -23,6 +25,8 @@ "start:tunnel": "./packages/cli/bin/n8n start --tunnel", "start:windows": "cd packages/cli/bin && n8n", "test": "turbo run test", + "test:backend": "pnpm --filter=!n8n-design-system --filter=!n8n-editor-ui test", + "test:frontend": "pnpm --filter=n8n-design-system --filter=n8n-editor-ui test", "watch": "turbo run watch", "webhook": "./packages/cli/bin/n8n webhook", "worker": "./packages/cli/bin/n8n worker", diff --git a/packages/design-system/package.json b/packages/design-system/package.json index 5cc3dd63ee..964489e64b 100644 --- a/packages/design-system/package.json +++ b/packages/design-system/package.json @@ -17,7 +17,7 @@ "clean": "rimraf dist .turbo", "build": "vite build", "typecheck": "vue-tsc --declaration --emitDeclarationOnly", - "test": "vitest run --coverage", + "test": "vitest run", "test:dev": "vitest", "build:storybook": "storybook build", "storybook": "storybook dev -p 6006", diff --git a/packages/design-system/vite.config.ts b/packages/design-system/vite.config.ts index 0f62568a14..62fc735255 100644 --- a/packages/design-system/vite.config.ts +++ b/packages/design-system/vite.config.ts @@ -1,9 +1,30 @@ import vue from '@vitejs/plugin-vue'; import { resolve } from 'path'; import { defineConfig, mergeConfig } from 'vite'; +import { type UserConfig } from 'vitest'; import { defineConfig as defineVitestConfig } from 'vitest/config'; -const { coverageReporters } = require('../../jest.config.js'); +export const vitestConfig = defineVitestConfig({ + test: { + globals: true, + environment: 'jsdom', + setupFiles: ['./src/__tests__/setup.ts'], + ...(process.env.COVERAGE_ENABLED === 'true' + ? { + coverage: { + provider: 'v8', + reporter: require('../../jest.config.js').coverageReporters, + all: true, + }, + } + : {}), + css: { + modules: { + classNameStrategy: 'non-scoped', + }, + }, + }, +}) as UserConfig; export default mergeConfig( defineConfig({ @@ -35,21 +56,5 @@ export default mergeConfig( }, }, }), - defineVitestConfig({ - test: { - globals: true, - environment: 'jsdom', - setupFiles: ['./src/__tests__/setup.ts'], - coverage: { - provider: 'v8', - reporter: coverageReporters, - all: true, - }, - css: { - modules: { - classNameStrategy: 'non-scoped', - }, - }, - }, - }), + vitestConfig, ); diff --git a/packages/editor-ui/package.json b/packages/editor-ui/package.json index 6f23a8e11c..bb1db23f80 100644 --- a/packages/editor-ui/package.json +++ b/packages/editor-ui/package.json @@ -22,7 +22,7 @@ "lintfix": "eslint src --ext .js,.ts,.vue --fix", "format": "prettier --write . --ignore-path ../../.prettierignore", "serve": "cross-env VUE_APP_URL_BASE_API=http://localhost:5678/ vite --host 0.0.0.0 --port 8080 dev", - "test": "vitest run --coverage", + "test": "vitest run", "test:dev": "vitest" }, "dependencies": { diff --git a/packages/editor-ui/vite.config.ts b/packages/editor-ui/vite.config.ts index 34ce3cd51d..be95672247 100644 --- a/packages/editor-ui/vite.config.ts +++ b/packages/editor-ui/vite.config.ts @@ -1,12 +1,10 @@ import vue from '@vitejs/plugin-vue'; import { resolve } from 'path'; import { defineConfig, mergeConfig } from 'vite'; -import { defineConfig as defineVitestConfig } from 'vitest/config'; import { sentryVitePlugin } from '@sentry/vite-plugin'; import packageJSON from './package.json'; - -const { coverageReporters } = require('../../jest.config.js'); +import { vitestConfig } from '../design-system/vite.config'; const vendorChunks = ['vue', 'vue-router']; const n8nChunks = ['n8n-workflow', 'n8n-design-system']; @@ -115,21 +113,5 @@ export default mergeConfig( }, }, }), - defineVitestConfig({ - test: { - globals: true, - environment: 'jsdom', - setupFiles: ['./src/__tests__/setup.ts'], - coverage: { - provider: 'v8', - reporter: coverageReporters, - all: true, - }, - css: { - modules: { - classNameStrategy: 'non-scoped', - }, - }, - }, - }), + vitestConfig, );