name: Deploy

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    container:
      image: catthehacker/ubuntu:act-latest
    steps:
      - name: Kaynak kodu çek
        uses: actions/checkout@v4

      - name: .env.production oluştur
        run: |
          cat > .env.production <<'EOF'
          BETTER_AUTH_SECRET=${{ secrets.BETTER_AUTH_SECRET }}
          BETTER_AUTH_URL=${{ secrets.BETTER_AUTH_URL }}
          NEXT_PUBLIC_APP_URL=${{ secrets.NEXT_PUBLIC_APP_URL }}
          GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}
          GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}
          RESEND_API_KEY=${{ secrets.RESEND_API_KEY }}
          EMAIL_FROM=${{ secrets.EMAIL_FROM }}
          IYZICO_API_KEY=${{ secrets.IYZICO_API_KEY }}
          IYZICO_SECRET_KEY=${{ secrets.IYZICO_SECRET_KEY }}
          IYZICO_BASE_URL=${{ secrets.IYZICO_BASE_URL }}
          ANTHROPIC_API_KEY=${{ secrets.ANTHROPIC_API_KEY }}
          EOF

      - name: Build & deploy
        run: |
          docker compose -p kolaytercih up -d --build --remove-orphans
          docker image prune -f
