lib/match/runner.rb in match-0.9.0 vs lib/match/runner.rb in match-0.10.0

- old
+ new

@@ -1,18 +1,19 @@ module Match class Runner attr_accessor :changes_to_commit + attr_accessor :spaceship def run(params) FastlaneCore::PrintTable.print_values(config: params, hide_keys: [:workspace], title: "Summary for match #{Match::VERSION}") UI.error("Enterprise profiles are currently not officially supported in _match_, you might run into issues") if Match.enterprise? params[:workspace] = GitHelper.clone(params[:git_url], params[:shallow_clone], skip_docs: params[:skip_docs], branch: params[:git_branch]) - spaceship = SpaceshipEnsure.new(params[:username]) unless params[:readonly] + self.spaceship = SpaceshipEnsure.new(params[:username]) unless params[:readonly] if params[:app_identifier].kind_of?(Array) app_identifiers = params[:app_identifier] else app_identifiers = params[:app_identifier].to_s.split(/\s*,\s*/).uniq @@ -29,14 +30,15 @@ cert_id = fetch_certificate(params: params) spaceship.certificate_exists(username: params[:username], certificate_id: cert_id) if spaceship # Provisioning Profiles app_identifiers.each do |app_identifier| - uuid = fetch_provisioning_profile(params: params, - certificate_id: cert_id, - app_identifier: app_identifier) - spaceship.profile_exists(username: params[:username], uuid: uuid) if spaceship + loop do + break if fetch_provisioning_profile(params: params, + certificate_id: cert_id, + app_identifier: app_identifier) + end end # Done if self.changes_to_commit and !params[:readonly] message = GitHelper.generate_commit_message(params) @@ -58,13 +60,11 @@ ensure GitHelper.clear_changes end def fetch_certificate(params: nil) - cert_type = :distribution - cert_type = :development if params[:type] == "development" - cert_type = :enterprise if Match.enterprise? && params[:type] == "enterprise" + cert_type = Match.cert_type_sym(params[:type]) certs = Dir[File.join(params[:workspace], "certs", cert_type.to_s, "*.cer")] keys = Dir[File.join(params[:workspace], "certs", cert_type.to_s, "*.p12")] if certs.count == 0 or keys.count == 0 @@ -90,24 +90,33 @@ return File.basename(cert_path).gsub(".cer", "") # Certificate ID end # @return [String] The UUID of the provisioning profile so we can verify it with the Apple Developer Portal def fetch_provisioning_profile(params: nil, certificate_id: nil, app_identifier: nil) - prov_type = params[:type].to_sym + prov_type = Match.profile_type_sym(params[:type]) profile_name = [Match::Generator.profile_type_name(prov_type), app_identifier].join("_").gsub("*", '\*') # this is important, as it shouldn't be a wildcard - profiles = Dir[File.join(params[:workspace], "profiles", prov_type.to_s, "#{profile_name}.mobileprovision")] + base_dir = File.join(params[:workspace], "profiles", prov_type.to_s) + profiles = Dir[File.join(base_dir, "#{profile_name}.mobileprovision")] # Install the provisioning profiles profile = profiles.last if params[:force_for_new_devices] && !params[:readonly] params[:force] = device_count_different?(profile: profile) unless params[:force] end if profile.nil? or params[:force] - UI.user_error!("No matching provisioning profiles found and can not create a new one because you enabled `readonly`") if params[:readonly] + if params[:readonly] + all_profiles = Dir.entries(base_dir).reject { |f| f.start_with? "." } + UI.error "No matching provisioning profiles found for '#{profile_name}'" + UI.error "A new one cannot be created because you enabled `readonly`" + UI.error "Provisioning profiles in your repo for type `#{prov_type}`:" + all_profiles.each { |p| UI.error "- '#{p}'" } + UI.error "If you are certain that a profile should exist, double-check the recent changes to your match repository" + UI.user_error! "No matching provisioning profiles found and can not create a new one because you enabled `readonly`. Check the output above for more information." + end profile = Generator.generate_provisioning_profile(params: params, prov_type: prov_type, certificate_id: certificate_id, app_identifier: app_identifier) self.changes_to_commit = true @@ -115,9 +124,16 @@ FastlaneCore::ProvisioningProfile.install(profile) parsed = FastlaneCore::ProvisioningProfile.parse(profile) uuid = parsed["UUID"] + + if spaceship && !spaceship.profile_exists(username: params[:username], uuid: uuid) + # This profile is invalid, let's remove the local file and generate a new one + File.delete(profile) + self.changes_to_commit = true + return nil + end Utils.fill_environment(Utils.environment_variable_name(app_identifier: app_identifier, type: prov_type), uuid)