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:
Milorad FIlipović 2023-09-13 15:24:02 +02:00 committed by GitHub
parent a6e027b3ff
commit c11dfbbe00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 108 additions and 62 deletions

View file

@ -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

View file

@ -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

View 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 }}

View 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