name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

defaults:
  run:
    shell: bash

jobs:
  tests:
    runs-on: ${{ matrix.os }}

    timeout-minutes: 10

    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macOS-latest]
        node-version: [12.x, 14.x]

    steps:
    - name: Prepare git
      run: git config --global core.autocrlf false

    - uses: actions/checkout@v2

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}

    - name: Get npm cache directory
      id: npm-cache
      run: |
        echo "::set-output name=dir::$(npm config get cache)"

    - uses: actions/cache@v2
      with:
        path: ${{ steps.npm-cache.outputs.dir }}
        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-node-

    - name: Install Node.js dependencies
      run: npm install

    - name: Code linter
      run: npm run lint

    - name: Tests
      run: npm run test
