name: Backend Deploy 🚀
run-name: ${{ gitea.actor }} backend güncelliyor...

on:
  push:
    branches:
      - main

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Kodu Çek
        uses: actions/checkout@v3

      - name: Docker Build
        run: docker build -t backend-haruncan-studio:latest .

      - name: Eski Konteyneri Sil
        run: docker rm -f backend-haruncan-studio-container || true

      - name: Veritabanı Migration
        run: |
          docker run --rm \
            --network docker-data_gitea \
            -e DATABASE_URL='${{ secrets.DATABASE_URL }}' \
            backend-haruncan-studio:latest \
            npx prisma migrate deploy

      - name: Yeni Versiyonu Başlat
        run: |
          docker run -d \
            --name backend-haruncan-studio-container \
            --restart always \
            --network docker-data_gitea \
            -p 1809:3000 \
            -v /mnt/extreme/docker-data/haruncan-studio-uploads:/app/uploads \
            -e DATABASE_URL='${{ secrets.DATABASE_URL }}' \
            -e JWT_SECRET='${{ secrets.JWT_SECRET }}' \
            -e NODE_ENV='production' \
            backend-haruncan-studio:latest