Class: Fastlane::Actions::UpdateSettingsBundleAction

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

Class Method Summary collapse

Class Method Details

.authorObject



56
57
58
# File 'lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb', line 56

def self.author
  "Jimmy Dee"
end

.available_optionsObject



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
107
108
109
110
111
112
# File 'lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb', line 68

def self.available_options
  [
    # Required parameters
    FastlaneCore::ConfigItem.new(key: :key,
                            env_name: "SETTINGS_BUNDLE_KEY",
                         description: "The user defaults key to update in the settings bundle",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :value,
                            env_name: "SETTINGS_BUNDLE_VALUE",
                         description: "Value to set with optional :version and :build included",
                            optional: false,
                                type: String),

    # Optional parameters
    FastlaneCore::ConfigItem.new(key: :xcodeproj,
                            env_name: "SETTINGS_BUNDLE_XCODEPROJ",
                         description: "An Xcode project file whose settings bundle to update",
                            optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :configuration,
                            env_name: "SETTINGS_BUNDLE_CONFIGURATION",
                         description: "The build configuration to use for the Info.plist file",
                            optional: true,
                       default_value: "Release",
                                type: String),
    FastlaneCore::ConfigItem.new(key: :file,
                            env_name: "SETTINGS_BUNDLE_FILE",
                         description: "The plist file in the Settings.bundle to update",
                            optional: true,
                       default_value: "Root.plist",
                                type: String),
    FastlaneCore::ConfigItem.new(key: :bundle_name,
                            env_name: "SETTINGS_BUNDLE_BUNDLE_NAME",
                         description: "The name of the settings bundle in the project (default Settings.bundle)",
                            optional: true,
                       default_value: "Settings.bundle",
                                type: String),
    FastlaneCore::ConfigItem.new(key: :target,
                            env_name: "SETTINGS_BUNDLE_TARGET",
                         description: "An optional target name from the project",
                            optional: true,
                                type: String)
  ]
end

.categoryObject



170
171
172
# File 'lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb', line 170

def self.category
  :project
end

.descriptionObject



52
53
54
# File 'lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb', line 52

def self.description
  "Fastlane plugin action to update static settings in an iOS settings bundle"
end

.detailsObject



60
61
62
63
64
65
66
# File 'lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb', line 60

def self.details
  "This action is used to automatically update a Title entry in a plist\n" \
    "in an app's Settings bundle. It can be used to update the current\n" \
    "version and/or build number automatically after they have been \n" \
    "updated, e.g. by the increment_version_number or increment_build_number\n" \
    "actions."
end

.example_codeObject



114
115
116
117
118
119
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
# File 'lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb', line 114

def self.example_code
  [
    "      update_settings_bundle(\n        key: \"CurrentAppVersion\",\n        value: \":version (:build)\"\n      )\n    EOF,\n    <<-EOF\n      update_settings_bundle(\n        xcodeproj: \"MyProject.xcodeproj\",\n        key: \"CurrentAppVersion\",\n        value: \":version (:build)\"\n      )\n    EOF,\n    <<-EOF\n      update_settings_bundle(\n        file: \"About.plist\",\n        key: \"CurrentAppVersion\",\n        value: \":version (:build)\"\n      )\n    EOF,\n    <<-EOF\n      update_settings_bundle(\n        key: \"BuildDate\",\n        value: Time.now.strftime(\"%Y-%m-%d\")\n      )\n    EOF,\n    <<-EOF\n      update_settings_bundle(\n        key: \"CurrentAppVersion\",\n        value: \":version (:build)\",\n        configuration: \"Debug\"\n      )\n    EOF,\n    <<-EOF\n      update_settings_bundle(\n        key: \"CurrentAppVersion\",\n        value: \":version (:build)\",\n        target: \"MyAppTarget\"\n      )\n    EOF,\n    <<-EOF\n      update_settings_bundle(\n        key: \"CurrentAppVersion\",\n        value: \":version (:build)\",\n        bundle_name: \"MySettings.bundle\"\n      )\n    EOF\n  ]\nend\n"

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


166
167
168
# File 'lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb', line 166

def self.is_supported?(platform)
  platform == :ios
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb', line 24

def self.run(params)
  key = params[:key]
  configuration = params[:configuration]
  target_name = params[:target]
  file = params[:file]
  value = params[:value]

  helper = Helper::SettingsBundleHelper

  xcodeproj_path = helper.xcodeproj_path_from_params params
  # Error already reported in helper
  return if xcodeproj_path.nil?

  # try to open project file (raises)
  project = Xcodeproj::Project.open xcodeproj_path

  # raises
  settings = helper.settings_from_project project, configuration, target_name

  formatted_value = helper.formatted_value value, settings

  # raises
  helper.update_settings_plist_title_setting project, params[:bundle_name], file, key,
                                             formatted_value
rescue => e
  UI.user_error! "#{e.message}\n#{e.backtrace}"
end