name: Tests

on:
  # if pushed directly
  push:
    branches:
      - master
      - release/*
      - ci/*
  # on a pull request
  pull_request:
    branches:
      - master
      - release/*
      - ci/*

jobs:
  unit-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: recursive
      - name: Set up JDK
        uses: actions/setup-java@v1
        with:
          java-version: 13

      - name: Install System Libs
        run: sudo apt-get install -y openssl libapr1

      - name: Check
        uses: eskatos/gradle-command-action@v1
        with:
          arguments: check
        env:
          CI: true

      - name: Upload Coverage Report
        uses: codecov/codecov-action@v1
        with:
          file: ./build/reports/jacoco/test/jacocoTestReport.xml

  integration-test:
    runs-on: ubuntu-latest
    # Docker Hub image that `container-job` executes in.
    # Use -buster which comes with Git 2.20, because action/checkout needs Git 2.18+ to make correct clone (needed by Gradle version plugin)
    container: node:12-buster
    services:
      redis:
        image: redis
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: recursive
      - name: Set up JDK
        uses: actions/setup-java@v1
        with:
          java-version: 13

      - name: Check
        uses: eskatos/gradle-command-action@v1
        with:
          arguments: check
        env:
          CI: true
          DSHACKLE_TEST_ENABLED: redis
          REDIS_HOST: redis
          REDIS_PORT: 6379