name: CI

on:
  push:
    branches: [ master ]

jobs:
  lint:
    name: Lint files

    strategy:
      matrix:
        os: [ ubuntu-latest ]
        node-version: [ 12.x ]

    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2

      - uses: actions/cache@v2
        with:
          path: '**/node_modules'
          key: ${{ matrix.os }}-modules-${{ hashFiles('**/yarn.lock') }}

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

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

      - name: Lint
        run: npm run lint


  test:
    needs: lint
    name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}
    runs-on: ${{ matrix.os }}

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

    steps:
      - uses: actions/checkout@v2

      - uses: actions/cache@v2
        with:
          path: '**/node_modules'
          key: ${{ matrix.os }}-modules-${{ hashFiles('**/yarn.lock') }}

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

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

      - name: Run tests
        run: npm test

  release:
    needs: test
    name: Release

    strategy:
      matrix:
        os: [ ubuntu-latest ]
        node-version: [ 12.x ]

    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2

      - uses: actions/cache@v2
        with:
          path: '**/node_modules'
          key: ${{ matrix.os }}-modules-${{ hashFiles('**/yarn.lock') }}

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

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

      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: yarn run semantic-release
