Class: Fastlane::Actions::UpdateCodeSigningSettingsAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/update_code_signing_settings.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, return_type, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



214
215
216
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 214

def self.authors
  ["mathiasAichinger", "hjanuschka", "p4checo", "portellaa", "aeons", "att55", "abcdev"]
end

.available_optionsObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 120

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :path,
                                 env_name: "FL_PROJECT_SIGNING_PROJECT_PATH",
                                 description: "Path to your Xcode project",
                                 code_gen_sensitive: true,
                                 default_value: Dir['*.xcodeproj'].first,
                                 default_value_dynamic: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Path is invalid") unless File.exist?(File.expand_path(value))
                                 end),
    FastlaneCore::ConfigItem.new(key: :use_automatic_signing,
                                 env_name: "FL_PROJECT_USE_AUTOMATIC_SIGNING",
                                 description: "Defines if project should use automatic signing",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :sdk,
                                 env_name: "FASTLANE_BUILD_SDK",
                                 optional: true,
                                 description: "Build target SDKs (iphoneos*, macosx*, iphonesimulator*)"),
    FastlaneCore::ConfigItem.new(key: :team_id,
                                 env_name: "FASTLANE_TEAM_ID",
                                 optional: true,
                                 description: "Team ID, is used when upgrading project"),
    FastlaneCore::ConfigItem.new(key: :targets,
                                 env_name: "FL_PROJECT_SIGNING_TARGETS",
                                 optional: true,
                                 type: Array,
                                 description: "Specify targets you want to toggle the signing mech. (default to all targets)"),
    FastlaneCore::ConfigItem.new(key: :build_configurations,
                                 env_name: "FL_PROJECT_SIGNING_BUILD_CONFIGURATIONS",
                                 optional: true,
                                 type: Array,
                                 description: "Specify build_configurations you want to toggle the signing mech. (default to all configurations)"),
    FastlaneCore::ConfigItem.new(key: :code_sign_identity,
                                 env_name: "FL_CODE_SIGN_IDENTITY",
                                 description: "Code signing identity type (iPhone Developer, iPhone Distribution)",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :entitlements_file_path,
                                 env_name: "FL_CODE_SIGN_ENTITLEMENTS_FILE_PATH",
                                 description: "Path to your entitlements file",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :profile_name,
                                 env_name: "FL_PROVISIONING_PROFILE_SPECIFIER",
                                 description: "Provisioning profile name to use for code signing",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :profile_uuid,
                                 env_name: "FL_PROVISIONING_PROFILE",
                                 description: "Provisioning profile UUID to use for code signing",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :bundle_identifier,
                                 env_name: "FL_APP_IDENTIFIER",
                                 description: "Application Product Bundle Identifier",
                                 optional: true)
  ]
end

.categoryObject



206
207
208
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 206

def self.category
  :code_signing
end

.descriptionObject



112
113
114
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 112

def self.description
  "Configures Xcode's Codesigning options"
end

.detailsObject



116
117
118
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 116

def self.details
  "Configures Xcode's Codesigning options of all targets in the project"
end

.example_codeObject



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 180

def self.example_code
  [
    ' # manual code signing
    update_code_signing_settings(
      use_automatic_signing: false,
      path: "demo-project/demo/demo.xcodeproj"
    )',
    ' # automatic code signing
    update_code_signing_settings(
      use_automatic_signing: true,
      path: "demo-project/demo/demo.xcodeproj"
    )',
    ' # more advanced manual code signing
    update_code_signing_settings(
      use_automatic_signing: false,
      path: "demo-project/demo/demo.xcodeproj",
      team_id: "QABC123DEV",
      bundle_identifier: "com.demoapp.QABC123DEV",
      code_sign_identity: "iPhone Distribution",
      sdk: "iphoneos*",
      profile_name: "Demo App Deployment Profile",
      entitlements_file_path: "Demo App/generated/New.entitlements"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



218
219
220
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 218

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

.outputObject



177
178
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 177

def self.output
end

.return_valueObject



210
211
212
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 210

def self.return_value
  "The current status (boolean) of codesigning after modification"
end

.run(params) ⇒ Object



5
6
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 5

def self.run(params)
  FastlaneCore::PrintTable.print_values(config: params, title: "Summary for code signing settings")
  path = params[:path]
  path = File.join(File.expand_path(path), "project.pbxproj")

  project = Xcodeproj::Project.open(params[:path])
  UI.user_error!("Could not find path to project config '#{path}'. Pass the path to your project (not workspace)!") unless File.exist?(path)
  UI.message("Updating the Automatic Codesigning flag to #{params[:use_automatic_signing] ? 'enabled' : 'disabled'} for the given project '#{path}'")

  unless project.root_object.attributes["TargetAttributes"]
    UI.user_error!("Seems to be a very old project file format - please open your project file in a more recent version of Xcode")
    return false
  end

  changed_targets = []
  changed_build_configurations = []

  project.targets.each do |target|
    if params[:targets]
      unless params[:targets].include?(target.name)
        UI.important("Skipping #{target.name} not selected (#{params[:targets].join(',')})")
        next
      end
    end

    target.build_configurations.each do |config|
      if params[:build_configurations]
        unless params[:build_configurations].include?(config.name)
          UI.important("Skipping #{config.name} not selected (#{params[:build_configurations].join(',')})")
          next
        end
      end

      style_value = params[:use_automatic_signing] ? 'Automatic' : 'Manual'
      development_team_setting = params[:sdk] ? "DEVELOPMENT_TEAM[sdk=#{params[:sdk]}]" : "DEVELOPMENT_TEAM"
      code_sign_identity_setting = params[:sdk] ? "CODE_SIGN_IDENTITY[sdk=#{params[:sdk]}]" : "CODE_SIGN_IDENTITY"
      provisioning_profile_setting = params[:sdk] ? "PROVISIONING_PROFILE_SPECIFIER[sdk=#{params[:sdk]}]" : "PROVISIONING_PROFILE_SPECIFIER"

      set_build_setting(config, "CODE_SIGN_STYLE", style_value)

      if params[:team_id]
        set_build_setting(config, development_team_setting, params[:team_id])
        UI.important("Set Team id to: #{params[:team_id]} for target: #{target.name} for build configuration: #{config.name}")
      end
      if params[:code_sign_identity]
        set_build_setting(config, code_sign_identity_setting, params[:code_sign_identity])
        UI.important("Set Code Sign identity to: #{params[:code_sign_identity]} for target: #{target.name} for build configuration: #{config.name}")
      end
      if params[:profile_name]
        set_build_setting(config, provisioning_profile_setting, params[:profile_name])
        UI.important("Set Provisioning Profile name to: #{params[:profile_name]} for target: #{target.name} for build configuration: #{config.name}")
      end
      if params[:entitlements_file_path]
        set_build_setting(config, "CODE_SIGN_ENTITLEMENTS", params[:entitlements_file_path])
        UI.important("Set Entitlements file path to: #{params[:entitlements_file_path]} for target: #{target.name} for build configuration: #{config.name}")
      end
      # Since Xcode 8, this is no longer needed, you simply use PROVISIONING_PROFILE_SPECIFIER
      if params[:profile_uuid]
        set_build_setting(config, "PROVISIONING_PROFILE", params[:profile_uuid])
        UI.important("Set Provisioning Profile UUID to: #{params[:profile_uuid]} for target: #{target.name} for build configuration: #{config.name}")
      end
      if params[:bundle_identifier]
        set_build_setting(config, "PRODUCT_BUNDLE_IDENTIFIER", params[:bundle_identifier])
        UI.important("Set Bundle identifier to: #{params[:bundle_identifier]} for target: #{target.name} for build configuration: #{config.name}")
      end

      changed_build_configurations << config.name
    end

    changed_targets << target.name
  end
  project.save

  if changed_targets.empty?
    UI.important("None of the specified targets has been modified")
    UI.important("available targets:")
    project.targets.each do |target|
      UI.important("\t* #{target.name}")
    end
  else
    UI.success("Successfully updated project settings to use Code Sign Style = '#{params[:use_automatic_signing] ? 'Automatic' : 'Manual'}'")
    UI.success("Modified Targets:")
    changed_targets.each do |target|
      UI.success("\t * #{target}")
    end

    UI.success("Modified Build Configurations:")
    changed_build_configurations.each do |name|
      UI.success("\t * #{name}")
    end
  end

  params[:use_automatic_signing]
end

.set_build_setting(configuration, name, value) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
# File 'fastlane/lib/fastlane/actions/update_code_signing_settings.rb', line 100

def self.set_build_setting(configuration, name, value)
  # Iterate over any keys that start with this name
  # This will also set keys that have filtering like [sdk=iphoneos*]
  keys = configuration.build_settings.keys.select { |key| key.to_s.match(/#{name}.*/) }
  keys.each do |key|
    configuration.build_settings[key] = value
  end

  # Explicitly set the key with value if keys don't exist
  configuration.build_settings[name] = value
end