name: Build and release Android app

on:
  push:
    branches:
      - release
  workflow_dispatch:

jobs:
  build-and-release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: '4.0.2'
          bundler-cache: true
          working-directory: ./fastlane

      - name: Set up Java
        uses: actions/setup-java@v5
        with:
          distribution: 'temurin'
          java-version: '17'

      - name: Install Fastlane dependencies
        run: |
          cd fastlane
          bundle install

      - name: Build web assets
        run: |
          pnpm install
          pnpm build

      - name: Sync web assets to Android
        run: |
          pnpm capacitor sync android

      - name: Run Fastlane release
        env:
          PLAY_STORE_JSON_KEY_DATA: ${{ secrets.PLAY_STORE_JSON_KEY_DATA }}
        run: |
          cd fastlane
          fastlane android release
