name: Deploy App (manual)

on:
  workflow_dispatch:
    inputs:
      app:
        description: App slug (directory under apps/)
        required: true
        type: string

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout (validate app exists in repo)
        uses: actions/checkout@v4

      - name: Validate app slug
        run: |
          APP="${{ inputs.app }}"
          if ! echo "$APP" | grep -qE '^[a-z0-9]+(-[a-z0-9]+)*$'; then
            echo "Invalid app slug: $APP"
            exit 1
          fi
          if [ ! -d "apps/$APP" ]; then
            echo "apps/$APP not found in repository"
            exit 1
          fi

      - name: Build and deploy on boka
        env:
          DEPLOY_ROOT: ${{ secrets.DEPLOY_ROOT }}
          DEPLOY_GIT_TOKEN: ${{ secrets.DEPLOY_GIT_TOKEN }}
          DEPLOY_BRANCH: main
        run: |
          DEPLOY_ROOT="${DEPLOY_ROOT:-/home/frank/playground.schwenk.online}"
          chmod +x scripts/deploy-app.sh
          DEPLOY_ROOT="$DEPLOY_ROOT" DEPLOY_GIT_TOKEN="$DEPLOY_GIT_TOKEN" \
            scripts/deploy-app.sh "${{ inputs.app }}"
