name: CI
on:
  push:
    branches:
      - '*'
  pull_request:
    branches:
      - '*'
jobs:
  ci:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ ubuntu-latest, windows-latest, macos-latest ]
        # Keep this list as: all supported LTS JDKs, the latest GA JDK, and optionally the latest EA JDK (if available).
        # https://www.oracle.com/java/technologies/java-se-support-roadmap.html
        java: [ 17, 21, 23 ]
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: ${{ matrix.java }}
          cache: maven
      - name: Build with Maven
        # To support Windows PowerShell, a space between --define property=true is required.
        run: ./mvnw --batch-mode --no-transfer-progress verify
      # Code Coverage (runs once per matrix)
      - name: Build with coverage with Maven using JDK ${{ matrix.java }}
        if: ${{ matrix.java == '17' && matrix.os == 'ubuntu-latest' }}
        run: ./mvnw --batch-mode --no-transfer-progress --activate-profiles=coverage verify
      - name: Upload JaCoCo report
        if: ${{ matrix.java == '17' && matrix.os == 'ubuntu-latest' }}
        uses: actions/upload-artifact@v4
        with:
          name: jacoco
          path: code-coverage/target/site/jacoco-aggregate/
      # Aggregate Javadoc (runs once per matrix)
      - name: Build aggregate Javadoc with Maven using JDK ${{ matrix.java }}
        if: ${{ matrix.java == '17' && matrix.os == 'ubuntu-latest' }}
        run: ./mvnw --batch-mode --no-transfer-progress --define skipTests=true verify javadoc:aggregate
      - name: Upload aggregate Javadoc
        if: ${{ matrix.java == '17' && matrix.os == 'ubuntu-latest' }}
        uses: actions/upload-artifact@v4
        with:
          name: apidocs
          path: target/site/apidocs/
