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 ccc0ad5 commit fec1e41
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 214 deletions.
35 changes: 35 additions & 0 deletions .github/actions/build-and-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Build and Cache'
description: 'Build n8n and cache all the dist folders'
inputs:
buildTarget:
type: choice
default: 'build'
options:
- build
- build:backend
cacheKey:
description: 'Cache key for modules and build artifacts'
required: true
type: string

runs:
using: 'composite'
steps:
- run: corepack enable
shell: bash

- uses: actions/setup-node@v4.0.1
with:
node-version: 18.x
cache: pnpm

- run: pnpm install --frozen-lockfile
shell: bash

- run: pnpm ${{ inputs.buildTarget }}
shell: bash

- uses: actions/cache/save@v4.0.0
with:
path: ./packages/**/dist
key: ${{ inputs.cacheKey }}
32 changes: 32 additions & 0 deletions .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'Lint'
description: 'Restore the dist folders from cache, and run linting'
inputs:
cacheKey:
description: 'Cache key to restore build artifacts from'
required: true
type: string

runs:
using: 'composite'
strategy:
matrix:
group: [backend, frontend, nodes]
steps:
- run: corepack enable
shell: bash

- uses: actions/setup-node@v4.0.1
with:
node-version: 18.x
cache: pnpm

- run: pnpm install --frozen-lockfile
shell: bash

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

- run: pnpm lint:${{ matrix.group }}
shell: bash
49 changes: 49 additions & 0 deletions .github/actions/unit-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: 'Unit tests'
description: 'Restore the dist folders from cache, and run tests'
inputs:
cacheKey:
description: 'Cache key to restore build artifacts from'
required: true
type: string
nodeVersion:
description: 'Version of node to use.'
required: false
type: string
default: '18.x'
collectCoverage:
required: false
type: string
default: 'false'

runs:
using: 'composite'
strategy:
matrix:
group: [backend, frontend, nodes]
steps:
- run: corepack enable
shell: bash

- uses: actions/setup-node@v4.0.1
with:
node-version: ${{ inputs.nodeVersion }}
cache: pnpm

- run: pnpm install --frozen-lockfile
shell: bash

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

- run: pnpm test:${{ matrix.group }}
shell: bash
env:
COVERAGE_ENABLED: ${{ inputs.collectCoverage }}

- uses: actions/cache/save@v4.0.0
if: ${{ inputs.collectCoverage == 'true' }}
with:
path: ./packages/**/coverage
key: ${{ inputs.cacheKey }}:${{ matrix.group }}:coverage
119 changes: 57 additions & 62 deletions .github/workflows/ci-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,88 +6,59 @@ on:
- master

jobs:
install-and-build:
build:
name: 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

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

unit-test:
name: Unit tests
uses: ./.github/workflows/units-tests-reusable.yml
needs: install-and-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
collectCoverage: true

lint:
name: Lint changes
runs-on: ubuntu-latest
needs: install-and-build
strategy:
matrix:
node-version: [18.x, 20.x]
needs: build
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
ref: ${{ github.sha }}
- uses: ./.github/actions/unit-tests
with:
node-version: ${{ matrix.node-version }}
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile
cacheKey: ${{ github.sha }}:build
collectCoverage: true

- name: Restore cached build artifacts
uses: actions/cache/restore@v4.0.0
unit-test-node-20:
name: Unit tests (Node 20)
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4.1.1
with:
path: ./packages/**/dist
key: ${{ github.sha }}-base:${{ matrix.node-version }}-test-lint
ref: ${{ github.sha }}
- uses: ./.github/actions/unit-tests
with:
cacheKey: ${{ github.sha }}:build
nodeVersion: 20.x

- name: Lint
env:
CI_LINT_MASTER: true
run: pnpm lint
lint:
name: Lint
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4.1.1
with:
ref: ${{ github.sha }}
- uses: ./.github/actions/lint
with:
cacheKey: ${{ github.sha }}:build

notify-on-failure:
name: Notify Slack on failure
runs-on: ubuntu-latest
needs: [unit-test, lint]
needs: [unit-test, unit-test-node-20, lint]
steps:
- name: Notify Slack on failure
uses: act10ns/slack@v2.0.0
Expand All @@ -97,3 +68,27 @@ jobs:
channel: '#alerts-build'
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
message: Master branch (build or test or lint) failed (${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})

upload-coverage:
name: Upload Coverage
runs-on: ubuntu-latest
needs: unit-test
steps:
- uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/coverage
key: ${{ github.sha }}:build:backend:coverage
- uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/coverage
key: ${{ github.sha }}:build:frontend:coverage
- uses: actions/cache/restore@v4.0.0
with:
path: ./packages/**/coverage
key: ${{ github.sha }}:build:nodes:coverage
- run: ls -R packages
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.0.1
with:
files: packages/**/coverage/cobertura-coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
23 changes: 7 additions & 16 deletions .github/workflows/ci-postgres-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,16 @@ concurrency:

jobs:
build:
name: Install & Build
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.1
- run: corepack enable
- uses: actions/setup-node@v4.0.1
with:
node-version: 18.x
cache: 'pnpm'
- run: pnpm install --frozen-lockfile

- name: Build Backend
run: pnpm build:backend

- name: Cache build artifacts
uses: actions/cache/save@v4.0.0
ref: ${{ github.sha }}
- uses: ./.github/actions/build-and-cache
with:
path: ./packages/**/dist
key: ${{ github.sha }}:db-tests
buildTarget: build:backend
cacheKey: ${{ github.sha }}:build:backend

mysql:
name: MySQL
Expand All @@ -54,7 +45,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 +78,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
Loading

0 comments on commit fec1e41

Please sign in to comment.