on:
  push:
    tags:
      - 'v*'

jobs:
  build:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up ruby env
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.1
          bundler-cache: true

      - name: Install Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          flutter-version: 3.22.0
          cache: true

      - name: Infer version number from git tag
        id: version
        env: 
          REF_NAME: ${{ github.ref_name }}
        run:
          # remove the 'v' prefix from the tag name
          echo "BUILD_NAME=${REF_NAME//v}" >> $GITHUB_ENV

      - name: Load secrets from github
        run: |
          echo "${{ secrets.IOS_SECRET_PROPERTIES_BASE64 }}" | base64 -d > secrets.properties
          echo "${{ secrets.IOS_GOOGLE_PLAY_JSON_BASE64 }}" | base64 -d > google-key.json
          echo "${{ secrets.IOS_KEYSTORE_BASE64 }}" | base64 -d > release.keystore
        working-directory: ios

      - name: Install fastlane
        run: bundle install
        working-directory: ios

      - name: Run fastlane lane
        run: bundle exec fastlane deploy_release
        working-directory: ios
        env:
          BUILD_NUMBER: ${{ github.run_number }}
          # BUILD_NAME is implicitly available
          GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
          IOS_ASC_KEY_ID: ${{ secrets.IOS_ASC_KEY_ID }}
          IOS_ASC_ISSUER_ID: ${{ secrets.IOS_ASC_ISSUER_ID }}
          IOS_ASC_KEY_P8: ${{ secrets.IOS_ASC_KEY_P8 }}