# .github/workflows/deploy-matrix.yml
name: Deploy MicroDAO
on:
  workflow_dispatch:
  push:
    branches: [ main ]

jobs:
  plan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Upload dependency matrix artifact
        uses: actions/upload-artifact@v4
        with:
          name: microdao-matrix
          path: microdao_dependency_matrix.yaml

  deploy:
    runs-on: ubuntu-latest
    needs: plan
    strategy:
      fail-fast: false
      matrix:
        stage: [P0, P1, P2, P3, P4]
        env: [dev, stage, prod]
    steps:
      - uses: actions/checkout@v4
      - name: Download matrix
        uses: actions/download-artifact@v4
        with:
          name: microdao-matrix
          path: .
      - name: Render deployment plan
        run: |
          python - <<'PY'
          import yaml, sys
          y = yaml.safe_load(open('microdao_dependency_matrix.yaml'))
          stage='${{ matrix.stage }}'
          env='${{ matrix.env }}'
          svcs=[s for s in y['services'] if s['stage']==stage]
          print(f"Deploy plan for {stage} in {env}:")
          for s in svcs:
            print(f"- {s['id']} deps={s.get('depends_on', [])}")
          PY
      - name: Deploy
        run: |
          echo "Deploying stage=${{ matrix.stage }} env=${{ matrix.env }}"
          # Insert helm/terraform commands here, filtered by stage and env
      - name: Post-deploy health checks
        run: |
          echo "Run health gates and canary analysis"