Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[match][sigh] speed up profiles fetching by adding name filter to the API calls #21016

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions match/lib/match/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,14 @@ def fetch_provisioning_profile(params: nil, certificate_id: nil, app_identifier:
end
parsed = FastlaneCore::ProvisioningProfile.parse(profile, keychain_path)
uuid = parsed["UUID"]
name = parsed["Name"]

if params[:output_path]
FileUtils.cp(profile, params[:output_path])
end

if spaceship && !spaceship.profile_exists(type: prov_type,
name: name,
username: params[:username],
uuid: uuid,
platform: params[:platform])
Expand Down Expand Up @@ -352,8 +354,10 @@ def device_count_different?(profile: nil, keychain_path: nil, platform: nil, inc

parsed = FastlaneCore::ProvisioningProfile.parse(profile, keychain_path)
uuid = parsed["UUID"]
name = parsed["Name"]

all_profiles = Spaceship::ConnectAPI::Profile.all(includes: "devices")
# Filtering by name allows us to filter out profiles way faster than querying all profiles
all_profiles = Spaceship::ConnectAPI::Profile.all(filter: { name: name }, includes: "devices")
portal_profile = all_profiles.detect { |i| i.uuid == uuid }

if portal_profile
Expand Down Expand Up @@ -427,8 +431,10 @@ def certificate_count_different?(profile: nil, keychain_path: nil, platform: nil

parsed = FastlaneCore::ProvisioningProfile.parse(profile, keychain_path)
uuid = parsed["UUID"]
name = parsed["Name"]

all_profiles = Spaceship::ConnectAPI::Profile.all(includes: "certificates")
# Filtering by name allows us to filter out profiles way faster than querying all profiles
all_profiles = Spaceship::ConnectAPI::Profile.all(filter: { name: name }, includes: "certificates")
portal_profile = all_profiles.detect { |i| i.uuid == uuid }

return false unless portal_profile
Expand Down
6 changes: 4 additions & 2 deletions match/lib/match/spaceship_ensure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ def certificates_exists(username: nil, certificate_ids: [])
UI.user_error!("To reset the certificates of your Apple account, you can use the `fastlane match nuke` feature, more information on https://docs.fastlane.tools/actions/match/")
end

def profile_exists(type: nil, username: nil, uuid: nil, platform: nil)
def profile_exists(type: nil, name: nil, username: nil, uuid: nil, platform: nil)
# App Store Connect API does not allow filter of profile by platform or uuid (as of 2020-07-30)
# Need to fetch all profiles and search for uuid on client side
# But we can filter provisioning profiles based on their type (this, in general way faster than getting all profiles)
filter = { profileType: Match.profile_types(type).join(",") } if type
filter = {}
filter[:profileType] = Match.profile_types(type).join(",") if type
filter[:name] = name if name
found = Spaceship::ConnectAPI::Profile.all(filter: filter).find do |profile|
profile.uuid == uuid
end
Expand Down
12 changes: 8 additions & 4 deletions sigh/lib/sigh/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ def profile_type
def fetch_profiles
UI.message("Fetching profiles...")

# Filtering on 'profileType' seems to be undocumented as of 2020-07-30
# but works on both web session and official API
results = Spaceship::ConnectAPI::Profile.all(filter: { profileType: profile_type }, includes: "bundleId,certificates").select do |profile|
filter = { profileType: profile_type }
# We can greatly speed up the search by filtering on the provisioning profile name
filter[:name] = Sigh.config[:provisioning_name] if Sigh.config[:provisioning_name].to_s.length > 0

results = Spaceship::ConnectAPI::Profile.all(filter: filter, includes: "bundleId,certificates").select do |profile|
profile.bundle_id.identifier == Sigh.config[:app_identifier]
end

Expand Down Expand Up @@ -166,7 +168,9 @@ def create_profile!
name = Sigh.config[:provisioning_name] || [app_identifier, profile_type_pretty_type].join(' ')

unless Sigh.config[:skip_fetch_profiles]
profile = Spaceship::ConnectAPI::Profile.all.find { |p| p.name == name }
# We can greatly speed up the search by filtering on the provisioning profile name
# It seems that there's no way to search for exact match using the API, so we'll need to run additional checks afterwards
profile = Spaceship::ConnectAPI::Profile.all(filter: { name: name }).find { |p| p.name == name }
if profile
UI.user_error!("The name '#{name}' is already taken, and fail_on_name_taken is true") if Sigh.config[:fail_on_name_taken]
UI.error("The name '#{name}' is already taken, using another one.")
Expand Down