# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/docs
# All available actions: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Actions.md
# 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.94.0"

default_platform :ios

platform :ios do

  desc "Runs all the tests"
  lane :test do
    scan
  end

  desc "Submit a new Beta Build to Apple TestFlight"
  desc "This will also make sure the profile is up to date"
  lane :beta do
    version = get_version_number(xcodeproj: ENV['XCODEPROJ_NAME'], target: 'Keybase')
    increment_build_number(build_number: number_of_commits)

    api_key = app_store_connect_api_key(
      key_id: "C783PA5XUX",
      issuer_id: "69a6de85-d809-47e3-e053-5b8c7c11a4d1",
      key_filepath: "/Users/test/AuthKey_C783PA5XUX.p8",
      duration: 1200, # optional (maximum 1200)
      in_house: false # optional but may be required if using match/sigh
    )

    sigh(app_identifier: "keybase.ios")
    sigh(app_identifier: "keybase.ios.KeybaseShare")
    gym(scheme: "Keybase") # Build your app - more options available
    pilot(
        api_key: api_key,
        changelog: changelog_from_git_commits(
          pretty: '%h %s',
          between: ["HEAD^^^^^", "HEAD"]
        )
    )

    # sh "your_script.sh"
    # You can also use other beta testing services here (run `fastlane actions`)
  end

  desc "Deploy a new version to the App Store"
  lane :appstore do
    # snapshot
    gym(scheme: "Keybase") # Build your app - more options available
    deliver(force: true)
    # frameit
  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

    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end

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


# More information about multiple platforms in fastlane: https://github.com/fastlane/fastlane/blob/master/docs/Platforms.md
# All available actions: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Actions.md

# fastlane reports which actions are used
# No personal data is recorded. Learn more at https://github.com/fastlane/enhancer
