fastlane-plugin-settings_bundle 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5aded674a659311979b8b13ff5c48f5bf8ef03d
4
- data.tar.gz: 8431dec4540f60360adfd7d02396f1c726001f2b
3
+ metadata.gz: 8ec2f564820b8e88b1b974a32e4d44414a65b0b8
4
+ data.tar.gz: 8da1f81314e240c30050a058df47d9c9c66cbe56
5
5
  SHA512:
6
- metadata.gz: 32a6e2e1dfd12a92027f42345809371144c790c03f9af8706f25f049cd2ac5eda4df3a96f617cb48b682c6310c7cbc3a86f83bc7aba297e9e74eb8f6a9caad07
7
- data.tar.gz: eaeeceeaa4c7dcf7eb7788991fb3c2ad33038e0bab99ff5ac6e1d995a2666e804d77821a9d27c295f3fa5d44d8868d96c6f73022f3aef245fe175dd71ea38181
6
+ metadata.gz: bab2cbe3e48fafe76e35bfce1868278a8c06910f3b26aec4d277d6b4e91b2c4e92532e0d906f07f04878c3ca577a09cef42caeef14973ae73ea1939b213145f5
7
+ data.tar.gz: e0744e178aff7a0415ef31801856ec11200e0a495a9fc99827509948a41e5abe86a258588332acb02ae4c5f66c54af7f5be8243702a450eb2f9f51817c9a8dbf
data/README.md CHANGED
@@ -29,7 +29,6 @@ the current build number.
29
29
 
30
30
  ```ruby
31
31
  update_settings_bundle(
32
- xcodeproj: "MyProject.xcodeproj",
33
32
  key: "CurrentAppVersion",
34
33
  value: ":version (:build)"
35
34
  )
@@ -41,11 +40,24 @@ specified format. Use the action this way after `increment_build_number` or
41
40
  `increment_version_number` to update your settings bundle as part of a
42
41
  version bump.
43
42
 
43
+ #### Specifying the project file
44
+
45
+ By default, the action looks for a single .xcodeproj file in the repo,
46
+ excluding any under Pods. If more than one is present, use the `:xcodeproj`
47
+ parameter:
48
+
49
+ ```ruby
50
+ update_settings_bundle(
51
+ xcodeproj: "./MyProject.xcodeproj",
52
+ key: "CurrentAppVersion",
53
+ value: ":version (:build)"
54
+ )
55
+ ```
56
+
44
57
  #### Files other than Root.plist
45
58
 
46
59
  ```ruby
47
60
  update_settings_bundle(
48
- xcodeproj: "MyProject.xcodeproj",
49
61
  file: "About.plist",
50
62
  key: "CurrentAppVersion",
51
63
  value: ":version (:build)"
@@ -65,7 +77,6 @@ other settings besides the version and build numbers.
65
77
 
66
78
  ```ruby
67
79
  update_settings_bundle(
68
- xcodeproj: "MyProject.xcodeproj",
69
80
  key: "BuildDate",
70
81
  value: Time.now.strftime("%Y-%m-%d")
71
82
  )
@@ -81,7 +92,6 @@ different configuration, use a `configuration` parameter:
81
92
 
82
93
  ```ruby
83
94
  update_settings_bundle(
84
- xcodeproj: "MyProject.xcodeproj",
85
95
  key: "CurrentAppVersion",
86
96
  value: ":version (:build)",
87
97
  configuration: "Debug"
@@ -94,16 +104,35 @@ By default, this action takes the settings from the first non-test, non-extensio
94
104
  the project. Use the optional :target parameter to specify a target by name.
95
105
  ```ruby
96
106
  update_settings_bundle(
97
- xcodeproj: "MyProject.xcodeproj",
98
107
  key: "CurrentAppVersion",
99
108
  value: ":version (:build)",
100
109
  target: "MyAppTarget"
101
110
  )
102
111
  ```
103
112
 
104
- ## Example
113
+ #### Bundle name parameter
114
+
115
+ By default, this action looks for a file called `Settings.bundle` in the project. To
116
+ specify a different name for your settings bundle, use the `:bundle_name` option:
117
+ ```ruby
118
+ update_settings_bundle(
119
+ key: "CurrentAppVersion",
120
+ value: ":version (:build)",
121
+ bundle_name: "MySettings.bundle"
122
+ )
123
+ ```
105
124
 
106
- See the SettingsBundleExample subdirectory for a sample project that
125
+ ## Examples
126
+
127
+ [SettingsBundleExample]: ./examples/SettingsBundleExample
128
+ [SettingsBundleLibraryExample]: ./examples/SettingsBundleLibraryExample
129
+
130
+ There are two examples in the `examples` subdirectory: [SettingsBundleExample] (basic) and
131
+ [SettingsBundleLibraryExample] (advanced).
132
+
133
+ ### SettingsBundleExample (basic)
134
+
135
+ See the `examples/SettingsBundleExample` subdirectory for a simple example project that
107
136
  makes use of this action.
108
137
 
109
138
  First build and run the sample project on a simulator or device. It should show
@@ -125,6 +154,37 @@ Run the sample app again. It should display 1.0.0 (2). Tap the version number ag
125
154
  to see the update to the
126
155
  settings bundle. The Build date field should show the current date.
127
156
 
157
+ ### SettingsBundleLibraryExample (advanced)
158
+
159
+ The [SettingsBundleLibraryExample] project includes multiple targets with different versions
160
+ and a settings bundle with multiple pages. In addition to the `SettingsBundleLibraryExample`
161
+ target, there is a `SettingsBundleExampleFramework`, which builds a framework that is embedded
162
+ in the application. The app version is 1.0.0. The framework version is 1.0.1.
163
+
164
+ The settings bundle includes a child pane in Framework.plist. The app version (CurrentAppVersion)
165
+ and build date are in the Root.plist. The framework version (CurrentFrameworkVersion) is in
166
+ Framework.plist. It appears on the "Framework settings" page in the Settings app.
167
+
168
+ The lane in the Fastfile makes use of the :target parameter to choose which version data to use.
169
+
170
+ To update this project:
171
+
172
+ ```bash
173
+ bundle exec fastlane library_test
174
+ ```
175
+
176
+ Now build and run the app. The settings have been updated with the appropriate version
177
+ for each component.
178
+
179
+ #### Note
180
+
181
+ Though you can use a different version in
182
+ the `Info.plist` for each target, `agvtool` will
183
+ automatically set them all to the same value on update.
184
+ If you do your version update using a different
185
+ mechanism, `:build` will refer to the `CFBundleVersion` from the `Info.plist`
186
+ for whichever target you use.
187
+
128
188
  ## Run tests for this plugin
129
189
 
130
190
  To run both the tests, and code style validation, run
@@ -28,19 +28,25 @@ module Fastlane
28
28
  file = params[:file]
29
29
  value = params[:value]
30
30
 
31
- # try to open project file (raises)
32
- project = Xcodeproj::Project.open params[:xcodeproj]
33
-
34
31
  helper = Helper::SettingsBundleHelper
35
32
 
33
+ xcodeproj_path = helper.xcodeproj_path_from_params params
34
+ # Error already reported in helper
35
+ return if xcodeproj_path.nil?
36
+
37
+ # try to open project file (raises)
38
+ project = Xcodeproj::Project.open xcodeproj_path
39
+
40
+ # raises
36
41
  settings = helper.settings_from_project project, configuration, target_name
37
42
 
38
43
  formatted_value = helper.formatted_value value, settings
39
44
 
40
- helper.update_settings_plist_title_setting project, file, key,
45
+ # raises
46
+ helper.update_settings_plist_title_setting project, params[:bundle_name], file, key,
41
47
  formatted_value
42
48
  rescue => e
43
- UI.user_error! e.message
49
+ UI.user_error! "#{e.message}\n#{e.backtrace}"
44
50
  end
45
51
 
46
52
  def self.description
@@ -62,11 +68,6 @@ module Fastlane
62
68
  def self.available_options
63
69
  [
64
70
  # Required parameters
65
- FastlaneCore::ConfigItem.new(key: :xcodeproj,
66
- env_name: "SETTINGS_BUNDLE_XCODEPROJ",
67
- description: "An Xcode project file whose settings bundle to update",
68
- optional: false,
69
- type: String),
70
71
  FastlaneCore::ConfigItem.new(key: :key,
71
72
  env_name: "SETTINGS_BUNDLE_KEY",
72
73
  description: "The user defaults key to update in the settings bundle",
@@ -79,6 +80,11 @@ module Fastlane
79
80
  type: String),
80
81
 
81
82
  # Optional parameters
83
+ FastlaneCore::ConfigItem.new(key: :xcodeproj,
84
+ env_name: "SETTINGS_BUNDLE_XCODEPROJ",
85
+ description: "An Xcode project file whose settings bundle to update",
86
+ optional: true,
87
+ type: String),
82
88
  FastlaneCore::ConfigItem.new(key: :configuration,
83
89
  env_name: "SETTINGS_BUNDLE_CONFIGURATION",
84
90
  description: "The build configuration to use for the Info.plist file",
@@ -91,6 +97,12 @@ module Fastlane
91
97
  optional: true,
92
98
  default_value: "Root.plist",
93
99
  type: String),
100
+ FastlaneCore::ConfigItem.new(key: :bundle_name,
101
+ env_name: "SETTINGS_BUNDLE_BUNDLE_NAME",
102
+ description: "The name of the settings bundle in the project (default Settings.bundle)",
103
+ optional: true,
104
+ default_value: "Settings.bundle",
105
+ type: String),
94
106
  FastlaneCore::ConfigItem.new(key: :target,
95
107
  env_name: "SETTINGS_BUNDLE_TARGET",
96
108
  description: "An optional target name from the project",
@@ -103,7 +115,6 @@ module Fastlane
103
115
  [
104
116
  <<-EOF
105
117
  update_settings_bundle(
106
- xcodeproj: "MyProject.xcodeproj",
107
118
  key: "CurrentAppVersion",
108
119
  value: ":version (:build)"
109
120
  )
@@ -111,6 +122,12 @@ module Fastlane
111
122
  <<-EOF
112
123
  update_settings_bundle(
113
124
  xcodeproj: "MyProject.xcodeproj",
125
+ key: "CurrentAppVersion",
126
+ value: ":version (:build)"
127
+ )
128
+ EOF,
129
+ <<-EOF
130
+ update_settings_bundle(
114
131
  file: "About.plist",
115
132
  key: "CurrentAppVersion",
116
133
  value: ":version (:build)"
@@ -118,14 +135,12 @@ module Fastlane
118
135
  EOF,
119
136
  <<-EOF
120
137
  update_settings_bundle(
121
- xcodeproj: "MyProject.xcodeproj",
122
138
  key: "BuildDate",
123
139
  value: Time.now.strftime("%Y-%m-%d")
124
140
  )
125
141
  EOF,
126
142
  <<-EOF
127
143
  update_settings_bundle(
128
- xcodeproj: "MyProject.xcodeproj",
129
144
  key: "CurrentAppVersion",
130
145
  value: ":version (:build)",
131
146
  configuration: "Debug"
@@ -133,11 +148,17 @@ module Fastlane
133
148
  EOF,
134
149
  <<-EOF
135
150
  update_settings_bundle(
136
- xcodeproj: "MyProject.xcodeproj",
137
151
  key: "CurrentAppVersion",
138
152
  value: ":version (:build)",
139
153
  target: "MyAppTarget"
140
154
  )
155
+ EOF,
156
+ <<-EOF
157
+ update_settings_bundle(
158
+ key: "CurrentAppVersion",
159
+ value: ":version (:build)",
160
+ bundle_name: "MySettings.bundle"
161
+ )
141
162
  EOF
142
163
  ]
143
164
  end
@@ -22,6 +22,7 @@ require 'plist'
22
22
 
23
23
  module Fastlane
24
24
  module Helper
25
+ UI = FastlaneCore::UI
25
26
  class SettingsBundleHelper
26
27
  Settings = Struct.new "Settings", :version, :build
27
28
 
@@ -73,8 +74,9 @@ module Fastlane
73
74
 
74
75
  release_info_plist_path = File.join project_parent, release_info_plist_path
75
76
 
76
- # try to open and parse the Info.plist (raises)
77
- info_plist = Plist.parse_xml release_info_plist_path
77
+ # try to open and parse the Info.plist. raises on failure.
78
+ info_plist = File.open(release_info_plist_path) { |f| Plist.parse_xml f }
79
+ raise "Failed to parse plist file #{release_info_plist_path}" if info_plist.nil?
78
80
 
79
81
  # increments already happened. read the current state.
80
82
  current_marketing_version = info_plist["CFBundleShortVersionString"]
@@ -92,22 +94,25 @@ module Fastlane
92
94
  # on error.
93
95
  #
94
96
  # :project: An open Xcodeproj::Project, obtained from Xcodeproj::Project.open, e.g.
97
+ # :bundle_name: (String) Regex to identify the bundle to look for, usually Settings.bundle.
95
98
  # :file: A settings plist file in the Settings.bundle, usually "Root.plist"
96
99
  # :key: A valid NSUserDefaults key in the Settings.bundle
97
100
  # :value: A new value for the key
98
- def update_settings_plist_title_setting(project, file, key, value)
99
- settings_bundle = project.files.find { |f| f.path =~ /Settings.bundle/ }
101
+ def update_settings_plist_title_setting(project, bundle_name, file, key, value)
102
+ settings_bundle = project.files.find { |f| f.path =~ /#{bundle_name}/ }
100
103
 
101
- raise "Settings.bundle not found in project" if settings_bundle.nil?
104
+ raise "#{bundle_name} not found in project" if settings_bundle.nil?
102
105
 
103
- settings_bundle_path = settings_bundle.path
106
+ # The #real_path method returns the full resolved path to the Settings.bundle
107
+ settings_bundle_path = settings_bundle.real_path
104
108
 
105
- project_parent = File.dirname project.path
109
+ plist_path = File.join settings_bundle_path, file
110
+
111
+ # raises IOError
112
+ settings_plist = File.open(plist_path) { |f| Plist.parse_xml f }
106
113
 
107
- plist_path = File.join project_parent, settings_bundle_path, file
114
+ raise "Could not parse #{plist_path}" if settings_plist.nil?
108
115
 
109
- # raises
110
- settings_plist = Plist.parse_xml plist_path
111
116
  preference_specifiers = settings_plist["PreferenceSpecifiers"]
112
117
 
113
118
  raise "#{file} is not a settings plist file" if preference_specifiers.nil?
@@ -126,6 +131,34 @@ module Fastlane
126
131
  # Save (raises)
127
132
  Plist::Emit.save_plist settings_plist, plist_path
128
133
  end
134
+
135
+ def xcodeproj_path_from_params(params)
136
+ return params[:xcodeproj] if params[:xcodeproj]
137
+
138
+ # Adapted from commit_version_bump
139
+ # https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/commit_version_bump.rb#L21
140
+
141
+ # This may not be a git project. Search relative to the Gemfile.
142
+ repo_path = Bundler.root
143
+
144
+ all_xcodeproj_paths = Dir[File.expand_path(File.join(repo_path, '**/*.xcodeproj'))]
145
+ # find an xcodeproj (ignoring the Cocoapods one)
146
+ xcodeproj_paths = Fastlane::Actions.ignore_cocoapods_path(all_xcodeproj_paths)
147
+
148
+ # no projects found: error
149
+ UI.user_error!('Could not find a .xcodeproj in the current repository\'s working directory.') and return nil if xcodeproj_paths.count == 0
150
+
151
+ # too many projects found: error
152
+ if xcodeproj_paths.count > 1
153
+ repo_pathname = Pathname.new repo_path
154
+ relative_projects = xcodeproj_paths.map { |e| Pathname.new(e).relative_path_from(repo_pathname).to_s }.join("\n")
155
+ UI.user_error!("Found multiple .xcodeproj projects in the current repository's working directory. Please specify your app's main project: \n#{relative_projects}")
156
+ return nil
157
+ end
158
+
159
+ # one project found: great
160
+ xcodeproj_paths.first
161
+ end
129
162
  end
130
163
  end
131
164
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module SettingsBundle
3
- VERSION = "1.1.1"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-settings_bundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Dee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-21 00:00:00.000000000 Z
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plist
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
- rubygems_version: 2.6.8
157
+ rubygems_version: 2.6.12
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Fastlane plugin to update static settings in an iOS settings bundle