on:
  pull_request:
    branches:
      - main
    paths:
      - "backend/**"
      - "pom.xml"

name: Code Coverage

permissions:
  pull-requests: write

jobs:
  generic_handler:
    name: Code Coverage
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.GH_TOKEN }}

      # Cache Maven dependencies
      - name: Cache Maven dependencies
        uses: actions/cache@v3
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('backend/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-

      - name: Set up JDK 21
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu'
          java-version: 21
          check-latest: false

      - name: Build with Maven - other
        run: mvn -B package -DskipAntRunForJenkins --file pom.xml -pl '!frontend'

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v5
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          slug: 1Panel-dev/CordysCRM