default_platform(:android)

platform :android do

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

  desc "Deploy a new version to the Google Play"
  lane :deploy do
    gradle(
        task: "bundle",
        build_type: "Release"
    )

    aab_path = lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH]
    keystore = ENV["FASTLANE_KEYSTORE"]
    storepass = ENV["FASTLANE_STOREPASS"]
    bily_keypass = ENV["FASTLANE_BILY_KEYPASS"]

    # Sign the AAB using jarsigner
    cmd = "jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 -keystore #{keystore} -storepass #{storepass} #{aab_path} bily-upload -keypass #{bily_keypass}"

    # Executing the command
    sh(cmd)

    upload_to_play_store(
        skip_upload_apk: true,
        validate_only: false
    )
  end

end
