Fastfile 8.3 KB

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