# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:ios)
enable_automatic_code_signing

ENV["KDS_PROJECT_NAME"] = "Runner"
ENV["KDS_VERSION_NUMBER_TO_SET"] = "0.0.4"

  desc "Opens reset_git_repo"
  lane :cleanproject do
	if is_ci
		reset_git_repo(force:true) if is_ci?			
	end
    # add actions here: https://docs.fastlane.tools/actions
  end

platform :ios do

  ## Setup
  before_all do |lane, options|
    ##import custom actions, mandatory for distribute_to_appcatalog action:
    import_from_git(url: "git@git.kurzdigital.com:kds/kds-fastlane-custom-actions.git")
    ##generate project specific build paths, set version etc.
    #kds_before_all()
    
    ## when we are on CI, we should reset all icon changes etc.
    #reset_git_repo(force:true) if is_ci?

    ###ensure to use the same version for all targets #test
    increment_version_number(
    version_number: ENV["KDS_VERSION_NUMBER_TO_SET"],
    xcodeproj: "#{ENV["KDS_PROJECT_NAME"]}.xcodeproj"
    )

    increment_build_number(
    build_number: number_of_commits.to_s,
    xcodeproj: "#{ENV["KDS_PROJECT_NAME"]}.xcodeproj"
    )

    ##generate project specific build paths etc
    generate_specific_build_vars()
  end







  desc "Description of what the lane does"
  lane :build do
	if is_ci
		get_provisioning_profile(
		app_identifier: "kds-touch-demo-rs", 
		username: "kds-ci@kurzdigital.com")

		build_ios_app(scheme: "Runner", 
		export_method: 'enterprise',
		output_directory: 'build')

		distribute_to_appcatalog(
            	appcatalog_app_id: "5c4896ba655065007f780306",
            	file_path: ENV['IPA_OUTPUT_PATH'],
            	#release_notes: "\n#{ENV["KDS_CHANGELOG"]}\n\n#{current_time_string}: #{ENV["KDS_BUILD_NAME"]}"
		release_notes: "Add vibrations to buttons and improved animations"
          ) 					
	end
    # add actions here: https://docs.fastlane.tools/actions
  end


	## Success Completion Handler
  after_all do  |lane, options|
    #slack_success(lane) if (is_ci? && !"#{lane}".eql?("test"))
  end

## ERROR Completion Handler
  error do |lane, exception|
    #slack_failure(lane, exception) if is_ci?
  end


end
