name: "\U0001F680 EAS Build and Submit"

on:
  workflow_dispatch:
    inputs:
      platform:
        required: true
        type: choice
        description: Select platform
        options:
          - ios
          - android
          - all
        default: "all"
      profile:
        required: true
        type: choice
        description: Select profile
        options:
          - development
          - staging
          - production
        default: staging
      submit:
        required: true
        type: choice
        description: Do you want to submit after build
        options:
          - "yes"
          - "no"
        default: "no"

jobs:
  eas_build:
    name: "EAS build and submit"
    runs-on: ubuntu-latest
    env:
      PLATFORM: ${{ github.event.inputs.platform }}
      PROFILE: ${{ github.event.inputs.profile }}
      SHOULD_SUBMIT: ${{ github.event.inputs.submit }}
      working-directory: ./apps/mobile
      EXPO_PUBLIC_NODE_ENV: ${{ github.event.inputs.profile == 'production' && 'production' || 'development' }}

    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: 24
      - uses: pnpm/action-setup@v4
      - name: "\U0001F4E6 Install Packages"
        run: pnpm install --frozen-lockfile
        working-directory: ${{ env.working-directory }}
      - name: Generate dotenv file
        working-directory: ${{ env.working-directory }}
        env:
          environ: '{"EXPO_PUBLIC_NODE_ENV": "${{ env.EXPO_PUBLIC_NODE_ENV }}"}'
        run: |
          ../../.github/scripts/create-env.sh "$environ"
      - uses: expo/expo-github-action@v8
        with:
          expo-cache: true
          expo-version: latest
          eas-version: latest
          token: ${{ secrets.EXPO_TOKEN }}
      - name: "\U0001F680 EAS ${{ github.event.inputs.profile }} Build and submit"
        run: |
          .github/scripts/eas-build.sh
