# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do
  desc 'Push a new release build to the App Store'
  lane :release do
    # Setup for CI. Uses a keychain to prevent the CI from hanging due to password prompts.
    setup_ci

    # Obtain credentials from App Store Connect API. Will be automatically used for the rest of the lane.
    app_store_connect_api_key(
      key_id: ENV['APP_STORE_KEY_ID'],
      issuer_id: ENV['APP_STORE_ISSUER_ID'],
      key_content: ENV['APP_STORE_CREDENTIALS'],
      is_key_content_base64: true
    )

    # Manage code signing (with match).
    sync_code_signing

    # Automatic signing is used during development, but fastlane needs to use manual signing.
    update_code_signing_settings(
      code_sign_identity: 'iPhone Distribution',
      profile_name: 'match AppStore com.tommychow.frosty'
    )

    # Build the app for release.
    build_app(
      workspace: 'Runner.xcworkspace',
      scheme: 'Runner',
      output_directory: '../build/ios/archive'
    )

    # Upload the app to the App Store.
    upload_to_app_store(
      submit_for_review: true,
      force: true, # Disable HTML summary prompt that appears when uploading to the App Store.
      precheck_include_in_app_purchases: false, # Disabled due to not being supported with the App Store Connect API Key.
      skip_screenshots: true,
      automatic_release: true,
      submission_information: { add_id_info_uses_idfa: false }
    )
  end
end
