Skip to content

Commit

Permalink
ci: Refactor linting workflow (no-changelog) (n8n-io#9714)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored Jun 13, 2024
1 parent cfef49e commit ab29ba9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 62 deletions.
32 changes: 5 additions & 27 deletions .github/workflows/ci-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,12 @@ jobs:
collectCoverage: true

lint:
name: Lint changes
runs-on: ubuntu-latest
name: Lint
uses: ./.github/workflows/linting-reusable.yml
needs: install-and-build
steps:
- uses: actions/[email protected]
with:
repository: n8n-io/n8n
ref: ${{ inputs.branch }}

- run: corepack enable
- uses: actions/[email protected]
with:
node-version: 20.x
cache: pnpm

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

- name: Restore cached build artifacts
uses: actions/cache/[email protected]
with:
path: ./packages/**/dist
key: ${{ github.sha }}-base:build

- name: Lint
env:
CI_LINT_MASTER: true
run: pnpm lint
with:
ref: ${{ inputs.branch }}
cacheKey: ${{ github.sha }}-base:build

notify-on-failure:
name: Notify Slack on failure
Expand Down
36 changes: 8 additions & 28 deletions .github/workflows/ci-pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build, unit test and lint branch
on: [pull_request]

jobs:
install:
install-and-build:
name: Install & Build
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -36,35 +36,15 @@ jobs:
unit-test:
name: Unit tests
uses: ./.github/workflows/units-tests-reusable.yml
needs: install
needs: install-and-build
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
cacheKey: ${{ github.sha }}-base:build

lint:
name: Lint changes
runs-on: ubuntu-latest
needs: install
steps:
- uses: actions/[email protected]
with:
repository: n8n-io/n8n
ref: refs/pull/${{ github.event.pull_request.number }}/merge

- run: corepack enable
- uses: actions/[email protected]
with:
node-version: 20.x
cache: pnpm

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

- name: Restore cached build artifacts
uses: actions/cache/[email protected]
with:
path: ./packages/**/dist
key: ${{ github.sha }}-base:build

- name: Lint
run: pnpm lint
name: Lint
uses: ./.github/workflows/linting-reusable.yml
needs: install-and-build
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
cacheKey: ${{ github.sha }}-base:build
54 changes: 54 additions & 0 deletions .github/workflows/linting-reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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: false
default: ''
type: string

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repository: n8n-io/n8n
ref: ${{ inputs.ref }}

- run: corepack enable
- uses: actions/[email protected]
with:
node-version: 20.x
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/[email protected]
with:
path: ./packages/**/dist
key: ${{ inputs.cacheKey }}

- name: Lint Backend
run: pnpm lint:backend

- name: Lint Nodes
run: pnpm lint:nodes

- name: Lint Frontend
run: pnpm lint:frontend
14 changes: 7 additions & 7 deletions .github/workflows/units-tests-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ on:
workflow_call:
inputs:
ref:
description: 'GitHub ref to test.'
description: GitHub ref to test.
required: false
type: string
default: 'master'
default: master
nodeVersion:
description: 'Version of node to use.'
description: Version of node to use.
required: false
type: string
default: 20.x
cacheKey:
description: 'Cache key for modules and build artifacts.'
description: Cache key for modules and build artifacts.
required: false
default: ''
type: string
collectCoverage:
required: false
default: 'false'
type: string
default: false
type: boolean

jobs:
unit-test:
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
run: pnpm test:frontend

- name: Upload coverage to Codecov
if: ${{ inputs.collectCoverage == 'true' }}
if: inputs.collectCoverage
uses: codecov/codecov-action@v3
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/@n8n/codemirror-lang/coverage/cobertura-coverage.xml,packages/editor-ui/coverage/cobertura-coverage.xml,packages/nodes-base/coverage/cobertura-coverage.xml,packages/workflow/coverage/cobertura-coverage.xml
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"format": "turbo run format && node scripts/format.mjs",
"lint": "turbo run lint",
"lintfix": "turbo run lintfix",
"lint:backend": "pnpm --filter=!@n8n/chat --filter=!@n8n/codemirror-lang --filter=!n8n-design-system --filter=!n8n-editor-ui --filter=!n8n-nodes-base --filter=!@n8n/n8n-nodes-langchain lint",
"lint:nodes": "pnpm --filter=n8n-nodes-base --filter=@n8n/n8n-nodes-langchain lint",
"lint:frontend": "pnpm --filter=@n8n/chat --filter=@n8n/codemirror-lang --filter=n8n-design-system --filter=n8n-editor-ui lint",
"optimize-svg": "find ./packages -name '*.svg' ! -name 'pipedrive.svg' -print0 | xargs -0 -P16 -L20 npx svgo",
"start": "run-script-os",
"start:default": "cd packages/cli/bin && ./n8n",
Expand Down

0 comments on commit ab29ba9

Please sign in to comment.