Skip to content

Commit

Permalink
ci: Parallelize unit tests on the CI (no-changelog)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Feb 8, 2024
1 parent de6d466 commit 2210a05
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 142 deletions.
37 changes: 37 additions & 0 deletions .github/actions/build-n8n/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Build n8n'
description: 'Build n8n and cache the dist folder'
inputs:
ref:
description: 'GitHub ref to build'
required: true
type: string
cacheKey:
description: 'Cache key for modules and build artifacts'
required: true
type: string
nodeVersion:
description: 'Version of node to use.'
required: false
type: string
default: '18.x'

runs:
using: 'composite'
steps:
- run: corepack enable
- uses: actions/setup-node@v4.0.1
with:
node-version: ${{ inputs.nodeVersion }}
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build

- name: Cache build artifacts
uses: actions/cache/save@v4.0.0
with:
path: ./packages/**/dist
key: ${{ inputs.cacheKey }}
71 changes: 13 additions & 58 deletions .github/workflows/ci-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,83 +6,38 @@ on:
- master

jobs:
install-and-build:
build:
runs-on: ubuntu-latest

timeout-minutes: 30

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4.1.1

- run: corepack enable
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4.0.1
with:
node-version: ${{ matrix.node-version }}
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build
ref: ${{ github.sha }}

- name: Cache build artifacts
uses: actions/cache/save@v4.0.0
- uses: ./.github/actions/build-n8n
with:
path: ./packages/**/dist
key: ${{ github.sha }}-base:${{ matrix.node-version }}-test-lint
ref: ${{ github.sha }}
cacheKey: ${{ github.sha }}:build

unit-test:
name: Unit tests
uses: ./.github/workflows/units-tests-reusable.yml
needs: install-and-build
uses: ./.github/workflows/reusable-units-tests.yml
needs: build
strategy:
matrix:
node-version: [18.x, 20.x]
with:
ref: ${{ inputs.branch }}
nodeVersion: ${{ matrix.node-version }}
cacheKey: ${{ github.sha }}-base:${{ matrix.node-version }}-test-lint
cacheKey: ${{ github.sha }}:build
collectCoverage: true

lint:
name: Lint changes
runs-on: ubuntu-latest
needs: install-and-build
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v4.1.1
with:
repository: n8n-io/n8n
ref: ${{ inputs.branch }}

- run: corepack enable
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4.0.1
with:
node-version: ${{ matrix.node-version }}
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Restore cached build artifacts
uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/dist
key: ${{ github.sha }}-base:${{ matrix.node-version }}-test-lint

- name: Lint
env:
CI_LINT_MASTER: true
run: pnpm lint
uses: ./.github/workflows/reusable-linting.yml
needs: build
with:
ref: ${{ inputs.branch }}
cacheKey: ${{ github.sha }}:build

notify-on-failure:
name: Notify Slack on failure
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci-postgres-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: actions/cache/save@v4.0.0
with:
path: ./packages/**/dist
key: ${{ github.sha }}:db-tests
key: ${{ github.sha }}:build:backend

mysql:
name: MySQL
Expand All @@ -54,7 +54,7 @@ jobs:
uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/dist
key: ${{ github.sha }}:db-tests
key: ${{ github.sha }}:build:backend

- name: Start MySQL
uses: isbang/compose-action@v1.5.1
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/dist
key: ${{ github.sha }}:db-tests
key: ${{ github.sha }}:build:backend

- name: Start Postgres
uses: isbang/compose-action@v1.5.1
Expand Down
58 changes: 11 additions & 47 deletions .github/workflows/ci-pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,25 @@ jobs:
steps:
- uses: actions/checkout@v4.1.1
with:
repository: n8n-io/n8n
ref: refs/pull/${{ github.event.pull_request.number }}/merge

- run: corepack enable
- name: Use Node.js 18
uses: actions/setup-node@v4.0.1
with:
node-version: 18.x
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build
ref: ${{ github.sha }}

- name: Cache build artifacts
uses: actions/cache/save@v4.0.0
- uses: ./.github/actions/build-n8n
with:
path: ./packages/**/dist
key: ${{ github.sha }}-base:18-test-lint
ref: refs/pull/${{ github.event.pull_request.number }}/merge
cacheKey: ${{ github.sha }}:build

unit-test:
name: Unit tests
uses: ./.github/workflows/units-tests-reusable.yml
uses: ./.github/workflows/reusable-units-tests.yml
needs: install
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
cacheKey: ${{ github.sha }}-base:18-test-lint
cacheKey: ${{ github.sha }}:build

lint:
name: Lint changes
runs-on: ubuntu-latest
name: Lint
uses: ./.github/workflows/reusable-linting.yml
needs: install
steps:
- uses: actions/checkout@v4.1.1
with:
repository: n8n-io/n8n
ref: refs/pull/${{ github.event.pull_request.number }}/merge

- run: corepack enable
- name: Use Node.js 18
uses: actions/setup-node@v4.0.1
with:
node-version: 18.x
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Restore cached build artifacts
uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/dist
key: ${{ github.sha }}-base:18-test-lint

- name: Lint
run: pnpm lint
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
cacheKey: ${{ github.sha }}:build
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
jobs:
run-e2e-tests:
name: E2E [Electron/Node 18]
uses: ./.github/workflows/e2e-reusable.yml
uses: ./.github/workflows/reusable-e2e.yml
if: ${{ github.event.review.state == 'approved' && !contains(github.event.pull_request.labels.*.name, 'community') }}
with:
pr_number: ${{ github.event.pull_request.number }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

run-e2e-tests:
name: E2E [Electron/Node 18]
uses: ./.github/workflows/e2e-reusable.yml
uses: ./.github/workflows/reusable-e2e.yml
with:
branch: ${{ github.event.inputs.branch || 'master' }}
user: ${{ github.event.inputs.user || 'PR User' }}
Expand Down
File renamed without changes.
45 changes: 45 additions & 0 deletions .github/workflows/reusable-linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Reusable linting workflow

on:
workflow_call:
inputs:
ref:
description: 'GitHub ref to lint.'
required: false
type: string
default: 'master'
cacheKey:
description: 'Cache key for modules and build artifacts.'
required: true
type: string

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
group: [backend, frontend, nodes]
steps:
- uses: actions/checkout@v4.1.1
with:
repository: n8n-io/n8n
ref: ${{ inputs.ref }}

- run: corepack enable
- name: Use Node.js 18
uses: actions/setup-node@v4.0.1
with:
node-version: 18.x
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Restore cached build artifacts
uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/dist
key: ${{ inputs.cacheKey }}

- name: Lint
run: pnpm lint:${{ matrix.group }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Reusable units test workflow
name: Reusable unit-test workflow

on:
workflow_call:
Expand All @@ -15,8 +15,7 @@ on:
default: '18.x'
cacheKey:
description: 'Cache key for modules and build artifacts.'
required: false
default: ''
required: true
type: string
collectCoverage:
required: false
Expand All @@ -25,10 +24,12 @@ on:

jobs:
unit-test:
name: Unit tests
runs-on: ubuntu-latest
env:
COVERAGE_ENABLED: ${{ inputs.collectCoverage }}
strategy:
matrix:
group: [backend, frontend, nodes]
steps:
- uses: actions/checkout@v4.1.1
with:
Expand All @@ -45,28 +46,43 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
if: ${{ inputs.cacheKey == '' }}
run: pnpm build

- name: Restore cached build artifacts
if: ${{ inputs.cacheKey != '' }}
uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/dist
key: ${{ inputs.cacheKey }}

- name: Test Backend
run: pnpm test:backend

- name: Test Nodes
run: pnpm test:nodes
- name: Test
run: pnpm test:${{ matrix.group }}

- name: Test Frontend
run: pnpm test:frontend
- name: Cache Coverage
if: ${{ inputs.collectCoverage == 'true' }}
uses: actions/cache/save@v4.0.0
with:
path: ./packages/**/coverage
key: ${{ inputs.cacheKey }}:${{ matrix.group }}:coverage

upload-coverage:
name: Upload Coverage
if: ${{ inputs.collectCoverage == 'true' }}
runs-on: ubuntu-latest
needs: unit-test
steps:
- uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/coverage
key: ${{ inputs.cacheKey }}:backend:coverage
- uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/coverage
key: ${{ inputs.cacheKey }}:frontend:coverage
- uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/coverage
key: ${{ inputs.cacheKey }}:nodes:coverage
- run: ls -R packages
- name: Upload coverage to Codecov
if: ${{ inputs.collectCoverage == 'true' }}
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4.0.1
with:
files: packages/@n8n/chat/coverage/cobertura-coverage.xml,packages/@n8n/nodes-langchain/coverage/cobertura-coverage.xml,packages/@n8n/permissions/coverage/cobertura-coverage.xml,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
files: packages/**/coverage/cobertura-coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
Loading

0 comments on commit 2210a05

Please sign in to comment.