name: Build
on: [push]

jobs:
  build-and-push-image:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 # Important pour récupérer tout l'historique Git

      - name: Log in to Harbor registry
        uses: docker/login-action@v3
        with:
          registry: harbor.bv.stef.lan
          username: ${{ secrets.HARBOR_USERNAME }}
          password: ${{ secrets.HARBOR_PASSWORD }} 
      - name: Log in to Gitea registry
        uses: docker/login-action@v3
        with:
          registry: gitea.bv.stef.lan
          username: ${{ secrets.USERNAME }}
          password: ${{ secrets.PASSWORD }}

      - name: Debug Gitea variables
        run: |
          echo "GITEA_REF: ${GITEA_REF}"
          echo "GITEA_SHA: ${GITEA_SHA}"
          echo "All env variables:"
          env 

      - name: Build and push image
        uses: docker/build-push-action@v6
        with:
          context: . # UTILISE LE CONTEXTE LOCAL, PAS L'URL GIT
          push: ${{ github.event_name != 'pull_request' }}
          tags: |
            harbor.bv.stef.lan/library/pki-manager:${{env.GITHUB_SHA}}
            gitea.bv.stef.lan/stef/pki-manager:v${{env.GITHUB_RUN_ID}}
          provenance: false # Peut simplifier le débogage initialement
          build-args: |
            BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
