From 419c13a6b393cae94147e11b45d3c92038a5565b Mon Sep 17 00:00:00 2001 From: bjornoleh <63544115+bjornoleh@users.noreply.github.com> Date: Mon, 18 Mar 2024 22:48:08 +0100 Subject: [PATCH] Fastfile: Parse Config.xcconfig to get BUNDLE_IDENTIFIER - Replace $(DEVELOPMENT_TEAM) parsed from BUNDLE_IDENTIFIER in Config.xcconfig with ENV["TEAMID"] - Use BUNDLE_ID instead of hard coded bundle identifier in Fastfile, inspired by Artificial-Pancreas/iAPS 6a46a2a by @Jon-b-m - Allows building of different instances of the app by only editing Config.xcconfig. --- fastlane/Fastfile | 62 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 295135f3b..f487b5c9c 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -23,11 +23,38 @@ DEVICE_NAME = ENV["DEVICE_NAME"] DEVICE_ID = ENV["DEVICE_ID"] ENV["FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT"] = "120" + +# Define method to parse xcconfig file, and replace $(DEVELOPMENT_TEAM) with ENV["TEAMID"] +def parse_xcconfig_file(path) + xcconfig = {} + File.open(path).each_line do |line| + line.strip! + next if line.empty? || line.start_with?('//') + parts = line.split('=') + next if parts.length < 2 # Skip lines without '=' + key, value = parts.map(&:strip) + # Replace $(DEVELOPMENT_TEAM) with ENV["TEAMID"] + value = value.gsub('$(DEVELOPMENT_TEAM)', TEAMID) + xcconfig[key] = value + end + xcconfig + end + +# Path to config.xcconfig file +xcconfig_path = "#{GITHUB_WORKSPACE}/Config.xcconfig" + +# Load the variables from config.xcconfig +xcconfig = parse_xcconfig_file(xcconfig_path) + +# Access BUNDLE_IDENTIFIER from the xcconfig file after replacing $(DEVELOPMENT_TEAM) with ENV["TEAMID"] +ENV["BUNDLE_ID"] = xcconfig["BUNDLE_IDENTIFIER"] + platform :ios do desc "Build iAPS" lane :build_iAPS do setup_ci if ENV['CI'] - + BUNDLE_ID = ENV["BUNDLE_ID"] + update_project_team( path: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj", teamid: "#{TEAMID}" @@ -40,7 +67,7 @@ platform :ios do ) previous_build_number = latest_testflight_build_number( - app_identifier: "ru.artpancreas.#{TEAMID}.FreeAPS", + app_identifier: "#{BUNDLE_ID}", api_key: api_key, ) @@ -55,14 +82,14 @@ platform :ios do type: "appstore", git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"), app_identifier: [ - "ru.artpancreas.#{TEAMID}.FreeAPS", - "ru.artpancreas.#{TEAMID}.FreeAPS.watchkitapp", - "ru.artpancreas.#{TEAMID}.FreeAPS.watchkitapp.watchkitextension" + "#{BUNDLE_ID}", + "#{BUNDLE_ID}.watchkitapp", + "#{BUNDLE_ID}.watchkitapp.watchkitextension" ] ) previous_build_number = latest_testflight_build_number( - app_identifier: "ru.artpancreas.#{TEAMID}.FreeAPS", + app_identifier: "#{BUNDLE_ID}", api_key: api_key, ) @@ -79,21 +106,21 @@ platform :ios do update_code_signing_settings( path: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj", - profile_name: mapping["ru.artpancreas.#{TEAMID}.FreeAPS"], + profile_name: mapping["#{BUNDLE_ID}"], code_sign_identity: "iPhone Distribution", targets: ["FreeAPS"] ) update_code_signing_settings( path: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj", - profile_name: mapping["ru.artpancreas.#{TEAMID}.FreeAPS.watchkitapp.watchkitextension"], + profile_name: mapping["#{BUNDLE_ID}.watchkitapp.watchkitextension"], code_sign_identity: "iPhone Distribution", targets: ["FreeAPSWatch WatchKit Extension"] ) update_code_signing_settings( path: "#{GITHUB_WORKSPACE}/FreeAPS.xcodeproj", - profile_name: mapping["ru.artpancreas.#{TEAMID}.FreeAPS.watchkitapp"], + profile_name: mapping["#{BUNDLE_ID}.watchkitapp"], code_sign_identity: "iPhone Distribution", targets: ["FreeAPSWatch"] ) @@ -133,6 +160,7 @@ platform :ios do lane :identifiers do setup_ci if ENV['CI'] ENV["MATCH_READONLY"] = false.to_s + BUNDLE_ID = ENV["BUNDLE_ID"] app_store_connect_api_key( key_id: "#{FASTLANE_KEY_ID}", @@ -147,18 +175,18 @@ platform :ios do } end - configure_bundle_id("FreeAPS", "ru.artpancreas.#{TEAMID}.FreeAPS", [ + configure_bundle_id("FreeAPS", "#{BUNDLE_ID}", [ Spaceship::ConnectAPI::BundleIdCapability::Type::APP_GROUPS, Spaceship::ConnectAPI::BundleIdCapability::Type::HEALTHKIT, Spaceship::ConnectAPI::BundleIdCapability::Type::NFC_TAG_READING ]) - configure_bundle_id("FreeAPSWatch WatchKit Extension", "ru.artpancreas.#{TEAMID}.FreeAPS.watchkitapp.watchkitextension", [ + configure_bundle_id("FreeAPSWatch WatchKit Extension", "#{BUNDLE_ID}.watchkitapp.watchkitextension", [ Spaceship::ConnectAPI::BundleIdCapability::Type::APP_GROUPS, Spaceship::ConnectAPI::BundleIdCapability::Type::HEALTHKIT ]) - configure_bundle_id("FreeAPSWatch", "ru.artpancreas.#{TEAMID}.FreeAPS.watchkitapp", [ + configure_bundle_id("FreeAPSWatch", "#{BUNDLE_ID}.watchkitapp", [ Spaceship::ConnectAPI::BundleIdCapability::Type::APP_GROUPS ]) @@ -168,6 +196,7 @@ platform :ios do lane :certs do setup_ci if ENV['CI'] ENV["MATCH_READONLY"] = false.to_s + BUNDLE_ID = ENV["BUNDLE_ID"] app_store_connect_api_key( key_id: "#{FASTLANE_KEY_ID}", @@ -180,9 +209,9 @@ platform :ios do force: true, git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"), app_identifier: [ - "ru.artpancreas.#{TEAMID}.FreeAPS", - "ru.artpancreas.#{TEAMID}.FreeAPS.watchkitapp.watchkitextension", - "ru.artpancreas.#{TEAMID}.FreeAPS.watchkitapp", + "#{BUNDLE_ID}", + "#{BUNDLE_ID}.watchkitapp.watchkitextension", + "#{BUNDLE_ID}.watchkitapp", ] ) end @@ -191,6 +220,7 @@ platform :ios do lane :validate_secrets do setup_ci if ENV['CI'] ENV["MATCH_READONLY"] = true.to_s + BUNDLE_ID = ENV["BUNDLE_ID"] app_store_connect_api_key( key_id: "#{FASTLANE_KEY_ID}", @@ -202,7 +232,7 @@ platform :ios do bundle_id = Spaceship::ConnectAPI::BundleId.find(identifier) end - find_bundle_id("ru.artpancreas.#{TEAMID}.FreeAPS") + find_bundle_id("#{BUNDLE_ID}") end desc "Nuke Certs"