# Customize this file, documentation can be found here:
# https://docs.fastlane.tools/actions/
# All available actions: https://docs.fastlane.tools/actions
# can also be listed using the `fastlane actions` command

# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`

# If you want to automatically update fastlane if a new version is available:
# update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.68.0"

default_platform :android

platform :android do

    versionNum = 82


    before_all do
    end

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


    desc "Deploy app to play store alpha channel"
    lane :deployAlpha do |options|

        gradle(task: 'clean')
        gradle(
              task: ":android-app:bundleRelease",
              properties: {
                  'versionNum' => versionNum
              }
        )

        supply(
            package_name: "dev.johnoreilly.galwaybus",
            track: "alpha",
            aab: "android-app/build/outputs/bundle/release/android-app-release.aab",
            skip_upload_apk: true,
            skip_upload_metadata: true,
            skip_upload_images: true,
            skip_upload_screenshots: true
        )
    end


    lane :deployInternalTest do |options|

        gradle(task: 'clean')
        gradle(
              task: ":android-app:bundleRelease",
              properties: {
                  'versionNum' => versionNum
              }
       )

        supply(
            package_name: "dev.johnoreilly.galwaybus",
            track: "internal",
            aab: "android-app/build/outputs/bundle/release/android-app-release.aab",
            skip_upload_apk: true,
            skip_upload_metadata: true,
            skip_upload_images: true,
            skip_upload_screenshots: true
        )
    end


    lane :buildApp do |options|
        gradle(task: 'clean')
        gradle(
              task: ":android-app:bundleRelease",
              properties: {
                  'versionNum' => versionNum
              }
        )
    end

    lane :buildAppApk do |options|
        gradle(task: 'clean')
        gradle(
              task: ":android-app:assembleRelease",
              properties: {
                  'versionNum' => versionNum
              }
        )
    end


    desc "Promote app from alpha to production in Play Store"
    lane :promoteAppToProd do |options|

        supply(
            package_name: "dev.johnoreilly.galwaybus",
            track: "internal",
            track_promote_to: "production",
            skip_upload_apk: true,
            skip_upload_metadata: true,
            skip_upload_images: true,
            skip_upload_screenshots: true,
            version_code: 1001086
        )
    end


    desc "Generate app screenshots that will be uploaded to play store"
    lane :screenshots do |options|

        gradle(
              task: "assembleDebug assembleDebugAndroidTest"
        )

        screengrab(
            locales: ['en-US'],
            clear_previous_screenshots: true,
            app_package_name: "dev.johnoreilly.galwaybus",
            use_tests_in_packages: ['dev.johnoreilly.galwaybus.screenshots'],
            app_apk_path: "android-app/build/outputs/apk/debug/app-debug.apk",
            tests_apk_path: "android-app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk"
        )
    end





  # You can define as many lanes as you want

  after_all do |lane|
    # This block is called, only if the executed lane was successful
  end

  error do |lane, exception|
    # slack(
    #   message: exception.message,
    #   success: false
    # )
  end
end
