# Deploy workflow — template for CI/CD pipeline
# Real registry URLs and deployment targets come from customer (A2/A8)

name: Deploy

on:
  push:
    branches: [main]

env:
  NODE_VERSION: "24"
  PNPM_VERSION: "9"
  # Placeholder: replace with customer registry
  REGISTRY: "registry.example.com"
  IMAGE_STANDALONE: "flights-web-standalone"
  IMAGE_REMOTE: "flights-web-remote"

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: ${{ env.PNPM_VERSION }}

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Typecheck
        run: pnpm typecheck

      - name: Lint
        run: pnpm lint

      - name: Test
        run: pnpm test

      - name: Build both targets
        run: pnpm build:both

      - name: Build Docker images
        run: |
          docker build -f Dockerfile.react -t ${{ env.REGISTRY }}/${{ env.IMAGE_STANDALONE }}:${{ github.sha }} .
          docker build -f Dockerfile.remote -t ${{ env.REGISTRY }}/${{ env.IMAGE_REMOTE }}:${{ github.sha }} .

      # Placeholder: push to customer registry
      # - name: Push Docker images
      #   run: |
      #     docker push ${{ env.REGISTRY }}/${{ env.IMAGE_STANDALONE }}:${{ github.sha }}
      #     docker push ${{ env.REGISTRY }}/${{ env.IMAGE_REMOTE }}:${{ github.sha }}

      # Placeholder: deploy to testing environment
      # - name: Deploy to testing
      #   run: |
      #     echo "Deploy standalone image to testing environment"
      #     echo "Run post-deploy smoke test"

      # Placeholder: auto-rollback on health-check failure
      # - name: Post-deploy health check
      #   run: |
      #     curl -f https://testing.example.com/health || echo "Health check failed — trigger rollback"
