diff --git a/.rubocop.yml b/.rubocop.yml index 265a1ad..cce2feb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -23,23 +23,23 @@ Style/VariableNumber: Style/MethodMissing: Enabled: false -# +# # File.chmod(0777, f) -# +# # is easier to read than -# +# # File.chmod(0o777, f) -# +# Style/NumericLiteralPrefix: Enabled: false -# +# # command = (!clean_expired.nil? || !clean_pattern.nil?) ? CLEANUP : LIST -# +# # is easier to read than -# +# # command = !clean_expired.nil? || !clean_pattern.nil? ? CLEANUP : LIST -# +# Style/TernaryParentheses: Enabled: false @@ -200,3 +200,19 @@ Style/IfInsideElse: # Sometimes we just want to 'collect' Style/CollectionMethods: Enabled: false + +# They have not to be snake_case +Style/FileName: + Exclude: + - '*.gemspec' + - '**/Dangerfile' + - '**/Brewfile' + - '**/Gemfile' + - '**/Podfile' + - '**/Rakefile' + - '**/Fastfile' + - '**/Deliverfile' + - '**/Snapfile' + +Eval: + Enabled: false diff --git a/Gemfile b/Gemfile index 4f2232e..33eb95f 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,8 @@ source 'https://rubygems.org' gemspec -gem 'simplecov' gem 'rspec-simplecov' +gem 'simplecov' plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval(File.read(plugins_path), binding) if File.exist?(plugins_path) diff --git a/Gemfile.lock b/Gemfile.lock index e29a7d7..7dc85ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,51 +1,44 @@ PATH remote: . specs: - fastlane-plugin-settings_bundle (1.0.1) + fastlane-plugin-settings_bundle (1.1.0) plist xcodeproj (>= 1.4.0) GEM remote: https://rubygems.org/ specs: - CFPropertyList (2.3.4) - activesupport (4.0.13) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - addressable (2.5.0) + CFPropertyList (2.3.5) + addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) ast (2.3.0) babosa (1.0.2) claide (1.0.1) coderay (1.1.1) colored (1.2) - commander (4.4.3) + colored2 (3.1.2) + commander-fastlane (4.4.4) highline (~> 1.7.2) - diff-lcs (1.2.5) + diff-lcs (1.3) docile (1.1.5) - domain_name (0.5.20161129) + domain_name (0.5.20170404) unf (>= 0.0.5, < 1.0.0) - dotenv (2.1.1) - excon (0.54.0) - faraday (0.10.0) + dotenv (2.2.0) + excon (0.55.0) + faraday (0.12.0.1) multipart-post (>= 1.2, < 3) faraday-cookie_jar (0.0.6) faraday (>= 0.7.4) http-cookie (~> 1.0.0) - faraday_middleware (0.10.1) + faraday_middleware (0.11.0.1) faraday (>= 0.7.4, < 1.0) - fastimage (2.0.1) - addressable (~> 2) - fastlane (2.3.1) - activesupport (< 5) + fastimage (2.1.0) + fastlane (2.27.0) addressable (>= 2.3, < 3.0.0) babosa (>= 1.0.2, < 2.0.0) - bundler (~> 1.12) + bundler (>= 1.12.0, < 2.0.0) colored - commander (>= 4.4.0, < 5.0.0) + commander-fastlane (>= 4.4.0, < 5.0.0) dotenv (>= 2.1.1, < 3.0.0) excon (>= 0.45.0, < 1.0.0) faraday (~> 0.9) @@ -53,9 +46,9 @@ GEM faraday_middleware (~> 0.9) fastimage (>= 1.6) gh_inspector (>= 1.0.1, < 2.0.0) - google-api-client (~> 0.9.1) + google-api-client (~> 0.9.2) highline (>= 1.7.2, < 2.0.0) - json (>= 2.0.1, < 3.0.0) + json (< 3.0.0) mini_magick (~> 4.5.1) multi_json multi_xml (~> 0.5) @@ -66,12 +59,13 @@ GEM slack-notifier (>= 1.3, < 2.0.0) terminal-notifier (>= 1.6.2, < 2.0.0) terminal-table (>= 1.4.5, < 2.0.0) + tty-screen (~> 0.5.0) word_wrap (~> 1.0.0) - xcodeproj (>= 0.20, < 2.0.0) + xcodeproj (>= 1.4.4, < 2.0.0) xcpretty (>= 0.2.4, < 1.0.0) xcpretty-travis-formatter (>= 0.0.3) - gh_inspector (1.0.2) - google-api-client (0.9.20) + gh_inspector (1.0.3) + google-api-client (0.9.28) addressable (~> 2.3) googleauth (~> 0.5) httpclient (~> 2.7) @@ -93,11 +87,10 @@ GEM domain_name (~> 0.5) httpclient (2.8.3) hurley (0.2) - i18n (0.7.0) - json (2.0.2) + json (2.1.0) jwt (1.5.6) little-plugger (1.1.4) - logging (2.1.0) + logging (2.2.2) little-plugger (~> 1.1) multi_json (~> 1.10) memoist (0.15.0) @@ -106,13 +99,12 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_magick (4.5.1) - minitest (4.7.5) multi_json (1.12.1) multi_xml (0.6.0) multipart-post (2.0.0) nanaimo (0.2.3) os (0.9.6) - parser (2.3.3.1) + parser (2.4.0.0) ast (~> 2.2) plist (3.2.0) powerpack (0.1.1) @@ -120,7 +112,7 @@ GEM coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - public_suffix (2.0.4) + public_suffix (2.0.5) rainbow (2.2.1) rake (12.0.0) representable (2.3.0) @@ -141,21 +133,21 @@ GEM rspec-support (~> 3.5.0) rspec-simplecov (0.2.2) rspec-support (3.5.0) - rubocop (0.46.0) - parser (>= 2.3.1.1, < 3.0) + rubocop (0.48.1) + parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.8.1) - rubyzip (1.2.0) + rubyzip (1.2.1) security (0.1.3) signet (0.7.3) addressable (~> 2.3) faraday (~> 0.9) jwt (~> 1.5) multi_json (~> 1.10) - simplecov (0.12.0) + simplecov (0.14.1) docile (~> 1.1.0) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) @@ -165,21 +157,19 @@ GEM terminal-notifier (1.7.1) terminal-table (1.7.3) unicode-display_width (~> 1.1.1) - thread_safe (0.3.5) - tzinfo (0.3.52) + tty-screen (0.5.0) uber (0.0.15) unf (0.1.4) unf_ext - unf_ext (0.0.7.2) - unicode-display_width (1.1.2) + unf_ext (0.0.7.4) + unicode-display_width (1.1.3) word_wrap (1.0.0) - xcodeproj (1.4.2) + xcodeproj (1.4.4) CFPropertyList (~> 2.3.3) - activesupport (>= 3) claide (>= 1.0.1, < 2.0) - colored (~> 1.2) + colored2 (~> 3.1) nanaimo (~> 0.2.3) - xcpretty (0.2.4) + xcpretty (0.2.6) rouge (~> 1.8) xcpretty-travis-formatter (0.0.4) xcpretty (~> 0.2, >= 0.0.7) @@ -199,4 +189,4 @@ DEPENDENCIES simplecov BUNDLED WITH - 1.13.7 + 1.14.6 diff --git a/README.md b/README.md index e192635..bfc4400 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,19 @@ update_settings_bundle( ) ``` +#### Target parameter + +By default, this action takes the settings from the first non-test, non-extension target in +the project. Use the optional :target parameter to specify a target by name. +```ruby +update_settings_bundle( + xcodeproj: "MyProject.xcodeproj", + key: "CurrentAppVersion", + value: ":version (:build)", + target: "MyAppTarget" +) +``` + ## Example See the SettingsBundleExample subdirectory for a sample project that diff --git a/Rakefile b/Rakefile index 05f4f23..2146b5f 100644 --- a/Rakefile +++ b/Rakefile @@ -6,4 +6,4 @@ RSpec::Core::RakeTask.new require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) -task default: [:spec, :rubocop] +task default: %i[spec rubocop] diff --git a/circle.yml b/circle.yml index 0ed729c..fc45c53 100644 --- a/circle.yml +++ b/circle.yml @@ -3,7 +3,4 @@ test: - bundle exec rake machine: ruby: - version: 2.3.2 -# Enable xcode below if you need macOS -# xcode: -# version: "7.3" + version: 2.4.0 diff --git a/fastlane-plugin-settings_bundle.gemspec b/fastlane-plugin-settings_bundle.gemspec index 0aea446..058b86e 100644 --- a/fastlane-plugin-settings_bundle.gemspec +++ b/fastlane-plugin-settings_bundle.gemspec @@ -1,4 +1,5 @@ # coding: utf-8 + lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'fastlane/plugin/settings_bundle/version' @@ -6,14 +7,14 @@ require 'fastlane/plugin/settings_bundle/version' Gem::Specification.new do |spec| spec.name = 'fastlane-plugin-settings_bundle' spec.version = Fastlane::SettingsBundle::VERSION - spec.author = %q{Jimmy Dee} - spec.email = %q{jgvdthree@gmail.com} + spec.author = 'Jimmy Dee' + spec.email = 'jgvdthree@gmail.com' - spec.summary = %q{Fastlane plugin to update static settings in an iOS settings bundle} + spec.summary = 'Fastlane plugin to update static settings in an iOS settings bundle' spec.homepage = "https://github.com/jdee/settings-bundle" spec.license = "MIT" - spec.files = Dir["lib/**/*"] + %w(README.md LICENSE) + spec.files = Dir["lib/**/*"] + %w[README.md LICENSE] spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] diff --git a/lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb b/lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb index c4dcf88..32170e1 100644 --- a/lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb +++ b/lib/fastlane/plugin/settings_bundle/actions/update_settings_bundle_action.rb @@ -24,6 +24,7 @@ class UpdateSettingsBundleAction < Action def self.run(params) key = params[:key] configuration = params[:configuration] + target_name = params[:target] file = params[:file] value = params[:value] @@ -32,7 +33,7 @@ def self.run(params) helper = Helper::SettingsBundleHelper - settings = helper.settings_from_project project, configuration + settings = helper.settings_from_project project, configuration, target_name formatted_value = helper.formatted_value value, settings @@ -89,6 +90,11 @@ def self.available_options description: "The plist file in the Settings.bundle to update", optional: true, default_value: "Root.plist", + type: String), + FastlaneCore::ConfigItem.new(key: :file, + env_name: "SETTINGS_BUNDLE_TARGET", + description: "An optional target name from the project", + optional: true, type: String) ] end @@ -124,6 +130,14 @@ def self.example_code value: ":version (:build)", configuration: "Debug" ) + EOF, + <<-EOF + update_settings_bundle( + xcodeproj: "MyProject.xcodeproj", + key: "CurrentAppVersion", + value: ":version (:build)", + target: "MyAppTarget" + ) EOF ] end diff --git a/lib/fastlane/plugin/settings_bundle/helper/settings_bundle_helper.rb b/lib/fastlane/plugin/settings_bundle/helper/settings_bundle_helper.rb index e7974e8..ac9278f 100644 --- a/lib/fastlane/plugin/settings_bundle/helper/settings_bundle_helper.rb +++ b/lib/fastlane/plugin/settings_bundle/helper/settings_bundle_helper.rb @@ -45,11 +45,17 @@ def formatted_value(value, settings) # # :project: An open Xcodeproj::Project via Xcodeproj::Project.open, e.g. # :configuration: A valid build configuration in the project - def settings_from_project(project, configuration) - # find the first non-test, non-extension target - # TODO: Make this a :target parameter - target = project.targets.find { |t| !t.test_target_type? && !t.extension_target_type? } - raise "No application target found" if target.nil? + # :target_name: A valid target name in the project or nil to use the first application target + def settings_from_project(project, configuration, target_name) + if target_name + target = project.targets.find { |t| t.name == target_name } + raise "Target named \"#{target_name}\" not found" if target.nil? + else + # find the first non-test, non-extension target + # TODO: Make this a :target parameter + target = project.targets.find { |t| !t.test_target_type? && !t.extension_target_type? } + raise "No application target found" if target.nil? + end # find the Info.plist paths for all configurations info_plist_paths = target.resolved_build_setting "INFOPLIST_FILE" diff --git a/lib/fastlane/plugin/settings_bundle/version.rb b/lib/fastlane/plugin/settings_bundle/version.rb index e635aea..f1dc90e 100644 --- a/lib/fastlane/plugin/settings_bundle/version.rb +++ b/lib/fastlane/plugin/settings_bundle/version.rb @@ -1,5 +1,5 @@ module Fastlane module SettingsBundle - VERSION = "1.0.1" + VERSION = "1.1.0" end end diff --git a/spec/settings_bundle_helper_spec.rb b/spec/settings_bundle_helper_spec.rb index 979524f..80b44e4 100644 --- a/spec/settings_bundle_helper_spec.rb +++ b/spec/settings_bundle_helper_spec.rb @@ -53,14 +53,49 @@ expect(Plist).to receive(:parse_xml).with("./Info.plist") { info_plist } # code under test - settings = helper.settings_from_project project, "Release" + settings = helper.settings_from_project project, "Release", nil # check results expect(settings.build).to eq "1" expect(settings.version).to eq "1.0.0" end - it 'raises if no application target found' do + it 'finds a target by name' do + # project setting + info_plists = { "Release" => "Info.plist" } + + # mock Info.plist + info_plist = { "CFBundleShortVersionString" => "1.0.0", + "CFBundleVersion" => "1" } + + # mock targets + test_target = double "target", + name: "MyAppTestTarget", + test_target_type?: true, + extension_target_type?: false + target = double "target", + name: "MyAppTarget", + test_target_type?: false, + extension_target_type?: false + + expect(target).to receive(:resolved_build_setting) + .with("INFOPLIST_FILE") { info_plists } + + # mock project + project = double "project", targets: [test_target, target], path: "" + + # mock out the file read + expect(Plist).to receive(:parse_xml).with("./Info.plist") { info_plist } + + # code under test + settings = helper.settings_from_project project, "Release", "MyAppTarget" + + # check results + expect(settings.build).to eq "1" + expect(settings.version).to eq "1.0.0" + end + + it 'raises if no target specified and application target found' do test_target = double "target", test_target_type?: true, extension_target_type?: false @@ -72,7 +107,19 @@ project = double "project", targets: [test_target, extension_target] expect do - helper.settings_from_project project, "Release" + helper.settings_from_project project, "Release", nil + end.to raise_error RuntimeError + end + + it 'raises if target specified and not found' do + application_target = double "target", + name: "ATarget", + test_target_type?: false, + extension_target_type?: false + + project = double "project", targets: [application_target] + expect do + helper.settings_from_project project, "Release", "MyAppTarget" end.to raise_error RuntimeError end @@ -89,7 +136,7 @@ project = double "project", targets: [target], path: "" expect do - helper.settings_from_project project, "Release" + helper.settings_from_project project, "Release", nil end.to raise_error RuntimeError end @@ -106,7 +153,7 @@ project = double "project", targets: [target], path: "" expect do - helper.settings_from_project project, "Release" + helper.settings_from_project project, "Release", nil end.to raise_error RuntimeError end @@ -133,7 +180,7 @@ # code under test expect do - helper.settings_from_project project, "Release" + helper.settings_from_project project, "Release", nil end.to raise_error RuntimeError end @@ -160,7 +207,7 @@ # code under test expect do - helper.settings_from_project project, "Release" + helper.settings_from_project project, "Release", nil end.to raise_error RuntimeError end end diff --git a/spec/update_settings_bundle_action_spec.rb b/spec/update_settings_bundle_action_spec.rb index f297bfd..f0ec058 100644 --- a/spec/update_settings_bundle_action_spec.rb +++ b/spec/update_settings_bundle_action_spec.rb @@ -29,7 +29,7 @@ settings = Fastlane::Helper::SettingsBundleHelper::Settings.new "1.0.0", "1" helper = Fastlane::Helper::SettingsBundleHelper - expect(helper).to receive(:settings_from_project).with(project, "Release") { settings } + expect(helper).to receive(:settings_from_project).with(project, "Release", "MyAppTarget") { settings } expect(helper).to receive(:formatted_value).with(":version (:build)", settings) { "1.0.0 (1)" } expect(helper).to receive(:update_settings_plist_title_setting) @@ -37,7 +37,7 @@ action.run xcodeproj: "MyProject.xcodeproj", key: "CurrentAppVersion", configuration: "Release", file: "Root.plist", - value: ":version (:build)" + value: ":version (:build)", target: "MyAppTarget" end it 'logs on error' do