.github/workflows/ci.yml
name: Lint, test and build
on:
push:
paths:
- '.github/workflows/ci.yml'
- 'src/**'
- '__tests__/**'
- 'tsconfig.json'
- '.eslintrc.json'
- 'jest.setup.js'
- 'jest.config.js'
- 'next.config.js'
- 'yarn.lock'
env:
NODE_VERSION: 16
jobs:
setup-env:
name: Setup environment
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Restore node_modules
uses: actions/cache@v3
id: node-modules-cache
with:
path: node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-deps-
- name: Install deps
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: yarn
- name: Cache node_modules
if: steps.node-modules-cache.outputs.cache-hit != 'true'
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-deps-
lint:
needs: setup-env
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Restore node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-deps-
- name: Lint
run: yarn lint
test:
needs: setup-env
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Restore node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-deps-
- name: Test & publish code coverage
uses: paambaati/codeclimate-action@v3.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageCommand: yarn test
debug: true
build:
needs: setup-env
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Restore node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-deps-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-deps-
- name: Create .env file
run: echo "${{ secrets.ENV_VARS }}" > .env
- name: Build
run: yarn build