# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/fastlane/docs
# 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.29.1"

default_platform :ios

platform :ios do
  before_all do
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    #cocoapods
    
  end

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

    def next_verson
        Time.now.strftime("%Y-%m-%d %H:%M:%S")
    end

    new_build_number = next_verson

    #OldCarDailyDebugOutput = "~/Desktop/YXPBuyerOutput/YXPBuyerDailyAdhoc/YXPBuyerDaily/" + new_build_number
    #OldCarDailyAdhocOutput = "~/Desktop/YXPBuyerOutput/YXPBuyerDailyDebug/YXPBuyerDebug/" + new_build_number
    #OldCarAppStoreOutput   = "~/Desktop/YXPBuyerOutput/YXPBuyerDailyAdhoc/YXPBuyerAppStore/" + new_build_number


    desc "Build ADHOC"
    lane :adhoc do
        gym(scheme: "CheckAuto3-0",
            configuration: "Release",
            export_method: "enterprise",
            xcargs:'-UseModernBuildSystem=NO',
            export_options: {
            #method: "ad-hoc",
                #compileBitcode: false,
                provisioningProfiles: {
                    "com.wuba.benztmp" => "comwubabenztmpprod"
                }
            },
            workspace: "CheckAuto3-0.xcworkspace",
            clean: true,
            #output_directory: OldCarDailyAdhocOutput
            )
      #usedcar firim key
      #firim(firim_api_token:"cbd89ab1ad9950aad2a93ff790ff75aa")
      #firim(firim_api_token:"08fee6b50e0caad63724294953fbe253")
      #firim(firim_api_token:"cbd89ab1ad9950aad2a93ff790ff75aa")
      #pgyer(api_key: "dbe8ad9d05e27e17131d1c3318c3b3b7", user_key: "51a9b9e0ce1a9a4cb2aac747ba78e6e8")
      #deliver(force: true)
      #deliver(username: "hhxx13141314@163.com", app_identifier: "com.youxinpai.buyer", skip_metadata: true, skip_screenshots:true ,force: true,ipa:OldCarDailyAdhocOutput,team_id:CQZUDS5K3X,team_name:"Uxin China Car Auction Co.Ltm",dev_portal_team_id:9774975,dev_portal_team_name:"Uxin China Car Auction Co.Ltm")

    end

	desc "Build app-store"
  	  lane :AppStore do
     	   gym(scheme: "YXPBuyer",
   	       configuration: "Release",
              export_method: "app-store",
              xcargs:'-UseModernBuildSystem=NO',
                export_options: {
                #method: "app-store",
                    provisioningProfiles: {
                        "com.youxinpai.buyer" => "comyouxinpaibuyerDistribution"
                    }
                },
              workspace: "YXPBuyer.xcworkspace",
              clean: true,
              #output_directory: OldCarAppStoreOutput
            )
        #pgyer(api_key: "8e99562e00f31259085f3877967b8918", user_key: "e939c215c7446648c4eab0ed0f1d095b")
    end

    #desc "deliver action"
    #lane :deliver_adhoc do
    # deliver(username: "hhxx13141314@163.com", app_identifier: "com.youxinpai.buyer", skip_metadata: true, skip_screenshots:true ,force: true,ipa:OldCarDailyAdhocOutput,team_id:CQZUDS5K3X,team_name:"Uxin China Car Auction Co.Ltm",dev_portal_team_id:9774975,dev_portal_team_name:"Uxin China Car Auction Co.Ltm")
    #end


     desc "daily test"
     lane :daily do
        gym(scheme: "YXP-iOS",
        configuration: "Debug",
        export_method: "development",
        workspace: "YXP-iOS.xcworkspace",
        clean: true,
        #output_directory: OldCarDailyDebugOutput
        )
        pgyer(api_key: "8e99562e00f31259085f3877967b8918", user_key: "e939c215c7446648c4eab0ed0f1d095b")
    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") # more information: https://codesigning.guide
    gym # 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
    gym # 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/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://github.com/fastlane/fastlane#metrics
