Skip to content

Commit

Permalink
Merge pull request fastlane-old#102 from WinterKirk/master
Browse files Browse the repository at this point in the history
Add force_for_new_devices option to renew profile if device count differs
  • Loading branch information
KrauseFx committed Feb 8, 2016
2 parents 0de6a3e + b537d5c commit 004ba71
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/match/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def self.available_options
end
end
end,
optional: true)
optional: true),
FastlaneCore::ConfigItem.new(key: :force_for_new_devices,
env_name: "MATCH_FORCE_FOR_NEW_DEVICES",
description: "Renew the provisioning profiles if the device count on the developer portal has changed",
is_string: false,
default_value: false)
]
end
end
Expand Down
17 changes: 17 additions & 0 deletions lib/match/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def profile(params: nil, certificate_id: nil)

# Install the provisioning profiles
profile = profiles.last
params[:force] = device_count_different?(profile: profile) unless params[:force]

if profile.nil? or params[:force]
UI.crash!("No matching provisioning profiles found and can not create a new one because you enabled `readonly`") if params[:readonly]
profile = Generator.generate_provisioning_profile(params: params,
Expand All @@ -90,5 +92,20 @@ def profile(params: nil, certificate_id: nil)

return uuid
end

def device_count_different?(profile: nil)
if profile
parsed = FastlaneCore::ProvisioningProfile.parse(profile)
uuid = parsed["UUID"]
portal_profile = Spaceship.provisioning_profile.all.detect { |i| i.uuid == uuid }

if portal_profile
profile_device_count = portal_profile.devices.count
portal_device_count = Spaceship.device.all.count
return portal_device_count != profile_device_count
end
end
return false
end
end
end
4 changes: 4 additions & 0 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
expect(spaceship).to receive(:profile_exists).and_return(true)
expect(spaceship).to receive(:bundle_identifier_exists).and_return(true)

profiles = "profiles"
expect(Spaceship).to receive(:provisioning_profile).and_return(profiles)
expect(profiles).to receive(:all).and_return([])

Match::Runner.new.run(config)
end
end
Expand Down

0 comments on commit 004ba71

Please sign in to comment.