# 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.63.0"

default_platform :ios

platform :ios do
  before_all do
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    # cocoapods
    # carthage
    create_keychain(
      name: ENV["MATCH_KEYCHAIN_NAME"],
      password: ENV["MATCH_KEYCHAIN_PASSWORD"],
      timeout: 1200
    )
  end

  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
    match(
      type: "appstore",
      git_url: "git@github.com:RocketChat/Rocket.Chat.ReactNative.FastLane.git"
    ) # more information: https://codesigning.guide
    pem()
    gym(scheme: "RocketChatRN") # Build your app - more options available
    pilot

    # 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 :release do
    # match(type: "appstore")
    # snapshot
    match(
      type: "appstore",
      git_url: "git@github.com:RocketChat/Rocket.Chat.ReactNative.FastLane.git"
    ) # more information: https://codesigning.guide
    deliver(force: true)
    # frameit
  end

  desc "Build App"
  lane :build do
    # match(type: "appstore")
    # snapshot
    match(
      type: "appstore",
      git_url: "git@github.com:RocketChat/Rocket.Chat.ReactNative.FastLane.git"
    ) # more information: https://codesigning.guide
    pem()
    gym(scheme: "RocketChatRN") # Build your app - more options available
    # 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."
    # )
    delete_keychain(name: ENV["MATCH_KEYCHAIN_NAME"])
  end

  error do |lane, exception|
    # slack(
    #   message: exception.message,
    #   success: false
    # )
    delete_keychain(name: ENV["MATCH_KEYCHAIN_NAME"])
  end
end


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

# fastlane reports which actions are used. No personal data is recorded.
# Learn more at https://docs.fastlane.tools/#metrics
