Fastfile 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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::APP_GROUPS,
  123. Spaceship::ConnectAPI::BundleIdCapability::Type::PUSH_NOTIFICATIONS
  124. ])
  125. configure_bundle_id("LoopFollow Live Activity Extension", "com.#{TEAMID}.LoopFollow.LoopFollowLAExtension", [
  126. Spaceship::ConnectAPI::BundleIdCapability::Type::APP_GROUPS
  127. ])
  128. end
  129. desc "Provision Certificates"
  130. lane :certs do
  131. setup_ci if ENV['CI']
  132. ENV["MATCH_READONLY"] = false.to_s
  133. app_store_connect_api_key(
  134. key_id: "#{FASTLANE_KEY_ID}",
  135. issuer_id: "#{FASTLANE_ISSUER_ID}",
  136. key_content: "#{FASTLANE_KEY}"
  137. )
  138. match(
  139. type: "appstore",
  140. force: false,
  141. verbose: true,
  142. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"),
  143. app_identifier: [
  144. "com.#{TEAMID}.LoopFollow",
  145. "com.#{TEAMID}.LoopFollow.LoopFollowLAExtension"
  146. ]
  147. )
  148. end
  149. desc "Validate Secrets"
  150. lane :validate_secrets do
  151. setup_ci if ENV['CI']
  152. ENV["MATCH_READONLY"] = true.to_s
  153. app_store_connect_api_key(
  154. key_id: "#{FASTLANE_KEY_ID}",
  155. issuer_id: "#{FASTLANE_ISSUER_ID}",
  156. key_content: "#{FASTLANE_KEY}"
  157. )
  158. match(
  159. type: "appstore",
  160. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"),
  161. app_identifier: [],
  162. )
  163. end
  164. desc "Nuke Certs"
  165. lane :nuke_certs do
  166. setup_ci if ENV['CI']
  167. ENV["MATCH_READONLY"] = false.to_s
  168. app_store_connect_api_key(
  169. key_id: "#{FASTLANE_KEY_ID}",
  170. issuer_id: "#{FASTLANE_ISSUER_ID}",
  171. key_content: "#{FASTLANE_KEY}"
  172. )
  173. match_nuke(
  174. type: "appstore",
  175. team_id: "#{TEAMID}",
  176. skip_confirmation: true,
  177. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}")
  178. )
  179. end
  180. desc "Check Certificates and Trigger Workflow for Expired or Missing Certificates"
  181. lane :check_and_renew_certificates do
  182. setup_ci if ENV['CI']
  183. ENV["MATCH_READONLY"] = false.to_s
  184. # Authenticate using App Store Connect API Key
  185. api_key = app_store_connect_api_key(
  186. key_id: ENV["FASTLANE_KEY_ID"],
  187. issuer_id: ENV["FASTLANE_ISSUER_ID"],
  188. key_content: ENV["FASTLANE_KEY"] # Ensure valid key content
  189. )
  190. # Initialize flag to track if renewal of certificates is needed
  191. new_certificate_needed = false
  192. # Fetch all certificates
  193. certificates = Spaceship::ConnectAPI::Certificate.all
  194. # Filter for Distribution Certificates
  195. distribution_certs = certificates.select { |cert| cert.certificate_type == "DISTRIBUTION" }
  196. # Handle case where no distribution certificates are found
  197. if distribution_certs.empty?
  198. puts "No Distribution certificates found! Triggering action to create certificate."
  199. new_certificate_needed = true
  200. else
  201. # Check for expiration
  202. distribution_certs.each do |cert|
  203. expiration_date = Time.parse(cert.expiration_date)
  204. puts "Current Distribution Certificate: #{cert.id}, Expiration date: #{expiration_date}"
  205. if expiration_date < Time.now
  206. puts "Distribution Certificate #{cert.id} is expired! Triggering action to renew certificate."
  207. new_certificate_needed = true
  208. else
  209. puts "Distribution certificate #{cert.id} is valid. No action required."
  210. end
  211. end
  212. end
  213. # Write result to new_certificate_needed.txt
  214. file_path = File.expand_path('new_certificate_needed.txt')
  215. File.write(file_path, new_certificate_needed ? 'true' : 'false')
  216. # Log the absolute path and contents of the new_certificate_needed.txt file
  217. puts ""
  218. puts "Absolute path of new_certificate_needed.txt: #{file_path}"
  219. new_certificate_needed_content = File.read(file_path)
  220. puts "Certificate creation or renewal needed: #{new_certificate_needed_content}"
  221. end
  222. end