default_platform(:ios)

platform :ios do
  desc "Increase version number"
  lane :bump do |options|
    increment_build_number
    if options[:version] && options[:version] != ""
      increment_version_number(
        version_number: options[:version]
      )
    end

    # Write version to record file
    version_num = get_build_number
    version_name = get_version_number
    sh("echo '#{version_name}(#{version_num})' > ../../version.txt")
  end

  desc "Build app using release scheme"
  lane :build do
    # Run to fix CI bugs
    setup_ci(provider: 'circleci')

    # Unlock keychain to access signing certs
    unlock_keychain( # Unlock an existing keychain and add it to the keychain search list
      path: ENV["KEYCHAIN_PATH"],
      password: ENV["KEYCHAIN_PASS"]
    )

    # Compile release version of code
    build_app(
      scheme: "flare",
      include_bitcode: false,
      export_options: {
        uploadBitcode: false,
        uploadSymbols: true,
        compileBitcode: false
      }
    )
  end

  desc "Submit already built app to Testflight"
  lane :alpha do |options|
    # Run to fix CI bugs
    setup_ci(provider: 'circleci')

    # Deploy to test flight
    pilot(
      api_key_path: "./api.json",
      ipa: './flare.ipa',
      groups: ['FLARe Testers'],
      skip_waiting_for_build_processing: true
    )
  end
end

