name: CI

on: [push, pull_request]

defaults:
  run:
    shell: bash

jobs:
  os-java:
    name: OS x Java
    strategy:
      matrix:
        os: [ubuntu-latest]
        # TODO: update each time a new major Java version is released.
        java: [11, 15]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2

      - name: Cache node modules
        uses: actions/cache@v2
        env:
          cache-name: cache-node-modules
        with:
          # npm cache files are stored in `~/.npm` on Linux/macOS
          path: ~/.npm
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Cache maven dependencies
        uses: actions/cache@v2
        env:
          cache-name: cache-maven-dependencies
        with:
          # mvn cache files are stored in `~/.m2` on Linux/macOS
          path: ~/.m2
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Set up JDK
        uses: actions/setup-java@v1
        with:
          java-version: ${{ matrix.java }}
      # http.keepAlive and maven.wagon.http.pool are used to help stabilize network connection in virtual hosts
      - name: Build with Maven
        run: mvn -B install -Dintegration-tests=true
      # check that git working tree is clean after running npm install via a frontend-maven-plugin
      # the git command returns 1 and fails the build if there are any uncommitted changes
      - name: Check for clean working tree
        run: git diff HEAD --exit-code
