mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
ci: Add reusable unit test workflow (no-changelog) (#7159)
Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
parent
a6e027b3ff
commit
c11dfbbe00
36
.github/workflows/ci-master.yml
vendored
36
.github/workflows/ci-master.yml
vendored
|
@ -40,41 +40,15 @@ jobs:
|
|||
|
||||
unit-test:
|
||||
name: Unit tests
|
||||
runs-on: ubuntu-latest
|
||||
uses: ./.github/workflows/units-tests-reusable.yml
|
||||
needs: install-and-build
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x, 20.5]
|
||||
steps:
|
||||
- uses: actions/checkout@v3.5.3
|
||||
with:
|
||||
repository: n8n-io/n8n
|
||||
ref: ${{ inputs.branch }}
|
||||
|
||||
- uses: pnpm/action-setup@v2.4.0
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3.7.0
|
||||
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@v3.3.1
|
||||
with:
|
||||
path: ./packages/**/dist
|
||||
key: ${{ github.sha }}-base:${{ matrix.node-version }}-test-lint
|
||||
|
||||
- name: Test
|
||||
run: pnpm test
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
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
|
||||
with:
|
||||
ref: ${{ inputs.branch }}
|
||||
nodeVersion: ${{ matrix.node-version }}
|
||||
cacheKey: ${{ github.sha }}-base:${{ matrix.node-version }}-test-lint
|
||||
|
||||
lint:
|
||||
name: Lint changes
|
||||
|
|
35
.github/workflows/ci-pull-requests.yml
vendored
35
.github/workflows/ci-pull-requests.yml
vendored
|
@ -34,38 +34,11 @@ jobs:
|
|||
|
||||
unit-test:
|
||||
name: Unit tests
|
||||
runs-on: ubuntu-latest
|
||||
uses: ./.github/workflows/units-tests-reusable.yml
|
||||
needs: install
|
||||
steps:
|
||||
- uses: actions/checkout@v3.5.3
|
||||
with:
|
||||
repository: n8n-io/n8n
|
||||
ref: ${{ inputs.branch }}
|
||||
|
||||
- uses: pnpm/action-setup@v2.4.0
|
||||
|
||||
- name: Use Node.js 18
|
||||
uses: actions/setup-node@v3.7.0
|
||||
with:
|
||||
node-version: 18.x
|
||||
cache: pnpm
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Restore cached build artifacts
|
||||
uses: actions/cache/restore@v3.3.1
|
||||
with:
|
||||
path: ./packages/**/dist
|
||||
key: ${{ github.sha }}-base:18-test-lint
|
||||
|
||||
- name: Test
|
||||
run: pnpm test
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
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
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
cacheKey: ${{ github.sha }}-base:18-test-lint
|
||||
|
||||
lint:
|
||||
name: Lint changes
|
||||
|
|
39
.github/workflows/units-tests-dispatch.yml
vendored
Normal file
39
.github/workflows/units-tests-dispatch.yml
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
name: Runs unit tests for a given ref
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
ref:
|
||||
description: 'GitHub ref to test.'
|
||||
required: false
|
||||
default: 'master'
|
||||
type: string
|
||||
prNumber:
|
||||
description: 'PR number to run tests for.'
|
||||
required: false
|
||||
type: number
|
||||
|
||||
jobs:
|
||||
prepare:
|
||||
name: Prepare
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
branch: ${{ steps.compute-branch.outputs.branch }}
|
||||
steps:
|
||||
- name: Compute branch
|
||||
id: compute-branch
|
||||
run: |
|
||||
BRANCH_NAME=""
|
||||
if [[ "${{ inputs.prNumber }}" != "" && "${{ inputs.prNumber }}" != "null" ]]; then
|
||||
BRANCH_NAME="refs/pull/${{ inputs.prNumber }}/merge"
|
||||
else
|
||||
BRANCH_NAME="${{ inputs.ref }}"
|
||||
fi
|
||||
echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
unit-test:
|
||||
name: Unit tests
|
||||
needs: prepare
|
||||
uses: ./.github/workflows/units-tests-reusable.yml
|
||||
with:
|
||||
ref: ${{ needs.prepare.outputs.branch }}
|
60
.github/workflows/units-tests-reusable.yml
vendored
Normal file
60
.github/workflows/units-tests-reusable.yml
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
name: Reusable units test workflow
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
ref:
|
||||
description: 'GitHub ref to test.'
|
||||
required: false
|
||||
type: string
|
||||
default: 'master'
|
||||
nodeVersion:
|
||||
description: 'Version of node to use.'
|
||||
required: false
|
||||
type: string
|
||||
default: '18.x'
|
||||
cacheKey:
|
||||
description: 'Cache key for modules and build artifacts.'
|
||||
required: false
|
||||
default: ''
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
unit-test:
|
||||
name: Unit tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3.5.3
|
||||
with:
|
||||
repository: n8n-io/n8n
|
||||
ref: ${{ inputs.ref }}
|
||||
|
||||
- uses: pnpm/action-setup@v2.4.0
|
||||
|
||||
- name: Use Node.js ${{ inputs.nodeVersion }}
|
||||
uses: actions/setup-node@v3.7.0
|
||||
with:
|
||||
node-version: ${{ inputs.nodeVersion }}
|
||||
cache: pnpm
|
||||
|
||||
- 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@v3.3.1
|
||||
with:
|
||||
path: ./packages/**/dist
|
||||
key: ${{ inputs.cacheKey }}
|
||||
|
||||
- name: Test
|
||||
run: pnpm test
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
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
|
Loading…
Reference in a new issue