default_platform(:mac)
$upload_retry=0

platform :mac do
  desc "Push a new beta build to TestFlight"
  lane :do_build do
    build_mac_app(
      workspace: "Runner.xcworkspace",
      scheme: "Runner",
      export_method: "app-store"
    )
  end

  lane :do_upload do
    changelog = read_changelog(changelog_path: '../CHANGELOG.md')

    begin
      upload_to_testflight(
        skip_waiting_for_build_processing: true,
        changelog: changelog,
      )
    rescue => ex
         $upload_retry +=1
         if $upload_retry <= 3
           do_upload
         else
           raise ex
         end
     end
  end

  lane :do_package do
    changelog = read_changelog(changelog_path: '../CHANGELOG.md')
    build_mac_app(
      workspace: "Runner.xcworkspace",
      scheme: "Runner",
      export_method: "developer-id",
      output_directory: "../build/export"
    )
  end
end
