name: Build and Test Java Application

on:
  push:
    branches:
      - "main"
    paths-ignore:
      - '.gitignore'
      - 'CODEOWNERS'
      - 'LICENSE'
      - '*.md'
      - '*.adoc'
      - '*.txt'
      - '.all-contributorsrc'
  pull_request:
    paths-ignore:
      - '.gitignore'
      - 'CODEOWNERS'
      - 'LICENSE'
      - '*.md'
      - '*.adoc'
      - '*.txt'
      - '.all-contributorsrc'

jobs:
  build-linux:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 17

      - name: Get Date
        id: get-date
        run: |
          echo "date=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT
        shell: bash
      - name: Cache Maven Repository
        id: cache-maven
        uses: actions/cache@v4
        with:
          path: ~/.m2/repository
          # resulting in faster build times. 
          key: maven-repo-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
      - name: Install pnpm
        run: npm install -g pnpm
      - name: Maven Version
        run: mvn --version
      - name: Build with Maven
        run: mvn -B formatter:validate install --file pom.xml
      - name: Build with Maven (Native)
        run: mvn -B install -Dnative -Dquarkus.native.container-build -Dnative.surefire.skip
  build-windows:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 17

      - name: Get Date
        id: get-date
        run: |
           echo "date=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT
        shell: bash
      - name: Cache Maven Repository
        id: cache-maven
        uses: actions/cache@v4
        with:
          path: ~/.m2/repository
          # resulting in faster build times. 
          key: maven-repo-${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
      - name: Install pnpm
        run: npm install -g pnpm@~8.6.12
      - name: Maven Version
        run: mvn --version
      - name: Build with Maven
        run: mvn -B install --file pom.xml