Skip to content

Commit

Permalink
Merge pull request #17 from bjornoleh/fastlane_bundle_id
Browse files Browse the repository at this point in the history
Get BUNDLE_IDENTIFIER from Config.xcconfig for use in Fastfile
  • Loading branch information
bjornoleh committed Mar 30, 2024
2 parents 2b4e28e + b9015c5 commit 1d3c8f0
Showing 1 changed file with 46 additions and 16 deletions.
62 changes: 46 additions & 16 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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,
)

Expand All @@ -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,
)

Expand All @@ -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"]
)
Expand Down Expand Up @@ -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}",
Expand All @@ -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
])

Expand All @@ -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}",
Expand All @@ -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
Expand All @@ -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}",
Expand All @@ -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}")

match(
type: "appstore",
Expand Down

0 comments on commit 1d3c8f0

Please sign in to comment.