name: Assemble bundle

on:
  push:
    branches:
      - main
  workflow_dispatch:
  workflow_call:

permissions:
  contents: read

jobs:
  check:
    uses: ./.github/workflows/check.yml
  bundle:
    runs-on: ubuntu-latest
    needs: [ check ]
    steps:
      - name: Decode Keystore
        run: |
          echo ${{ secrets.KEY_STORE }} | base64 -di > "${RUNNER_TEMP}"/keystore.jks
      - uses: actions/checkout@v4
      - uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true

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

      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v4

      - name: Bundle
        env:
          KEY_PATH: ${{ runner.temp }}/keystore.jks
          KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
          KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
          KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
          MAPBOX_KEY: ${{ secrets.MAPBOX_KEY }}
          GOOGLE_KEY: ${{ secrets.GOOGLE_KEY }}
        run: bundle exec fastlane bundle
      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: release
          path: |
            app/build/outputs/**
            wear/build/outputs/**
