name: Tests

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  test-api:
    name: Test API
    runs-on: ubuntu-latest

    defaults:
      run:
        working-directory: api

    steps:
      - name: Set up Go 1.x
        uses: actions/setup-go@v2
        with:
          go-version: ^1.13
        id: go

      - name: Check out code into the Go module directory
        uses: actions/checkout@v2

      - name: Get dependencies
        run: |
          go get -v -t -d ./...
          if [ -f Gopkg.toml ]; then
              curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
              dep ensure
          fi

      - name: Build
        run: go build -v .

      - name: Test
        run: go test -v ./...
        
  test-ui:
    name: Test UI
    runs-on: ubuntu-latest
    
    defaults:
      run:
        working-directory: ui
    
    strategy:
      matrix:
        node-version: [10.x, 14.x]

    steps:
    - uses: actions/checkout@v2
      
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    
    - name: Install dependencies
      run: npm install
      
    - name: Build
      run: npm run build --if-present
      
    - name: Test
      run: npm test
