Class: Fastlane::Actions::UpdateBuildSettingsKeyAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/update_build_settings_key/actions/update_build_settings_key_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



39
40
41
# File 'lib/fastlane/plugin/update_build_settings_key/actions/update_build_settings_key_action.rb', line 39

def self.authors
  ["ungacy"]
end

.available_optionsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fastlane/plugin/update_build_settings_key/actions/update_build_settings_key_action.rb', line 52

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :xcodeproj,
                                 env_name: "FL_PROJECT_SIGNING_PROJECT_PATH",
                                 description: "Path to your Xcode project",
                                 verify_block: proc do |value|
                                   UI.user_error!("Path is invalid") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :configuration,
                                 description: "name of your configuration ,such as 'Release'"),
    FastlaneCore::ConfigItem.new(key: :build_settings_key,
                                 description: "key of the build setting you want update"),
    FastlaneCore::ConfigItem.new(key: :map,
                                 type: Hash,
                                 description: "KEY is path to Info.plist , VALUE is updated value of build setting key")
  ]
end

.descriptionObject



35
36
37
# File 'lib/fastlane/plugin/update_build_settings_key/actions/update_build_settings_key_action.rb', line 35

def self.description
  "Updates build settings key to a new value"
end

.detailsObject



47
48
49
50
# File 'lib/fastlane/plugin/update_build_settings_key/actions/update_build_settings_key_action.rb', line 47

def self.details
  # Optional:
  "Updates build settings key to a new value including specific profile,\nwill Update code signing settings from 'Automatic' to a specific profile when key is PROVISIONING_PROFILE_SPECIFIER"
end

.example_codeObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fastlane/plugin/update_build_settings_key/actions/update_build_settings_key_action.rb', line 70

def self.example_code
  [
    'update_build_settings_key(
      xcodeproj: "Demo/Demo.xcodeproj",
      configuration: "Release",
      build_settings_key: "PROVISIONING_PROFILE_SPECIFIER",
      map: {
        "Demo Watch Extension/Info.plist" => "Demo WatchKit Extension 2",
        "Demo Watch/Info.plist" => "Demo WatchKit App",
        "Demo Today/Info.plist" => "Demo Today",
        "Demo/Info.plist" => "Demo"
      }
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
92
# File 'lib/fastlane/plugin/update_build_settings_key/actions/update_build_settings_key_action.rb', line 86

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.return_valueObject



43
44
45
# File 'lib/fastlane/plugin/update_build_settings_key/actions/update_build_settings_key_action.rb', line 43

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



4
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
# File 'lib/fastlane/plugin/update_build_settings_key/actions/update_build_settings_key_action.rb', line 4

def self.run(params)
  require 'plist'
  require 'xcodeproj'

  info_plist_key = 'INFOPLIST_FILE'
  build_settings_key = params[:build_settings_key]
  project_path = params[:xcodeproj]
  configuration = params[:configuration]
  map = params[:map]
  project = Xcodeproj::Project.open(project_path)
  # Set ProvisioningStyle to Manual if
  if 'PROVISIONING_PROFILE_SPECIFIER' == build_settings_key
    pbxprojects = project.objects.select { |obj| obj.isa == 'PBXProject' }
    pbxprojects.each { |obj| obj.attributes.each { |attribute, value| value.each { |key, item| item['ProvisioningStyle'] = 'Manual' } if value.kind_of? Hash } }
  end
  configs = project.objects.select { |obj| obj.isa == 'XCBuildConfiguration' && obj.to_s == configuration && obj.build_settings[info_plist_key] }
  UI.user_error!("Info plist uses $(#{build_settings_key}), but xcodeproj does not") unless configs.count > 0
  configs = configs.select do |obj|
    info_plist_value = obj.build_settings[info_plist_key]
    !map[info_plist_value].nil?
  end
  UI.user_error!("Xcodeproj doesn't have #{configuration} with info plist #{project_path}.") unless configs.count > 0
  # For each of the build configurations, set specific profile
  configs.each do |c|
    info_plist_value = c.build_settings[info_plist_key]
    c.build_settings[build_settings_key] = map[info_plist_value]
  end
  project.save
  UI.success("Successfully updated project")
end