# This workflow will build the project on pull requests with tests
# Uses:
#   OS: ubuntu-latest
#   JDK: Adopt JDK 8, Adopt JDK 11 and Adopt JDK 17

name: PR Builder

on:
  pull_request:
    branches: [main, master]
  workflow_dispatch:

env:
  MAVEN_OPTS: -Xmx4g -Xms1g

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        java-version: [ 8, 11, 17 ]

    steps:
      - uses: actions/checkout@v2
      - name: Set up Adopt JDK
        uses: actions/setup-java@v2
        with:
          java-version: ${{ matrix.java-version }}
          distribution: "adopt"
      - name: Cache local Maven repository
        id: cache-maven-m2
        uses: actions/cache@v3
        env:
          cache-name: cache-m2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-${{ env.cache-name }}-
            ${{ runner.os }}-maven-
            ${{ runner.os }}-
      - name: Build with Maven
        run: mvn clean install -U -B

