name: Build
on:
  push:
    branches:
      - master
  pull_request:
jobs:
  test:
    strategy:
      matrix:
        version:
          - 8.x
          - 16.x
        platform:
          - ubuntu-latest
          - macos-latest
          - windows-latest
    runs-on: ${{matrix.platform}}
    steps:
      - name: Use Node ${{matrix.version}}
        uses: actions/setup-node@v1
        with:
          node-version: ${{matrix.version}}
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Install Dependencies
        run: npm ci
      - name: Commitlint
        run: git log --format=%B -1 | npm run commitlint
      - name: Test
        run: npm test
      - name: Generate Coverage
        if: ${{ matrix.platform == 'ubuntu-latest' && matrix.version == '16.x' }}
        run: npm run coverage
      - name: Upload Coverage
        if: ${{ matrix.platform == 'ubuntu-latest' && matrix.version == '16.x' }}
        uses: codecov/codecov-action@v2
      - name: Release
        if: ${{ matrix.platform == 'ubuntu-latest' && matrix.version == '16.x' && github.ref == 'refs/heads/master' }}
        run: npm run release
        env:
          GH_TOKEN: ${{ secrets.GH_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
