# GitHub Actions: build with playx secure env.
# Copy to .github/workflows/build.yml.
#
# Setup (Repository > Settings > Secrets and variables > Actions): add each
# secret (e.g. STRIPE_KEY, MAPS_KEY), then map it below as PLAYX_SECRET_<NAME>.
# `dart run playx:secure_env --from-env-prefix PLAYX_SECRET_` encrypts them into
# lib/generated/playx_secure_env.g.dart before building.
# Apps depending on playx_core only: use `dart run playx_core:secure_env`.
name: Build

on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      PLAYX_ENV: prod
      PLAYX_SECRET_STRIPE_KEY: ${{ secrets.STRIPE_KEY }}
      PLAYX_SECRET_MAPS_KEY: ${{ secrets.MAPS_KEY }}
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: '17'

      - uses: subosito/flutter-action@v2
        with:
          channel: stable
          cache: true

      - run: flutter pub get

      - name: Generate encrypted secure env
        run: dart run playx:secure_env --from-env-prefix PLAYX_SECRET_

      - name: Build Android
        run: flutter build appbundle --release

      - name: Build web
        run: flutter build web --release

      - uses: actions/upload-artifact@v4
        with:
          name: builds
          path: |
            build/app/outputs/bundle/release/*.aab
            build/web
