Class: Fastlane::Actions::UpdateProjectTeamAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/update_project_team.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



80
81
82
# File 'fastlane/lib/fastlane/actions/update_project_team.rb', line 80

def self.authors
  ["lgaches", "iBotPeaches"]
end

.available_optionsObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'fastlane/lib/fastlane/actions/update_project_team.rb', line 56

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :path,
                                 env_name: "FL_PROJECT_SIGNING_PROJECT_PATH",
                                 description: "Path to your Xcode project",
                                 default_value: Dir['*.xcodeproj'].first,
                                 default_value_dynamic: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Path is invalid") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :targets,
                                 env_name: "FL_PROJECT_TARGET",
                                 description: "Name of the targets you want to update",
                                 type: Array,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :teamid,
                                 env_name: "FL_PROJECT_TEAM_ID",
                                 description: "The Team ID you want to use",
                                 code_gen_sensitive: true,
                                 default_value: ENV["TEAM_ID"] || CredentialsManager::AppfileConfig.try_fetch_value(:team_id),
                                 default_value_dynamic: true)
  ]
end

.categoryObject



98
99
100
# File 'fastlane/lib/fastlane/actions/update_project_team.rb', line 98

def self.category
  :project
end

.descriptionObject



48
49
50
# File 'fastlane/lib/fastlane/actions/update_project_team.rb', line 48

def self.description
  "Update Xcode Development Team ID"
end

.detailsObject



52
53
54
# File 'fastlane/lib/fastlane/actions/update_project_team.rb', line 52

def self.details
  "This action updates (or adds) the Developer Team ID of your Xcode project."
end

.example_codeObject



88
89
90
91
92
93
94
95
96
# File 'fastlane/lib/fastlane/actions/update_project_team.rb', line 88

def self.example_code
  [
    'update_project_team',
    'update_project_team(
      path: "Example.xcodeproj",
      teamid: "A3ZZVJ7CNY"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



84
85
86
# File 'fastlane/lib/fastlane/actions/update_project_team.rb', line 84

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'fastlane/lib/fastlane/actions/update_project_team.rb', line 7

def self.run(params)
  project_path = params[:path]
  selected_targets = params[:targets]

  # Load .xcodeproj
  project = Fastlane::Helper::XcodeprojHelper.get_project!(project_path)

  # Fetch target
  targets = project.native_targets
  if selected_targets
    # Error to user if invalid target
    diff_targets = selected_targets - targets.map(&:name)
    UI.user_error!("Could not find target(s) in the project '#{project_path}' - #{diff_targets.join(',')}") unless diff_targets.empty?

    targets.select! { |native_target| selected_targets.include?(native_target.name) }
  end

  # Set teamid in target
  targets.each do |target|
    target.build_configurations.each do |configuration|
      # Iterate over any keys that start with DEVELOPMENT_TEAM
      # This will also set keys that have filtering like [sdk=iphoneos*]
      keys = configuration.build_settings.keys.select { |key| key.to_s.start_with?("DEVELOPMENT_TEAM") }
      keys.each do |key|
        configuration.build_settings[key] = params[:teamid]
        UI.message("Updated build setting '#{key}' to '#{params[:teamid]}' for configuration '#{configuration.name}'")
      end

      # Explicitly set the key with value if keys don't exist
      unless keys.include?('DEVELOPMENT_TEAM')
        configuration.build_settings['DEVELOPMENT_TEAM'] = params[:teamid]
        UI.message("Added build setting 'DEVELOPMENT_TEAM' with value '#{params[:teamid]}' for configuration '#{configuration.name}'")
      end
    end

    project.save

    UI.success("Successfully updated project settings to use Developer Team ID '#{params[:teamid]}' for target `#{target.name}`")
  end
end