---
# System prepended metadata

title: Fastlaen FastFile

---

# Fastlaen FastFile

default_platform(:ios)

platform :ios do

  before_all do |lane|
  #Pleae dont put anything here
  end
  
  desc "Manual Highway Lane: Git pull" 
  lane: pullDevelopment do 
    #ensure_git_branch(
     #  branch: 'development')
    git_pull
  end 

  desc "App Store[Not used]"
  lane :distributeAppStore do
    match(type: "appstore",
          app_identifier: ["com.dsg.mobile.consumer",
                           "com.dsg.mobile.consumer.RichNotificationServiceExtension",
                           "com.dsg.mobile.consumer.iMessage-Stickers"],
          git_branch: "app-store",
          team_id: "XT5SKW92DF")

    build_app(scheme: "RELEASE APP STORE",
              workspace: "DSG.ScoreCardConsumerApp.xcworkspace",
              include_bitcode: true,
              clean: true)

    upload_to_app_store
  end

  desc "Manual Highway Build"
  lane :manualBuild do |options|
    #match(type: "enterprise")
    build_app(scheme: options[:scheme],
              workspace: "DSG.ScoreCardConsumerApp.xcworkspace",
              export_options:{
                method:"enterprise"
              },
              include_bitcode: true)
  end
  
  desc "Jenkins Highway Build"
  lane :jenkinsBuild do |options|
    #match(type: "enterprise")
    build_app(scheme: options[:scheme],
              workspace: "DSG.ScoreCardConsumerApp.xcworkspace",
              export_options:{
                method:"enterprise"
              },
              include_bitcode: true)
  end

  desc "Common Lane Distribute"
  lane :distribute do |options|
    changelog_from_git_commits(commits_count: 5,
                               merge_commit_filtering: "include_merges")

    firebase_app_distribution(app: "1:936104992585:ios:22fe9b536f8f704754c498", # App ID for DSG-ConsumerAPP-QA
                              groups: options[:groups] ? "Dev-Group" : "QA-Group")
  end
  

  desc "Common Lane Increment Build Number" 
  lane :incrementBuildNumber do
    increment_build_number
  end
 
  desc "Manual Highway Distribute Prod UAT"
  lane :manualDistributeProdUAT do
    ensure_git_status_clean
    incrementBuildNumber
    manualBuild(scheme: "UAT RELEASE PROD")
    distribute(groups: "Dev-Group")
  end
  
  desc "Jankins Highway Distribute Prod UAT"
  lane :jenkisDistributeProdUAT do
    #ensure_git_status_clean
    incrementBuildNumber
    jenkinsBuild(scheme: "UAT RELEASE PROD")
    distribute(groups: "Dev-Group")
  end

  desc "Manual Highway Distribute Release QA"
  lane :manualDistributeReleaseQA do
    #ensure_git_status_clean
    incrementBuildNumber
    manualBuild(scheme: "RELEASE QA")
    distribute(groups: "Dev-Group")
  end
  
  desc "Jenkins Highway Distribute Release QA"
  lane :jenkisDistributeReleaseQA do
    #ensure_git_status_clean
    incrementBuildNumber
    jenkinsBuild(scheme: "RELEASE QA")
    distribute(groups: "Dev-Group")
  end

  desc "Manual Highway Distribute Dev"
  lane :manualDistributeDev do
    incrementBuildNumber
    manualBuild(scheme: "RELEASE QA")
    distribute(groups: "Dev-Group")
  end
  
  desc "Jenkins Highway Distribute Dev"
  lane :jenkinsDistributeDev do
    incrementBuildNumber
    jenkinsBuild(scheme: "RELEASE QA")
    distribute(groups: "Dev-Group")
  end

  desc "Manual Highway Distribute Dev UAT RELEASE PROD"
  lane :manualDistributeProdToDev do
    incrementBuildNumber
    manualBuild(scheme: "UAT RELEASE PROD")
    distribute(groups: "Dev-Group")
  end
  
  desc "Jenkins Highway Distribute Dev UAT RELEASE PROD"
  lane :jenkisDistributeProdToDev do
    incrementBuildNumber
    jenkinsBuild(scheme: "UAT RELEASE PROD")
    distribute(groups: "Dev-Group")
  end

  desc "Manual Highway Commit Version Bump"
  lane :manualCommitVersionBump do
    build_number = get_build_number
    version_number = get_version_number(
      target: "QA Release"
    )
    commit_version_bump(
      message: "Version Bump to v#{version_number} - #{build_number}",
      xcodeproj: "DSG.ScoreCardConsumerApp.xcodeproj",
      force: false
    )
  end
  
  desc "Jenkins Highway Commit Version Bump"
  lane :jenkinsCommitVersionBump do
    build_number = get_build_number
    version_number = get_version_number(
      target: "QA Release"
    )
    commit_version_bump(
      message: "Version Bump to v#{version_number} - #{build_number}",
      xcodeproj: "DSG.ScoreCardConsumerApp.xcodeproj",
      force: true #due to jenkins limitation
    )
  end

 desc "Jenkins Highway commit incremented version"
 lane :jenkinsManualPushToGitRemote do
  sh("git checkout -b versionBump")
  sh("git add .")
  commitVersionBump
  sh("git checkout jenkins-pipeline-setup")
  sh("git merge versionBump")
  sh("git push origin jenkins-pipeline-setup")
  sh("git branch -d versionBump")
 end
 
 desc "Manual Highway Push to git remote"
  lane :manualPushToGitRemote do
    push_to_git_remote(
      remote: "origin",
      local_branch: "development",
      remote_branch: "development", 
      force: false,
      force_with_lease: false,
      tags: false,
      no_verify: true,
      set_upstream: false
    )
  end

  #desc "Push to git remote"
  #lane :pushToGitRemote do
    #commitIncrementedVersion
  #end

  desc "Jenkins Test Lane"
  lane :jenkinsLane do
    incrementBuildNumber
    pushToGitRemote
  end


  after_all do |lane|
    #pushToGitRemote
    clean_build_artifacts
  end


  lane :tests do
    run_tests(workspace: "DSG.ScoreCardConsumerApp.xcworkspace",
              scheme: "DEBUG QA",
              skip_testing: ["ScoreCardConsumerAppTests/ScoreCardConsumerAppTests",
                             "ScoreCardConsumerAppTests/FitnessAppLIstViewTests",
                             "ScoreCardConsumerAppTests/IntroBannerCellTests",
                             "ScoreCardConsumerAppTests/ManageTrackerActionSheetTests",
                             "ScoreCardConsumerAppTests/MoveManageTrackerModelTests",
                             "ScoreCardConsumerAppTests/MoveManageTrackerViewControllerTests",
                             "ScoreCardConsumerAppTests/MoveTrackerCategoriesTests",
                             "ScoreCardConsumerAppTests/MoveRealmControllerTests",
                             "ScoreCardConsumerAppTests/DSGMoveTrackerTests",
                             "ScoreCardConsumerAppTests/SuggetedAppsTests"])
  end

  
end
