# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: "Continuous Integration"

on:
  pull_request:
    branches: [ develop, v2.x-develop ]

permissions: read-all

jobs:
  ci:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        java: [17]
    steps:
      - name: "Cache Maven Repos"
        uses: actions/cache@v4
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-
      - if: github.event_name == 'pull_request_target'
        run: echo "REF=refs/pull/${{ github.event.number }}/merge" >> "$GITHUB_ENV"
      - name: "Checkout"
        uses: actions/checkout@v4
        with:
          ref: ${{ env.REF }}
      - name: "Set up JDK ${{ matrix.java }}"
        uses: actions/setup-java@v4
        with:
          java-version: ${{ matrix.java }}
          distribution: 'zulu'
          architecture: x64
      - name: "Print maven version"
        run: mvn -version
      - name: "Check with Maven"
        run: mvn -B clean package apache-rat:check spotbugs:spotbugs -DskipTests -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
      - name: "Build with Maven"
        run: mvn -Prelease-nacos -DskipTests clean install -U -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
      - name: "Test With Maven"
        run: mvn -Prelease-nacos clean test -DtrimStackTrace=false -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn