diff --git a/.ruby-version b/.ruby-version index 59aa62c..73462a5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4.5 +2.5.1 diff --git a/config/locales/en.yml b/config/locales/en.yml index 67a3d59..eaa5168 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -157,12 +157,6 @@ en: start: 'Cleaning local Provisioning Profiles...' delete: 'Delete %{path}' finish: 'Finish cleaning local Provisionig Profiles' - analyze: - target_bundle_identifier: - prompt: | - Please input your app bundle identifier - Example: com.example.ios - ask: 'Enter your app bundle identifier: ' ios: build: error: diff --git a/deploygate.gemspec b/deploygate.gemspec index 348a8b6..43992c6 100644 --- a/deploygate.gemspec +++ b/deploygate.gemspec @@ -38,9 +38,9 @@ POST_INSTALL_MESSAGE spec.add_runtime_dependency 'sentry-raven', '~> 2.8' # ios build - spec.add_runtime_dependency 'fastlane', '~> 2.115' + spec.add_runtime_dependency 'fastlane', '~> 2.148.1' - spec.add_development_dependency 'bundler', '~> 1.17' + spec.add_development_dependency 'bundler', '>= 2.1.4', '< 3.0' spec.add_development_dependency 'rake', '~> 12.0' spec.add_development_dependency 'rspec', '~> 3.5' spec.add_development_dependency 'webmock', '~> 2.3' diff --git a/lib/deploygate/add_devices_server.rb b/lib/deploygate/add_devices_server.rb index f61eaa4..68f624b 100644 --- a/lib/deploygate/add_devices_server.rb +++ b/lib/deploygate/add_devices_server.rb @@ -1,8 +1,7 @@ module DeployGate class AddDevicesServer - def start(token, owner_name, bundle_id, distribution_key, args, options) - DeployGate::Xcode::MemberCenter.instance + def start(token, owner_name, bundle_id, distribution_key, member_center, args, options) options.server = false puts I18n.t('command_builder.add_devices.server.connecting') @@ -15,7 +14,7 @@ def start(token, owner_name, bundle_id, distribution_key, args, options) raise res[:message] end - websocket_setup(server, bundle_id, push_token, action, args, options) do |socket| + websocket_setup(server, bundle_id, push_token, action, member_center, args, options) do |socket| puts HighLine.color(I18n.t('command_builder.add_devices.server.start'), HighLine::GREEN) Workers::PeriodicTimer.new(60) do @@ -33,12 +32,12 @@ def start(token, owner_name, bundle_id, distribution_key, args, options) end end - def self.build(pool, bunlde_id, iphones, args, options) + def self.build(pool, bunlde_id, iphones, member_center, args, options) iphones.reject! { |iphone| iphone['is_registered'] } # remove udids if already registered devices = iphones.map do |iphone| udid = iphone['udid'] device_name= iphone['device_name'] - DeployGate::Xcode::MemberCenters::Device.new(udid, '', device_name) + DeployGate::Xcode::MemberCenters::Device.new(udid, '', device_name, member_center) end return if devices.empty? @@ -53,7 +52,7 @@ def self.build(pool, bunlde_id, iphones, args, options) private - def websocket_setup(server, bundle_id, push_token, target_action, args, options, &block) + def websocket_setup(server, bundle_id, push_token, target_action, member_center, args, options, &block) socket = SocketIO::Client::Simple.connect server socket.on :connect do socket.emit :subscribe, push_token @@ -72,7 +71,7 @@ def websocket_setup(server, bundle_id, push_token, target_action, args, options, data = JSON.parse(push_data['data']) iphones = data['iphones'] - DeployGate::AddDevicesServer.build(pool, bundle_id, iphones, args, options) + DeployGate::AddDevicesServer.build(pool, bundle_id, iphones, member_center, args, options) end end end diff --git a/lib/deploygate/command_builder.rb b/lib/deploygate/command_builder.rb index d7ca224..b524868 100644 --- a/lib/deploygate/command_builder.rb +++ b/lib/deploygate/command_builder.rb @@ -150,7 +150,7 @@ def error_handling(command, error) tags[:xcode_version] = version if version.present? puts '' - puts error_report(error, version, dg_version) + puts error_report(error, dg_version, version) if HighLine.agree(I18n.t('command_builder.error_handling.agree')) {|q| q.default = "y"} tags = { command: command, diff --git a/lib/deploygate/commands/add_devices.rb b/lib/deploygate/commands/add_devices.rb index ba35442..83c419f 100644 --- a/lib/deploygate/commands/add_devices.rb +++ b/lib/deploygate/commands/add_devices.rb @@ -21,22 +21,27 @@ def run(args, options) distribution_key = options.distribution_key server = options.server - bundle_id = bundle_id(work_dir, options.configuration) + root_path = DeployGate::Xcode::Ios.project_root_path(work_dir) + workspaces = DeployGate::Xcode::Ios.find_workspaces(root_path) + analyze = DeployGate::Xcode::Analyze.new(workspaces, options.configuration) + bundle_id = analyze.target_bundle_identifier + developer_team = analyze.developer_team + member_center = DeployGate::Xcode::MemberCenter.new(developer_team) if server - run_server(session, owner, bundle_id, distribution_key, args, options) + run_server(session, owner, bundle_id, distribution_key, member_center, args, options) else - device_register(session, owner, udid, device_name, bundle_id, args, options) + device_register(session, owner, udid, device_name, bundle_id, member_center, args, options) end end - def run_server(session, owner, bundle_id, distribution_key, args, options) - DeployGate::AddDevicesServer.new().start(session.token, owner, bundle_id, distribution_key, args, options) + def run_server(session, owner, bundle_id, distribution_key, member_center, args, options) + DeployGate::AddDevicesServer.new().start(session.token, owner, bundle_id, distribution_key, member_center, args, options) end - def device_register(session, owner, udid, device_name, bundle_id, args, options) + def device_register(session, owner, udid, device_name, bundle_id, member_center, args, options) if udid.nil? && device_name.nil? - devices = fetch_devices(session.token, owner, bundle_id) + devices = fetch_devices(session.token, owner, bundle_id, member_center) select_devices = select_devices(devices) not_device if select_devices.empty? @@ -44,7 +49,7 @@ def device_register(session, owner, udid, device_name, bundle_id, args, options) else register_udid = udid || HighLine.ask(I18n.t('commands.add_devices.input_udid')) register_device_name = device_name || HighLine.ask(I18n.t('commands.add_devices.input_device_name')) - device = DeployGate::Xcode::MemberCenters::Device.new(register_udid, '', register_device_name) + device = DeployGate::Xcode::MemberCenters::Device.new(register_udid, '', register_device_name, member_center) puts device.to_s if HighLine.agree(I18n.t('commands.add_devices.device_register_confirm')) {|q| q.default = "y"} @@ -54,7 +59,7 @@ def device_register(session, owner, udid, device_name, bundle_id, args, options) end end - build!(bundle_id, args, options) + build!(bundle_id, member_center, args, options) end def register!(devices) @@ -64,18 +69,18 @@ def register!(devices) end end - def build!(bundle_id, args, options) - app = DeployGate::Xcode::MemberCenters::App.new(bundle_id) + def build!(bundle_id, member_center, args, options) + app = DeployGate::Xcode::MemberCenters::App.new(bundle_id, member_center) app.create! unless app.created? - DeployGate::Xcode::MemberCenters::ProvisioningProfile.new(bundle_id).create! - team = DeployGate::Xcode::MemberCenter.instance.team + DeployGate::Xcode::MemberCenters::ProvisioningProfile.new(bundle_id, member_center).create! + team = member_center.team DeployGate::Xcode::Export.clean_provisioning_profiles(bundle_id, team) DeployGate::Commands::Deploy::Build.run(args, options) end - def fetch_devices(token, owner, bundle_id) + def fetch_devices(token, owner, bundle_id, member_center) res = DeployGate::API::V1::Users::App.not_provisioned_udids(token, owner, bundle_id) if res[:error] case res[:message] @@ -89,21 +94,11 @@ def fetch_devices(token, owner, bundle_id) end results = res[:results] - devices = results.map{|r| DeployGate::Xcode::MemberCenters::Device.new(r[:udid], r[:user_name], r[:device_name])} + devices = results.map{|r| DeployGate::Xcode::MemberCenters::Device.new(r[:udid], r[:user_name], r[:device_name], member_center)} devices end - # @param [String] work_dir - # @param [String] build_configuration - # @return [String] - def bundle_id(work_dir, build_configuration) - root_path = DeployGate::Xcode::Ios.project_root_path(work_dir) - workspaces = DeployGate::Xcode::Ios.find_workspaces(root_path) - analyze = DeployGate::Xcode::Analyze.new(workspaces, build_configuration) - analyze.target_bundle_identifier - end - # @param [Array] # @return [Array] def select_devices(devices) diff --git a/lib/deploygate/commands/deploy/build.rb b/lib/deploygate/commands/deploy/build.rb index 7607d73..1a760ca 100644 --- a/lib/deploygate/commands/deploy/build.rb +++ b/lib/deploygate/commands/deploy/build.rb @@ -38,44 +38,24 @@ def ios(workspaces, options) analyze = DeployGate::Xcode::Analyze.new(workspaces, build_configuration, target_scheme) target_scheme = analyze.scheme - # TODO: Support export method option (ex: --method adhoc) - codesigning_identity= nil - provisioning_style = analyze.provisioning_style - provisioning_profile_info = nil - if (!over_xcode?(8) && provisioning_style == nil) || - provisioning_style == DeployGate::Xcode::Analyze::PROVISIONING_STYLE_MANUAL - - # Only run Provisioning Style is Manual or nil - bundle_identifier = analyze.target_bundle_identifier - xcode_provisioning_profile_uuid = analyze.target_xcode_setting_provisioning_profile_uuid - provisioning_team = analyze.provisioning_team - target_provisioning_profile = DeployGate::Xcode::Export.provisioning_profile( - bundle_identifier, - xcode_provisioning_profile_uuid, - provisioning_team - ) - - method = DeployGate::Xcode::Export.method(target_provisioning_profile) - codesigning_identity = DeployGate::Xcode::Export.codesigning_identity(target_provisioning_profile) - - profile = FastlaneCore::ProvisioningProfile.parse(target_provisioning_profile) - provisioning_profile_info = { - provisioningProfiles: { - "#{bundle_identifier}" => profile['Name'] - } - } - else - method = select_method + code_sign_identity = nil + project_profile_info = nil + allow_provisioning_updates = true + if analyze.code_sign_style == Xcode::Analyze::PROVISIONING_STYLE_MANUAL + code_sign_identity = analyze.code_sign_identity + project_profile_info = analyze.project_profile_info end + method = Xcode::Export.method(analyze.target_provisioning_profile) || select_method + ipa_path = DeployGate::Xcode::Ios.build( analyze, target_scheme, - codesigning_identity, - provisioning_profile_info, + code_sign_identity, + project_profile_info, build_configuration, method, - over_xcode?(9) && codesigning_identity.nil? + allow_provisioning_updates ) Push.upload([ipa_path], options) end diff --git a/lib/deploygate/version.rb b/lib/deploygate/version.rb index 999c422..a43c175 100644 --- a/lib/deploygate/version.rb +++ b/lib/deploygate/version.rb @@ -1,3 +1,3 @@ module DeployGate - VERSION = '0.7.0' + VERSION = '0.8.0' end diff --git a/lib/deploygate/xcode/analyze.rb b/lib/deploygate/xcode/analyze.rb index 59654ba..bc9f2e1 100644 --- a/lib/deploygate/xcode/analyze.rb +++ b/lib/deploygate/xcode/analyze.rb @@ -1,7 +1,7 @@ module DeployGate module Xcode class Analyze - attr_reader :workspaces, :scheme_workspace, :build_workspace, :scheme + attr_reader :workspaces, :scheme_workspace, :build_workspace, :scheme, :xcodeproj BASE_WORK_DIR_NAME = 'project.xcworkspace' DEFAULT_BUILD_CONFIGURATION = 'Release' @@ -23,153 +23,83 @@ def initialize(workspaces, build_configuration = nil, target_scheme = nil) @build_workspace = find_build_workspace(workspaces) @xcodeproj = File.dirname(@scheme_workspace) - config = FastlaneCore::Configuration.create(Gym::Options.available_options, { workspace: @scheme_workspace }) - project = FastlaneCore::Project.new(config) + config = FastlaneCore::Configuration.create(Gym::Options.available_options, { project: @xcodeproj }) + Gym.config = config + @project = FastlaneCore::Project.new(config) - if project.schemes.length > 1 && target_scheme && project.schemes.include?(target_scheme) - project.options[:scheme] = target_scheme + if @project.schemes.length > 1 && target_scheme && @project.schemes.include?(target_scheme) + @project.options[:scheme] = target_scheme else - project.select_scheme + @project.select_scheme end - @scheme = project.options[:scheme] + @scheme = @project.options[:scheme] end - # Support Xcode7 more - # @return [String] - def target_bundle_identifier - begin - product_name = target_product_name - product_bundle_identifier = target_build_configration.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] - product_bundle_identifier = convert_bundle_identifier(product_bundle_identifier) - - info_plist_file_path = target_build_configration.build_settings['INFOPLIST_FILE'] - root_path = DeployGate::Xcode::Ios.project_root_path(@scheme_workspace) - plist_bundle_identifier = - File.open(File.join(root_path, info_plist_file_path)) do |file| - plist = Plist.parse_xml file.read - plist['CFBundleIdentifier'] - end - plist_bundle_identifier = convert_bundle_identifier(plist_bundle_identifier) - - bundle_identifier = if plist_bundle_identifier.blank? - product_bundle_identifier - else - plist_bundle_identifier - end - bundle_identifier.gsub!(/\$\(PRODUCT_NAME:.+\)/, product_name) - rescue BundleIdentifierDifferentError => e - raise e - rescue => e - cli = HighLine.new - puts I18n.t('xcode.analyze.target_bundle_identifier.prompt') - bundle_identifier = cli.ask(I18n.t('xcode.analyze.target_bundle_identifier.ask')) { |q| q.validate = /^(\w+)\.(\w+).*\w$/ } + def code_sign_style + style = nil + resolve_build_configuration do |build_configuration, target| + style = build_configuration.resolve_build_setting("CODE_SIGN_STYLE", target) end - bundle_identifier + style end - # @param [String] bundle_identifier - # @return [String] - def convert_bundle_identifier(bundle_identifier) - new_bundle_identifier = bundle_identifier.gsub(/\$\(([^\)]+)\)|\${([^}]+)}/) { - custom_id = $1 || $2 - if custom_id == 'TARGET_NAME' - target_project_setting.name - else - target_build_configration.build_settings[custom_id] - end - } - # bail out if the result identical to the original - return bundle_identifier if new_bundle_identifier == bundle_identifier + def code_sign_identity + identity = nil + resolve_build_configuration do |build_configuration, target| + identity = build_configuration.resolve_build_setting("CODE_SIGN_IDENTITY", target) + end - convert_bundle_identifier(new_bundle_identifier) + identity end + # Support Xcode7 more # @return [String] - def target_xcode_setting_provisioning_profile_uuid - uuid = target_build_configration.build_settings['PROVISIONING_PROFILE'] - UUID.validate(uuid) ? uuid : nil - end - - def provisioning_style - target = target_provisioning_info - build_settings = target_build_configration.build_settings - - style = PROVISIONING_STYLE_MANUAL - if target - # Manual or Automatic or nil (Xcode7 below) - begin - style = target['ProvisioningStyle'] || build_settings['CODE_SIGN_STYLE'] - rescue - # Not catch error - end + def target_bundle_identifier + bundle_identifier = nil + resolve_build_configuration do |build_configuration, target| + bundle_identifier = build_configuration.resolve_build_setting("PRODUCT_BUNDLE_IDENTIFIER", target) end - style + bundle_identifier end - def provisioning_team - target = target_provisioning_info - + def developer_team team = nil - if target - begin - team = target['DevelopmentTeam'] - rescue - # Not catch error - end + resolve_build_configuration do |build_configuration, target| + team = build_configuration.resolve_build_setting("DEVELOPMENT_TEAM", target) end team end - private - - def target_provisioning_info - main_target = target_project_setting - main_target_uuid = main_target && main_target.uuid + def project_profile_info + gym = Gym::CodeSigningMapping.new(project: @project) - target = nil - if main_target_uuid - begin - target = target_project.root_object.attributes['TargetAttributes'][main_target_uuid] - rescue - # Not catch error - end - end - - target + { + provisioningProfiles: gym.detect_project_profile_mapping + } end - def target_build_configration - target_project_setting.build_configuration_list.build_configurations.reject{|conf| conf.name != @build_configuration}.first - end + def target_provisioning_profile + gym = Gym::CodeSigningMapping.new(project: @project) + bundle_id = target_bundle_identifier - def target_product_name - target_project_setting.product_name + Xcode::Export.provisioning_profile(bundle_id, nil, developer_team, gym.merge_profile_mapping[bundle_id.to_sym]) end - def target_project_setting - scheme_file = find_xcschemes - xs = Xcodeproj::XCScheme.new(scheme_file) - target_name = xs.profile_action.buildable_product_runnable.buildable_reference.target_name - - target_project.native_targets.reject{|target| target.name != target_name}.first - end + private - def target_project - Xcodeproj::Project.open(@xcodeproj) - end + def resolve_build_configuration(&block) + gym = Gym::CodeSigningMapping.new(project: @project) + specified_configuration = gym.detect_configuration_for_archive - def find_xcschemes - shared_schemes = Dir[File.join(@xcodeproj, 'xcshareddata', 'xcschemes', '*.xcscheme')].reject do |scheme| - @scheme != File.basename(scheme, '.xcscheme') - end - user_schemes = Dir[File.join(@xcodeproj, 'xcuserdata', '*.xcuserdatad', 'xcschemes', '*.xcscheme')].reject do |scheme| - @scheme != File.basename(scheme, '.xcscheme') + Xcodeproj::Project.open(@xcodeproj).targets.each do |target| + target.build_configuration_list.build_configurations.each do |build_configuration| + next if build_configuration.name != specified_configuration + block.call(build_configuration, target) + end end - - shared_schemes.concat(user_schemes).first end # @param [Array] workspaces diff --git a/lib/deploygate/xcode/export.rb b/lib/deploygate/xcode/export.rb index b32e229..a237d1f 100644 --- a/lib/deploygate/xcode/export.rb +++ b/lib/deploygate/xcode/export.rb @@ -12,12 +12,12 @@ class << self # @param [String] uuid # @param [String] provisioning_team # @return [String] - def provisioning_profile(bundle_identifier, uuid = nil, provisioning_team = nil) - local_teams = DeployGate::Xcode::Export.find_local_data(bundle_identifier, uuid, provisioning_team) + def provisioning_profile(bundle_identifier, uuid = nil, provisioning_team = nil, specifier_name = nil) + local_teams = DeployGate::Xcode::Export.find_local_data(bundle_identifier, uuid, provisioning_team, specifier_name) case local_teams.teams_count when 0 - target_provisioning_profile = create_provisioning(bundle_identifier, uuid) + target_provisioning_profile = create_provisioning(bundle_identifier, uuid, provisioning_team) when 1 target_provisioning_profile = select_profile(local_teams.first_team_profile_paths) else @@ -32,12 +32,13 @@ def provisioning_profile(bundle_identifier, uuid = nil, provisioning_team = nil) # @param [String] uuid # @param [String] provisioning_team # @return [LocalTeams] - def find_local_data(bundle_identifier, uuid = nil, provisioning_team = nil) + def find_local_data(bundle_identifier, uuid = nil, provisioning_team = nil, specifier_name = nil) local_teams = LocalTeams.new profile_paths = load_profile_paths profiles = profile_paths.map{|p| profile_to_plist(p)} profiles.reject! {|profile| profile['UUID'] != uuid} unless uuid.nil? + profiles.reject! {|profile| profile['Name'] != specifier_name} unless specifier_name.nil? profiles.each do |profile| next if DateTime.now >= profile['ExpirationDate'] || !installed_certificate?(profile['Path']) @@ -201,9 +202,10 @@ def profile_to_plist(profile_path) end end - def create_provisioning(identifier, uuid) - app = MemberCenters::App.new(identifier) - provisioning_prifile = MemberCenters::ProvisioningProfile.new(identifier) + def create_provisioning(identifier, uuid, team_id) + member_center = Xcode::MemberCenter.new(team_id) + app = MemberCenters::App.new(identifier, member_center) + provisioning_prifile = MemberCenters::ProvisioningProfile.new(identifier, member_center) begin unless app.created? diff --git a/lib/deploygate/xcode/ios.rb b/lib/deploygate/xcode/ios.rb index 209ffb4..3a858a7 100644 --- a/lib/deploygate/xcode/ios.rb +++ b/lib/deploygate/xcode/ios.rb @@ -28,7 +28,7 @@ def build(ios_analyze, values = { export_method: export_method, - workspace: ios_analyze.build_workspace, + project: ios_analyze.xcodeproj, configuration: build_configuration || DeployGate::Xcode::Analyze::DEFAULT_BUILD_CONFIGURATION, scheme: target_scheme } diff --git a/lib/deploygate/xcode/member_center.rb b/lib/deploygate/xcode/member_center.rb index c01339c..9265dff 100644 --- a/lib/deploygate/xcode/member_center.rb +++ b/lib/deploygate/xcode/member_center.rb @@ -1,15 +1,12 @@ -require 'singleton' - module DeployGate module Xcode class MemberCenter - include Singleton attr_reader :email, :method, :team, :launcher - def initialize + def initialize(team_id) @email = input_email @launcher = Spaceship::Launcher.new @email - @team = @launcher.select_team + @team = @launcher.select_team(team_id: team_id) if @launcher.client.in_house? @method = Export::ENTERPRISE diff --git a/lib/deploygate/xcode/member_centers/app.rb b/lib/deploygate/xcode/member_centers/app.rb index 8a87834..631863a 100644 --- a/lib/deploygate/xcode/member_centers/app.rb +++ b/lib/deploygate/xcode/member_centers/app.rb @@ -5,9 +5,10 @@ class App attr_reader :uuid, :member_center # @param [String] uuid + # @param [Xcode::MemberCenter] member_center # @return [DeployGate::Xcode::MemberCenters::App] - def initialize(uuid) - @member_center = DeployGate::Xcode::MemberCenter.instance + def initialize(uuid, member_center) + @member_center = member_center @uuid = uuid end diff --git a/lib/deploygate/xcode/member_centers/device.rb b/lib/deploygate/xcode/member_centers/device.rb index 1329936..07f2b38 100644 --- a/lib/deploygate/xcode/member_centers/device.rb +++ b/lib/deploygate/xcode/member_centers/device.rb @@ -5,29 +5,31 @@ class Device attr_reader :udid, :user_name ,:device_name, :member_center attr_accessor :register_name + REGISTER_NAME_MAX_LENGTH = 50 + # @param [String] udid # @param [String] user_name # @param [String] device_name + # @param [Xcode::MemberCenter] member_center # @return [DeployGate::Devices::Ios] - def initialize(udid, user_name, device_name) + def initialize(udid, user_name, device_name, member_center) @udid = udid @user_name = user_name @device_name = device_name + @member_center = member_center @register_name = generate_register_name(@user_name, @device_name) end def registered? - instance = DeployGate::Xcode::MemberCenter.instance - !instance.launcher.device.find_by_udid(@udid).nil? + !@member_center.launcher.device.find_by_udid(@udid).nil? end # @return [void] def register! - instance = DeployGate::Xcode::MemberCenter.instance return if registered? - instance.launcher.device.create!(name: @register_name, udid: @udid) + @member_center.launcher.device.create!(name: @register_name, udid: @udid) end # @return [String] @@ -42,7 +44,13 @@ def generate_register_name(user_name, device_name) name += "#{user_name} - " if !user_name.nil? && user_name != '' name += device_name - name + register_name_trim(name) + end + + # Device name must be 50 characters or less. + def register_name_trim(name) + return name if name.length <= REGISTER_NAME_MAX_LENGTH + name.slice(0, REGISTER_NAME_MAX_LENGTH) end end end diff --git a/lib/deploygate/xcode/member_centers/provisioning_profile.rb b/lib/deploygate/xcode/member_centers/provisioning_profile.rb index 058ea6b..1d074f9 100644 --- a/lib/deploygate/xcode/member_centers/provisioning_profile.rb +++ b/lib/deploygate/xcode/member_centers/provisioning_profile.rb @@ -12,8 +12,8 @@ class NotExistUUIDProvisioningProfileError < DeployGate::RavenIgnoreException OUTPUT_PATH = '/tmp/dg/provisioning_profile/' CERTIFICATE_OUTPUT_PATH = '/tmp/dg/certificate/' - def initialize(app_identifier) - @member_center = DeployGate::Xcode::MemberCenter.instance + def initialize(app_identifier, member_center) + @member_center = member_center @app_identifier = app_identifier FileUtils.mkdir_p(OUTPUT_PATH) diff --git a/spec/deploygate/xcode/analyze_spec.rb b/spec/deploygate/xcode/analyze_spec.rb index 173356f..6a168ff 100644 --- a/spec/deploygate/xcode/analyze_spec.rb +++ b/spec/deploygate/xcode/analyze_spec.rb @@ -1,59 +1,2 @@ describe DeployGate::Xcode::Analyze do - - context '#convert_bundle_identifier' do - - class DummyProject - SCHEME = 'dummy' - def schemes - [SCHEME, 'dummy2'] - end - - def options - {} - end - end - - class DummyProjectSetting - def name - 'TargetName' - end - end - - class DummyBuildConfigration - def build_settings - { - 'PRODUCT_NAME' => '$(TARGET_NAME)', - 'CUSTOM_KEY' => 'CustomKey', - 'PRODUCT_BUNDLE_IDENTIFER' => 'com.deploygate.app', - 'DEBUG_POSTFIX' => '.debug', - 'LOOP' => '$(LOOP)' - } - end - end - - before do - allow_any_instance_of(DeployGate::Xcode::Analyze).to receive(:find_scheme_workspace).and_return('') - allow_any_instance_of(DeployGate::Xcode::Analyze).to receive(:find_build_workspace) - allow_any_instance_of(DeployGate::Xcode::Analyze).to receive(:target_build_configration).and_return(DummyBuildConfigration.new) - allow_any_instance_of(DeployGate::Xcode::Analyze).to receive(:target_project_setting).and_return(DummyProjectSetting.new) - allow(FastlaneCore::Configuration).to receive(:create) - allow(FastlaneCore::Project).to receive(:new).and_return(DummyProject.new) - end - - it do - analyze = DeployGate::Xcode::Analyze.new('', nil, DummyProject::SCHEME) - expect(analyze.convert_bundle_identifier('com.deploygate.$(PRODUCT_NAME).${CUSTOM_KEY}')).to eq 'com.deploygate.TargetName.CustomKey' - end - - it 'if only env' do - analyze = DeployGate::Xcode::Analyze.new('', nil, DummyProject::SCHEME) - expect(analyze.convert_bundle_identifier('$(PRODUCT_BUNDLE_IDENTIFER)$(DEBUG_POSTFIX)')).to eq 'com.deploygate.app.debug' - end - - it 'if loop env' do - analyze = DeployGate::Xcode::Analyze.new('', nil, DummyProject::SCHEME) - expect(analyze.convert_bundle_identifier('$(LOOP)')).to eq '$(LOOP)' - end - end - end diff --git a/spec/deploygate/xcode/ios_spec.rb b/spec/deploygate/xcode/ios_spec.rb index 797f214..89b1f3e 100644 --- a/spec/deploygate/xcode/ios_spec.rb +++ b/spec/deploygate/xcode/ios_spec.rb @@ -9,6 +9,9 @@ class AnalyzeMock def build_workspace '' end + def xcodeproj + '' + end end end diff --git a/spec/deploygate/xcode/member_center_spec.rb b/spec/deploygate/xcode/member_center_spec.rb index f53a784..415b8bf 100644 --- a/spec/deploygate/xcode/member_center_spec.rb +++ b/spec/deploygate/xcode/member_center_spec.rb @@ -5,7 +5,7 @@ def in_house? end let(:email) { 'test@example.com' } - let(:center) { DeployGate::Xcode::MemberCenter.instance } + let(:center) { DeployGate::Xcode::MemberCenter.new('com-example-team-id') } before do allow_any_instance_of(Spaceship::PortalClient).to receive(:login) {} allow_any_instance_of(Spaceship::PortalClient).to receive(:teams) {['team_name', 'team_id']} diff --git a/spec/deploygate/xcode/member_centers/app_spec.rb b/spec/deploygate/xcode/member_centers/app_spec.rb index 806a5e2..719ae5c 100644 --- a/spec/deploygate/xcode/member_centers/app_spec.rb +++ b/spec/deploygate/xcode/member_centers/app_spec.rb @@ -2,7 +2,8 @@ let(:email) { 'test@example.com' } let(:registered_uuid) { 'com.example.test.registered' } let(:non_registered_uuid) { 'com.example.test.non.registered' } - let(:app) { DeployGate::Xcode::MemberCenters::App.new('com.example.test.new.app') } + let(:member_center) { DeployGate::Xcode::MemberCenter.new('com-example-team-id') } + let(:app) { DeployGate::Xcode::MemberCenters::App.new('com.example.test.new.app', member_center) } before do allow_any_instance_of(Spaceship::PortalClient).to receive(:login) {} @@ -18,13 +19,13 @@ context "#created?" do it "app created" do - app = DeployGate::Xcode::MemberCenters::App.new(registered_uuid) + app = DeployGate::Xcode::MemberCenters::App.new(registered_uuid, member_center) expect(app.created?).to be_truthy end it "no app created" do - app = DeployGate::Xcode::MemberCenters::App.new(non_registered_uuid) + app = DeployGate::Xcode::MemberCenters::App.new(non_registered_uuid, member_center) expect(app.created?).to be_falsey end