name: ci/cd

on: [push, pull_request, create] # see: https://developer.github.com/webhooks/

jobs:
  test:
    name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        node_version: ['8', '10', '11', '12', '13']
        os: [ubuntu-latest, windows-latest, macOS-latest]
    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js ${{ matrix.node_version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node_version }}
    - name: yarn install and test
      run: |
        yarn install
        yarn test

  publish-npm:
    name: Publish on node 13 and ubuntu-latest
    if: github.event_name == 'create' && github.event.ref_type == 'tag' # see: https://developer.github.com/v3/activity/events/types/#createevent
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: 13
          registry-url: https://registry.npmjs.org/
      - run: yarn install
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.YARN_TOKEN}}
