Fastfile 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. # This file contains the fastlane.tools configuration
  2. # You can find the documentation at https://docs.fastlane.tools
  3. #
  4. # For a list of all available actions, check out
  5. #
  6. # https://docs.fastlane.tools/actions
  7. #
  8. # For a list of all available plugins, check out
  9. #
  10. # https://docs.fastlane.tools/plugins/available-plugins
  11. #
  12. default_platform(:ios)
  13. TEAMID = ENV["TEAMID"]
  14. GH_PAT = ENV["GH_PAT"]
  15. GITHUB_WORKSPACE = ENV["GITHUB_WORKSPACE"]
  16. GITHUB_REPOSITORY_OWNER = ENV["GITHUB_REPOSITORY_OWNER"]
  17. FASTLANE_KEY_ID = ENV["FASTLANE_KEY_ID"]
  18. FASTLANE_ISSUER_ID = ENV["FASTLANE_ISSUER_ID"]
  19. FASTLANE_KEY = ENV["FASTLANE_KEY"]
  20. DEVICE_NAME = ENV["DEVICE_NAME"]
  21. DEVICE_ID = ENV["DEVICE_ID"]
  22. ENV["FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT"] = "120"
  23. platform :ios do
  24. desc "Build Loop Follow"
  25. lane :build_LoopFollow do
  26. setup_ci if ENV['CI']
  27. update_project_team(
  28. path: "#{GITHUB_WORKSPACE}/LoopFollow.xcodeproj",
  29. teamid: "#{TEAMID}"
  30. )
  31. api_key = app_store_connect_api_key(
  32. key_id: "#{FASTLANE_KEY_ID}",
  33. issuer_id: "#{FASTLANE_ISSUER_ID}",
  34. key_content: "#{FASTLANE_KEY}"
  35. )
  36. previous_build_number = latest_testflight_build_number(
  37. app_identifier: "com.#{TEAMID}.LoopFollow",
  38. api_key: api_key,
  39. )
  40. current_build_number = previous_build_number + 1
  41. increment_build_number(
  42. xcodeproj: "#{GITHUB_WORKSPACE}/LoopFollow.xcodeproj",
  43. build_number: current_build_number
  44. )
  45. match(
  46. type: "appstore",
  47. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"),
  48. app_identifier: [
  49. "com.#{TEAMID}.LoopFollow",
  50. "com.#{TEAMID}.LoopFollow.LoopFollowLAExtension"
  51. ]
  52. )
  53. mapping = Actions.lane_context[
  54. SharedValues::MATCH_PROVISIONING_PROFILE_MAPPING
  55. ]
  56. update_code_signing_settings(
  57. path: "#{GITHUB_WORKSPACE}/LoopFollow.xcodeproj",
  58. profile_name: mapping["com.#{TEAMID}.LoopFollow"],
  59. code_sign_identity: "iPhone Distribution",
  60. targets: ["LoopFollow"]
  61. )
  62. update_code_signing_settings(
  63. path: "#{GITHUB_WORKSPACE}/LoopFollow.xcodeproj",
  64. profile_name: mapping["com.#{TEAMID}.LoopFollow.LoopFollowLAExtension"],
  65. code_sign_identity: "iPhone Distribution",
  66. targets: ["LoopFollowLAExtensionExtension"]
  67. )
  68. gym(
  69. export_method: "app-store",
  70. scheme: "LoopFollow",
  71. output_name: "LoopFollow.ipa",
  72. configuration: "Release",
  73. destination: 'generic/platform=iOS',
  74. buildlog_path: 'buildlog',
  75. export_options: {
  76. provisioningProfiles: {
  77. "com.#{TEAMID}.LoopFollow" => mapping["com.#{TEAMID}.LoopFollow"],
  78. "com.#{TEAMID}.LoopFollow.LoopFollowLAExtension" => mapping["com.#{TEAMID}.LoopFollow.LoopFollowLAExtension"]
  79. }
  80. }
  81. )
  82. copy_artifacts(
  83. target_path: "artifacts",
  84. artifacts: ["*.mobileprovision", "*.ipa", "*.dSYM.zip"]
  85. )
  86. end
  87. desc "Push to TestFlight"
  88. lane :release do
  89. api_key = app_store_connect_api_key(
  90. key_id: "#{FASTLANE_KEY_ID}",
  91. issuer_id: "#{FASTLANE_ISSUER_ID}",
  92. key_content: "#{FASTLANE_KEY}"
  93. )
  94. upload_to_testflight(
  95. api_key: api_key,
  96. skip_submission: false,
  97. ipa: "LoopFollow.ipa",
  98. skip_waiting_for_build_processing: true,
  99. )
  100. end
  101. desc "Provision Identifiers and Certificates"
  102. lane :identifiers do
  103. setup_ci if ENV['CI']
  104. ENV["MATCH_READONLY"] = false.to_s
  105. app_store_connect_api_key(
  106. key_id: "#{FASTLANE_KEY_ID}",
  107. issuer_id: "#{FASTLANE_ISSUER_ID}",
  108. key_content: "#{FASTLANE_KEY}"
  109. )
  110. def configure_bundle_id(name, identifier, capabilities)
  111. bundle_id = Spaceship::ConnectAPI::BundleId.find(identifier) || Spaceship::ConnectAPI::BundleId.create(
  112. name: name,
  113. identifier: identifier,
  114. platform: "IOS"
  115. )
  116. existing = bundle_id.get_capabilities.map(&:capability_type)
  117. capabilities.reject { |c| existing.include?(c) }.each do |cap|
  118. bundle_id.create_capability(cap)
  119. end
  120. end
  121. configure_bundle_id("LoopFollow", "com.#{TEAMID}.LoopFollow", [
  122. Spaceship::ConnectAPI::BundleIdCapability::Type::PUSH_NOTIFICATIONS
  123. ])
  124. configure_bundle_id("LoopFollow Live Activity Extension", "com.#{TEAMID}.LoopFollow.LoopFollowLAExtension", [])
  125. end
  126. desc "Provision Certificates"
  127. lane :certs do
  128. setup_ci if ENV['CI']
  129. ENV["MATCH_READONLY"] = false.to_s
  130. app_store_connect_api_key(
  131. key_id: "#{FASTLANE_KEY_ID}",
  132. issuer_id: "#{FASTLANE_ISSUER_ID}",
  133. key_content: "#{FASTLANE_KEY}"
  134. )
  135. match(
  136. type: "appstore",
  137. force: false,
  138. verbose: true,
  139. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"),
  140. app_identifier: [
  141. "com.#{TEAMID}.LoopFollow",
  142. "com.#{TEAMID}.LoopFollow.LoopFollowLAExtension"
  143. ]
  144. )
  145. end
  146. desc "Validate Secrets"
  147. lane :validate_secrets do
  148. setup_ci if ENV['CI']
  149. ENV["MATCH_READONLY"] = true.to_s
  150. app_store_connect_api_key(
  151. key_id: "#{FASTLANE_KEY_ID}",
  152. issuer_id: "#{FASTLANE_ISSUER_ID}",
  153. key_content: "#{FASTLANE_KEY}"
  154. )
  155. def find_bundle_id(identifier)
  156. bundle_id = Spaceship::ConnectAPI::BundleId.find(identifier)
  157. end
  158. find_bundle_id("com.#{TEAMID}.loopkit.LoopFollow")
  159. match(
  160. type: "appstore",
  161. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"),
  162. app_identifier: [],
  163. )
  164. end
  165. desc "Nuke Certs"
  166. lane :nuke_certs do
  167. setup_ci if ENV['CI']
  168. ENV["MATCH_READONLY"] = false.to_s
  169. app_store_connect_api_key(
  170. key_id: "#{FASTLANE_KEY_ID}",
  171. issuer_id: "#{FASTLANE_ISSUER_ID}",
  172. key_content: "#{FASTLANE_KEY}"
  173. )
  174. match_nuke(
  175. type: "appstore",
  176. team_id: "#{TEAMID}",
  177. skip_confirmation: true,
  178. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}")
  179. )
  180. end
  181. desc "Check Certificates and Trigger Workflow for Expired or Missing Certificates"
  182. lane :check_and_renew_certificates do
  183. setup_ci if ENV['CI']
  184. ENV["MATCH_READONLY"] = false.to_s
  185. # Authenticate using App Store Connect API Key
  186. api_key = app_store_connect_api_key(
  187. key_id: ENV["FASTLANE_KEY_ID"],
  188. issuer_id: ENV["FASTLANE_ISSUER_ID"],
  189. key_content: ENV["FASTLANE_KEY"] # Ensure valid key content
  190. )
  191. # Initialize flag to track if renewal of certificates is needed
  192. new_certificate_needed = false
  193. # Fetch all certificates
  194. certificates = Spaceship::ConnectAPI::Certificate.all
  195. # Filter for Distribution Certificates
  196. distribution_certs = certificates.select { |cert| cert.certificate_type == "DISTRIBUTION" }
  197. # Handle case where no distribution certificates are found
  198. if distribution_certs.empty?
  199. puts "No Distribution certificates found! Triggering action to create certificate."
  200. new_certificate_needed = true
  201. else
  202. # Check for expiration
  203. distribution_certs.each do |cert|
  204. expiration_date = Time.parse(cert.expiration_date)
  205. puts "Current Distribution Certificate: #{cert.id}, Expiration date: #{expiration_date}"
  206. if expiration_date < Time.now
  207. puts "Distribution Certificate #{cert.id} is expired! Triggering action to renew certificate."
  208. new_certificate_needed = true
  209. else
  210. puts "Distribution certificate #{cert.id} is valid. No action required."
  211. end
  212. end
  213. end
  214. # Write result to new_certificate_needed.txt
  215. file_path = File.expand_path('new_certificate_needed.txt')
  216. File.write(file_path, new_certificate_needed ? 'true' : 'false')
  217. # Log the absolute path and contents of the new_certificate_needed.txt file
  218. puts ""
  219. puts "Absolute path of new_certificate_needed.txt: #{file_path}"
  220. new_certificate_needed_content = File.read(file_path)
  221. puts "Certificate creation or renewal needed: #{new_certificate_needed_content}"
  222. end
  223. end