# Production ships when a v* tag is pushed (docs/release/environments.md):
#   git tag v1.2.0 && git push origin v1.2.0
#
# Same shape as deploy-sandbox: Convex first, then fingerprint-gated
# OTA update vs. store builds. Store builds are submitted automatically;
# App Store release and Play rollout are still confirmed by hand in the
# store consoles.
#
# Requires in the `production` EAS environment: CONVEX_DEPLOY_KEY (production
# project), GLIDE_APP_VARIANT=production, and the live EXPO_PUBLIC_* vars.
name: Release to production

# DISABLED — manual-only for now. Production releases are run by hand (see the
# manual runbook in docs/release/environments.md). To automate, restore the tag
# trigger below and connect the repo to EAS's GitHub integration.
on:
  workflow_dispatch: {}
  # push:
  #   tags: ['v*']

jobs:
  deploy_backend:
    name: Deploy Convex (production)
    environment: production
    steps:
      - uses: eas/checkout
      - uses: eas/install_node_modules
      - name: Deploy to the production Convex project
        run: bunx convex deploy

  fingerprint:
    name: Compute fingerprint
    type: fingerprint
    environment: production

  get_ios_build:
    name: Find existing iOS build
    needs: [fingerprint]
    type: get-build
    params:
      platform: ios
      profile: production
      fingerprint_hash: ${{ needs.fingerprint.outputs.ios_fingerprint_hash }}

  get_android_build:
    name: Find existing Android build
    needs: [fingerprint]
    type: get-build
    params:
      platform: android
      profile: production
      fingerprint_hash: ${{ needs.fingerprint.outputs.android_fingerprint_hash }}

  publish_update:
    name: OTA update (production channel)
    needs: [deploy_backend, get_ios_build, get_android_build]
    if: ${{ needs.get_ios_build.outputs.build_id && needs.get_android_build.outputs.build_id }}
    type: update
    environment: production
    params:
      channel: production

  build_ios:
    name: Build iOS (production)
    needs: [deploy_backend, get_ios_build]
    if: ${{ !needs.get_ios_build.outputs.build_id }}
    type: build
    params:
      platform: ios
      profile: production

  submit_ios:
    name: Submit to App Store
    needs: [build_ios]
    type: submit
    params:
      build_id: ${{ needs.build_ios.outputs.build_id }}
      profile: production

  build_android:
    name: Build Android (production)
    needs: [deploy_backend, get_android_build]
    if: ${{ !needs.get_android_build.outputs.build_id }}
    type: build
    params:
      platform: android
      profile: production

  submit_android:
    name: Submit to Play Store
    needs: [build_android]
    type: submit
    params:
      build_id: ${{ needs.build_android.outputs.build_id }}
      profile: production
