# 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)

platform :ios do
  desc "Execute SwiftFormat and treat any formatting errors as real errors."
  lane :format do
    swiftformat(
      executable: "Pods/SwiftFormat/CommandLineTool/swiftformat",
      config: "Pods/SwiftConfigurationFiles/.swiftformat",
      path: "../",
      lint: true
    )
  end

  desc "Execute SwiftLint and treat any formatting errors as real errors."
  lane :lint do
    swiftlint(
      config_file: ".swiftlint.yml",
      strict: true,
      executable: "Pods/SwiftLint/swiftlint"
    )
  end

  desc "Verify Carthage support by making sure the scheme `GradientLoadingBar` is shared."
  lane :verify_carthage do
    #
    # For Carthage support we explicitly have to mark the scheme `GradientLoadingBar` as shared.
    # Source: https://www.amerhukic.com/how-to-add-carthage-support-in-existing-cocoapod-project
    #
    build_app(
      project: "Pods/Pods.xcodeproj",
      scheme: "GradientLoadingBar",
      skip_archive: true
    )
  end

  desc "Execute tests."
  lane :tests do
    run_tests(
      project: "Pods/Pods.xcodeproj",
      scheme: "GradientLoadingBar-Unit-Tests",
      devices: ["iPhone 14"],
      code_coverage: true,
      number_of_retries: 1
    )
  end

  desc "Execute validation of library."
  lane :pod_lint do
    Dir.chdir("..") do
      #
      # Move outside of `Example/` directory.
      #
      # - Note: We skip running the tests here, as we have a separate lane for this which allows better customization.
      #
      pod_lib_lint(
        verbose: true,
        skip_tests: true
      )
    end
  end
end
