2023-09-13 06:24:02 -07:00
|
|
|
name: Reusable units test workflow
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_call:
|
|
|
|
inputs:
|
|
|
|
ref:
|
2024-06-13 04:10:51 -07:00
|
|
|
description: GitHub ref to test.
|
2023-09-13 06:24:02 -07:00
|
|
|
required: false
|
|
|
|
type: string
|
2024-06-13 04:10:51 -07:00
|
|
|
default: master
|
2023-09-13 06:24:02 -07:00
|
|
|
nodeVersion:
|
2024-06-13 04:10:51 -07:00
|
|
|
description: Version of node to use.
|
2023-09-13 06:24:02 -07:00
|
|
|
required: false
|
|
|
|
type: string
|
2024-05-24 03:32:50 -07:00
|
|
|
default: 20.x
|
2023-09-13 06:24:02 -07:00
|
|
|
cacheKey:
|
2024-06-13 04:10:51 -07:00
|
|
|
description: Cache key for modules and build artifacts.
|
2023-09-13 06:24:02 -07:00
|
|
|
required: false
|
|
|
|
default: ''
|
|
|
|
type: string
|
2023-11-07 05:19:39 -08:00
|
|
|
collectCoverage:
|
|
|
|
required: false
|
2024-06-13 04:10:51 -07:00
|
|
|
default: false
|
|
|
|
type: boolean
|
2024-07-03 01:37:04 -07:00
|
|
|
secrets:
|
|
|
|
CODECOV_TOKEN:
|
|
|
|
description: 'Codecov upload token.'
|
|
|
|
required: false
|
2023-09-13 06:24:02 -07:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
unit-test:
|
|
|
|
name: Unit tests
|
|
|
|
runs-on: ubuntu-latest
|
2023-11-07 05:19:39 -08:00
|
|
|
env:
|
|
|
|
COVERAGE_ENABLED: ${{ inputs.collectCoverage }}
|
2023-09-13 06:24:02 -07:00
|
|
|
steps:
|
2024-01-26 02:26:30 -08:00
|
|
|
- uses: actions/checkout@v4.1.1
|
2023-09-13 06:24:02 -07:00
|
|
|
with:
|
|
|
|
repository: n8n-io/n8n
|
|
|
|
ref: ${{ inputs.ref }}
|
|
|
|
|
2024-02-02 00:47:58 -08:00
|
|
|
- run: corepack enable
|
2023-09-13 06:24:02 -07:00
|
|
|
- name: Use Node.js ${{ inputs.nodeVersion }}
|
2024-05-24 03:32:50 -07:00
|
|
|
uses: actions/setup-node@v4.0.2
|
2023-09-13 06:24:02 -07:00
|
|
|
with:
|
|
|
|
node-version: ${{ inputs.nodeVersion }}
|
|
|
|
cache: pnpm
|
|
|
|
|
|
|
|
- name: Install dependencies
|
|
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
|
2024-07-05 08:43:52 -07:00
|
|
|
- name: Setup build cache
|
2024-08-13 05:44:36 -07:00
|
|
|
if: inputs.collectCoverage != true
|
2024-07-05 08:43:52 -07:00
|
|
|
uses: rharkor/caching-for-turbo@v1.5
|
|
|
|
|
2023-09-13 06:24:02 -07:00
|
|
|
- name: Build
|
|
|
|
if: ${{ inputs.cacheKey == '' }}
|
|
|
|
run: pnpm build
|
|
|
|
|
|
|
|
- name: Restore cached build artifacts
|
|
|
|
if: ${{ inputs.cacheKey != '' }}
|
2024-01-26 02:26:30 -08:00
|
|
|
uses: actions/cache/restore@v4.0.0
|
2023-09-13 06:24:02 -07:00
|
|
|
with:
|
|
|
|
path: ./packages/**/dist
|
|
|
|
key: ${{ inputs.cacheKey }}
|
|
|
|
|
2023-11-07 05:19:39 -08:00
|
|
|
- name: Test Backend
|
|
|
|
run: pnpm test:backend
|
|
|
|
|
2023-11-10 06:04:26 -08:00
|
|
|
- name: Test Nodes
|
|
|
|
run: pnpm test:nodes
|
|
|
|
|
2023-11-07 05:19:39 -08:00
|
|
|
- name: Test Frontend
|
|
|
|
run: pnpm test:frontend
|
2023-09-13 06:24:02 -07:00
|
|
|
|
|
|
|
- name: Upload coverage to Codecov
|
2024-06-13 04:10:51 -07:00
|
|
|
if: inputs.collectCoverage
|
2024-07-03 01:37:04 -07:00
|
|
|
uses: codecov/codecov-action@v4.5.0
|
2023-09-13 06:24:02 -07:00
|
|
|
with:
|
2024-07-03 01:37:04 -07:00
|
|
|
token: ${{ secrets.CODECOV_TOKEN }}
|