on: [push, pull_request]

jobs:
  test:
    name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        node_version: [8, 10, 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: npm install, build and test
      run: |
        npm install -g npm
        npm ci
        npm run build

  artifact:
    name: Build artifact
    runs-on: ubuntu-latest
    needs: [test]

    steps:
    - uses: actions/checkout@v1

    - name: Use Node.js ${{ 12 }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ 12 }}
    
    - name: npm install, build
      run: |
        npm install -g npm
        npm ci
        npm run build

    - uses: actions/upload-artifact@master
      with:
        name: production-build
        path: build
