# 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(:android)

platform :android do
  desc "Runs all the tests"
  lane :test do
    gradle(task: "test")
  end

  desc "Build a new Beta build"
  lane :beta do
    gradle(task: "clean assembleRelease")
    #crashlytics

    # sh "your_script.sh"
    # You can also use other beta testing services here
  end

  desc "Update versionCode to be one higher than the latest on Play Store"
  lane :update_version do
    gp = google_play_track_version_codes(track: 'production')
    gb = google_play_track_version_codes(track: 'beta')
    ga = google_play_track_version_codes(track: 'alpha')
    gi = google_play_track_version_codes(track: 'internal')
    max_value = [gp[0].to_i, gb[0].to_i, ga[0].to_i, gi[0].to_i].max
    version_updated = max_value + 1

    increment_version_code(
        gradle_file_path: "mobile/build.gradle",
        version_code: version_updated
    )
  end

  desc "Set versionCode to a specific value"
  lane :set_version do |options|
    version = options[:version]
    increment_version_code(
        gradle_file_path: "mobile/build.gradle",
        version_code: version
    )
  end

  desc "Deploy a new version to the Google Play"
  lane :deploy do
    gradle(task: "clean assembleRelease")
    upload_to_play_store
  end
end
