Fastfile 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. # Define method to parse xcconfig file, and replace $(DEVELOPMENT_TEAM) with ENV["TEAMID"]
  24. def parse_xcconfig_file(path)
  25. xcconfig = {}
  26. File.open(path).each_line do |line|
  27. line.strip!
  28. next if line.empty? || line.start_with?('//')
  29. parts = line.split('=')
  30. next if parts.length < 2 # Skip lines without '='
  31. key, value = parts.map(&:strip)
  32. # Replace $(DEVELOPMENT_TEAM) with ENV["TEAMID"]
  33. value = value.gsub('$(DEVELOPMENT_TEAM)', TEAMID)
  34. xcconfig[key] = value
  35. end
  36. xcconfig
  37. end
  38. # Path to config.xcconfig file
  39. xcconfig_path = "#{GITHUB_WORKSPACE}/Config.xcconfig"
  40. # Load the variables from config.xcconfig
  41. xcconfig = parse_xcconfig_file(xcconfig_path)
  42. # Access BUNDLE_IDENTIFIER from the xcconfig file after replacing $(DEVELOPMENT_TEAM) with ENV["TEAMID"]
  43. ENV["BUNDLE_ID"] = xcconfig["BUNDLE_IDENTIFIER"]
  44. platform :ios do
  45. desc "Build iAPS"
  46. lane :build_iAPS do
  47. setup_ci if ENV['CI']
  48. BUNDLE_ID = ENV["BUNDLE_ID"]
  49. update_project_team(
  50. path: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj",
  51. teamid: "#{TEAMID}"
  52. )
  53. api_key = app_store_connect_api_key(
  54. key_id: "#{FASTLANE_KEY_ID}",
  55. issuer_id: "#{FASTLANE_ISSUER_ID}",
  56. key_content: "#{FASTLANE_KEY}"
  57. )
  58. previous_build_number = latest_testflight_build_number(
  59. app_identifier: "#{BUNDLE_ID}",
  60. api_key: api_key,
  61. )
  62. current_build_number = previous_build_number + 1
  63. increment_build_number(
  64. xcodeproj: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj",
  65. build_number: current_build_number
  66. )
  67. match(
  68. type: "appstore",
  69. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"),
  70. app_identifier: [
  71. "#{BUNDLE_ID}",
  72. "#{BUNDLE_ID}.watchkitapp",
  73. "#{BUNDLE_ID}.watchkitapp.watchkitextension"
  74. ]
  75. )
  76. previous_build_number = latest_testflight_build_number(
  77. app_identifier: "#{BUNDLE_ID}",
  78. api_key: api_key,
  79. )
  80. current_build_number = previous_build_number + 1
  81. increment_build_number(
  82. xcodeproj: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj",
  83. build_number: current_build_number
  84. )
  85. mapping = Actions.lane_context[
  86. SharedValues::MATCH_PROVISIONING_PROFILE_MAPPING
  87. ]
  88. update_code_signing_settings(
  89. path: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj",
  90. profile_name: mapping["#{BUNDLE_ID}"],
  91. code_sign_identity: "iPhone Distribution",
  92. targets: ["FreeAPS"]
  93. )
  94. update_code_signing_settings(
  95. path: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj",
  96. profile_name: mapping["#{BUNDLE_ID}.watchkitapp.watchkitextension"],
  97. code_sign_identity: "iPhone Distribution",
  98. targets: ["FreeAPSWatch WatchKit Extension"]
  99. )
  100. update_code_signing_settings(
  101. path: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj",
  102. profile_name: mapping["#{BUNDLE_ID}.watchkitapp"],
  103. code_sign_identity: "iPhone Distribution",
  104. targets: ["FreeAPSWatch"]
  105. )
  106. gym(
  107. export_method: "app-store",
  108. scheme: "FreeAPS X",
  109. output_name: "iAPS.ipa",
  110. configuration: "Release",
  111. destination: 'generic/platform=iOS',
  112. buildlog_path: 'buildlog'
  113. )
  114. copy_artifacts(
  115. target_path: "artifacts",
  116. artifacts: ["*.mobileprovision", "*.ipa", "*.dSYM.zip"]
  117. )
  118. end
  119. desc "Push to TestFlight"
  120. lane :release do
  121. api_key = app_store_connect_api_key(
  122. key_id: "#{FASTLANE_KEY_ID}",
  123. issuer_id: "#{FASTLANE_ISSUER_ID}",
  124. key_content: "#{FASTLANE_KEY}"
  125. )
  126. upload_to_testflight(
  127. api_key: api_key,
  128. skip_submission: false,
  129. ipa: "iAPS.ipa",
  130. skip_waiting_for_build_processing: true,
  131. )
  132. end
  133. desc "Provision Identifiers and Certificates"
  134. lane :identifiers do
  135. setup_ci if ENV['CI']
  136. ENV["MATCH_READONLY"] = false.to_s
  137. BUNDLE_ID = ENV["BUNDLE_ID"]
  138. app_store_connect_api_key(
  139. key_id: "#{FASTLANE_KEY_ID}",
  140. issuer_id: "#{FASTLANE_ISSUER_ID}",
  141. key_content: "#{FASTLANE_KEY}"
  142. )
  143. def configure_bundle_id(name, identifier, capabilities)
  144. bundle_id = Spaceship::ConnectAPI::BundleId.find(identifier) || Spaceship::ConnectAPI::BundleId.create(name: name, identifier: identifier)
  145. capabilities.each { |capability|
  146. bundle_id.create_capability(capability)
  147. }
  148. end
  149. configure_bundle_id("FreeAPS", "#{BUNDLE_ID}", [
  150. Spaceship::ConnectAPI::BundleIdCapability::Type::APP_GROUPS,
  151. Spaceship::ConnectAPI::BundleIdCapability::Type::HEALTHKIT,
  152. Spaceship::ConnectAPI::BundleIdCapability::Type::NFC_TAG_READING
  153. ])
  154. configure_bundle_id("FreeAPSWatch WatchKit Extension", "#{BUNDLE_ID}.watchkitapp.watchkitextension", [
  155. Spaceship::ConnectAPI::BundleIdCapability::Type::APP_GROUPS,
  156. Spaceship::ConnectAPI::BundleIdCapability::Type::HEALTHKIT
  157. ])
  158. configure_bundle_id("FreeAPSWatch", "#{BUNDLE_ID}.watchkitapp", [
  159. Spaceship::ConnectAPI::BundleIdCapability::Type::APP_GROUPS
  160. ])
  161. end
  162. desc "Provision Certificates"
  163. lane :certs do
  164. setup_ci if ENV['CI']
  165. ENV["MATCH_READONLY"] = false.to_s
  166. BUNDLE_ID = ENV["BUNDLE_ID"]
  167. app_store_connect_api_key(
  168. key_id: "#{FASTLANE_KEY_ID}",
  169. issuer_id: "#{FASTLANE_ISSUER_ID}",
  170. key_content: "#{FASTLANE_KEY}"
  171. )
  172. match(
  173. type: "appstore",
  174. force: true,
  175. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"),
  176. app_identifier: [
  177. "#{BUNDLE_ID}",
  178. "#{BUNDLE_ID}.watchkitapp.watchkitextension",
  179. "#{BUNDLE_ID}.watchkitapp",
  180. ]
  181. )
  182. end
  183. desc "Validate Secrets"
  184. lane :validate_secrets do
  185. setup_ci if ENV['CI']
  186. ENV["MATCH_READONLY"] = true.to_s
  187. BUNDLE_ID = ENV["BUNDLE_ID"]
  188. app_store_connect_api_key(
  189. key_id: "#{FASTLANE_KEY_ID}",
  190. issuer_id: "#{FASTLANE_ISSUER_ID}",
  191. key_content: "#{FASTLANE_KEY}"
  192. )
  193. def find_bundle_id(identifier)
  194. bundle_id = Spaceship::ConnectAPI::BundleId.find(identifier)
  195. end
  196. find_bundle_id("#{BUNDLE_ID}")
  197. match(
  198. type: "appstore",
  199. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"),
  200. app_identifier: [],
  201. )
  202. end
  203. desc "Nuke Certs"
  204. lane :nuke_certs do
  205. setup_ci if ENV['CI']
  206. ENV["MATCH_READONLY"] = false.to_s
  207. app_store_connect_api_key(
  208. key_id: "#{FASTLANE_KEY_ID}",
  209. issuer_id: "#{FASTLANE_ISSUER_ID}",
  210. key_content: "#{FASTLANE_KEY}"
  211. )
  212. match_nuke(
  213. type: "appstore",
  214. team_id: "#{TEAMID}",
  215. skip_confirmation: true,
  216. git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}")
  217. )
  218. end
  219. end