name: Deploy to Fly.io
# Note: path-filtered by design; touching this workflow file also triggers deploy.

on:
  push:
    branches: [main]
    paths:
      - "docs/**"
      - "installer/**"
      - "nginx/**"
      - "Dockerfile.docs"
      - "fly.toml"
      - ".github/workflows/deploy-fly.yml"
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: fly-deploy-mudabbir
  cancel-in-progress: true

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup flyctl
        uses: superfly/flyctl-actions/setup-flyctl@master

      - name: Validate required secret
        run: |
          if [ -z "${{ secrets.FLY_API_TOKEN }}" ]; then
            echo "::error::Missing required GitHub secret: FLY_API_TOKEN"
            exit 1
          fi

      - name: Deploy app
        env:
          FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
        run: flyctl deploy --remote-only --config fly.toml --app mudabbir
