name: CI
on: [ push, pull_request ]

jobs:
  deploy:
    env:
      REPO: ${{ github.event.repository.name }}
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4

      - name: Setup JDK
        uses: actions/setup-java@v4
        with:
          distribution: 'zulu'
          java-version: '21'

      - name: Build Runner
        run: ./mvnw --no-transfer-progress clean verify -Pnative -Dquarkus.native.remote-container-build=true

      - name: Add coverage to PR
        id: jacoco
        uses: madrapps/jacoco-report@v1.7.1
        with:
          paths: ${{ github.workspace }}/**/target/coverage/jacoco.xml
          token: ${{ secrets.GITHUB_TOKEN }}
          min-coverage-overall: 40
          min-coverage-changed-files: 60
          title: ${{ env.REPO }} Coverage

      - name: Build Container
        if: github.ref_name == 'main'
        run: docker build -f src/main/docker/Dockerfile.native-micro -t ${{ env.REPO }} .

      - name: Deploy
        if: github.ref_name == 'main'
        run: "docker compose up -d"
