name: CI

on: [push, pull_request]

jobs:
  build:

    runs-on: self-hosted

    strategy:
      matrix:
        node-version: [12.x]

    steps:
    - uses: actions/checkout@v1
    - name: Get npm cache directory
      id: npm-cache
      run: |
        echo "::set-output name=dir::$(npm config get cache)"
    - uses: actions/cache@v1
      with:
        path: ${{ steps.npm-cache.outputs.dir }}
        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-node-
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm install
    - run: npx sequelize-cli db:migrate
      env:
        NODE_ENV: test
    - run: npm run build --if-present
    - run: npm run lint-ci
      env:
        NODE_ENV: test
    - run: npm test
      env:
        CI: true
        NODE_ENV: test
