Class: Fastlane::Actions::UpdateInfoPlistAction

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

Constant Summary

Constants inherited from Fastlane::Action

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

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, 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

.authorObject



108
109
110
# File 'fastlane/lib/fastlane/actions/update_info_plist.rb', line 108

def self.author
  'tobiasstrebitzer'
end

.available_optionsObject



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
99
100
101
102
103
104
105
106
# File 'fastlane/lib/fastlane/actions/update_info_plist.rb', line 67

def self.available_options
  [

    FastlaneCore::ConfigItem.new(key: :xcodeproj,
                                 env_name: "FL_UPDATE_PLIST_PROJECT_PATH",
                                 description: "Path to your Xcode project",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass the path to the project, not the workspace") if value.end_with?(".xcworkspace")
                                   UI.user_error!("Could not find Xcode project") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :plist_path,
                                 env_name: "FL_UPDATE_PLIST_PATH",
                                 description: "Path to info plist",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Invalid plist file") unless value.downcase.end_with?(".plist")
                                 end),
    FastlaneCore::ConfigItem.new(key: :scheme,
                                 env_name: "FL_UPDATE_PLIST_APP_SCHEME",
                                 description: "Scheme of info plist",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :app_identifier,
                                 env_name: 'FL_UPDATE_PLIST_APP_IDENTIFIER',
                                 description: 'The App Identifier of your app',
                                 code_gen_sensitive: true,
                                 default_value: ENV['PRODUCE_APP_IDENTIFIER'],
                                 default_value_dynamic: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :display_name,
                                 env_name: 'FL_UPDATE_PLIST_DISPLAY_NAME',
                                 description: 'The Display Name of your app',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :block,
                                 type: :string_callback,
                                 description: 'A block to process plist with custom logic',
                                 optional: true)

  ]
end

.categoryObject



138
139
140
# File 'fastlane/lib/fastlane/actions/update_info_plist.rb', line 138

def self.category
  :project
end

.descriptionObject



59
60
61
# File 'fastlane/lib/fastlane/actions/update_info_plist.rb', line 59

def self.description
  'Update a Info.plist file with bundle identifier and display name'
end

.detailsObject



63
64
65
# File 'fastlane/lib/fastlane/actions/update_info_plist.rb', line 63

def self.details
  "This action allows you to modify your `Info.plist` file before building. This may be useful if you want a separate build for alpha, beta or nightly builds, but don't want a separate target."
end

.example_codeObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'fastlane/lib/fastlane/actions/update_info_plist.rb', line 112

def self.example_code
  [
    'update_info_plist( # update app identifier string
      plist_path: "path/to/Info.plist",
      app_identifier: "com.example.newappidentifier"
    )',
    'update_info_plist( # Change the Display Name of your app
      plist_path: "path/to/Info.plist",
      display_name: "MyApp-Beta"
    )',
    'update_info_plist( # Target a specific `xcodeproj` rather than finding the first available one
      xcodeproj: "path/to/Example.proj",
      plist_path: "path/to/Info.plist",
      display_name: "MyApp-Beta"
    )',
    'update_info_plist( # Advanced processing: find URL scheme for particular key and replace value
      xcodeproj: "path/to/Example.proj",
      plist_path: "path/to/Info.plist",
      block: proc do |plist|
        urlScheme = plist["CFBundleURLTypes"].find{|scheme| scheme["CFBundleURLName"] == "com.acme.default-url-handler"}
        urlScheme[:CFBundleURLSchemes] = ["acme-production"]
      end
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



55
56
57
# File 'fastlane/lib/fastlane/actions/update_info_plist.rb', line 55

def self.is_supported?(platform)
  [:ios].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
47
48
49
# File 'fastlane/lib/fastlane/actions/update_info_plist.rb', line 7

def self.run(params)
  # Check if parameters are set
  if params[:app_identifier] || params[:display_name] || params[:block]
    if (params[:app_identifier] || params[:display_name]) && params[:block]
      UI.important("block parameter can not be specified with app_identifier or display_name")
      return false
    end

    # Assign folder from parameter or search for xcodeproj file
    folder = params[:xcodeproj] || Dir["*.xcodeproj"].first
    UI.user_error!("Could not figure out your xcodeproj path. Please specify it using the `xcodeproj` parameter") if folder.nil?

    if params[:scheme]
      project = Xcodeproj::Project.open(folder)
      scheme = project.native_targets.detect { |target| target.name == params[:scheme] }
      UI.user_error!("Couldn't find scheme named '#{params[:scheme]}'") unless scheme

      params[:plist_path] = scheme.build_configurations.first.build_settings["INFOPLIST_FILE"]
      UI.user_error!("Scheme named '#{params[:scheme]}' doesn't have a plist file") unless params[:plist_path]
      params[:plist_path] = params[:plist_path].gsub("$(SRCROOT)", ".")
    end

    if params[:plist_path].nil?
      UI.user_error!("You must specify either a plist path or a scheme")
    end

    # Read existing plist file
    info_plist_path = File.join(folder, "..", params[:plist_path])
    UI.user_error!("Couldn't find info plist file at path '#{info_plist_path}'") unless File.exist?(info_plist_path)

    UpdatePlistAction.run(
      plist_path: info_plist_path,
      block: proc do |plist|
        plist['CFBundleIdentifier'] = params[:app_identifier] if params[:app_identifier]
        plist['CFBundleDisplayName'] = params[:display_name] if params[:display_name]
        params[:block].call(plist) if params[:block]
      end
    )
  else
    UI.important("You haven't specified any parameters to update your plist.")
    false
  end
end