name: CI/CD Lions Pipeline

on:
  push:
    branches: [main, develop]
  workflow_dispatch:
    inputs:
      environment:
        description: 'Environnement cible'
        required: true
        default: 'production'
        type: choice
        options:
          - dev
          - staging
          - production

env:
  LIONS_CLUSTER: k1
  LIONS_JAVA_VERSION: '17'   # override si app en Java 21

jobs:
  pipeline:
    name: Build + Push + Deploy
    runs-on: ubuntu-latest
    timeout-minutes: 30

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup lionsctl
        run: |
          # Suppose lionsctl installé sur le runner (via image custom)
          # Alternative : curl -L https://git.lions.dev/lionsdev/lionsctl/releases/download/latest/lionsctl -o /usr/local/bin/lionsctl
          lionsctl --version

      - name: Pipeline deploy
        env:
          LIONS_REGISTRY_USERNAME: ${{ secrets.LIONS_REGISTRY_USERNAME }}
          LIONS_REGISTRY_PASSWORD: ${{ secrets.LIONS_REGISTRY_PASSWORD }}
          LIONS_GIT_USERNAME: lionsctl-bot
          LIONS_GIT_PASSWORD: ${{ secrets.LIONS_GIT_PASSWORD }}
          LIONS_GIT_ACCESS_TOKEN: ${{ secrets.LIONS_GIT_ACCESS_TOKEN }}
          SMTP_HOST: ${{ secrets.SMTP_HOST }}
          SMTP_USERNAME: ${{ secrets.SMTP_USERNAME }}
          SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
          SMTP_FROM: ${{ secrets.SMTP_FROM }}
        run: |
          ENV="${{ github.event.inputs.environment || 'production' }}"
          lionsctl pipeline \
            -u ${{ gitea.server_url }}/${{ gitea.repository }} \
            -b ${{ gitea.ref_name }} \
            -j ${{ env.LIONS_JAVA_VERSION }} \
            -e "$ENV" \
            -c ${{ env.LIONS_CLUSTER }} \
            -p prod \
            -m admin@lions.dev
