SiarheiFedartsou / fastlane-plugin-versioning

Extends fastlane versioning actions. Allows to set/get versions without using agvtool and do some other small tricks.
MIT License
509 stars 61 forks source link

Error when running increment_version_number_in_xcodeproj with scheme and build configuration #63

Closed n0490b closed 3 years ago

n0490b commented 3 years ago

When I execute increment_version_number_in_xcodeproj(scheme: "MyApp", build_configuration_name: "Release", bump_type: 'minor') I get the error

`set_version_number_using_scheme': \e[31m[!] undefined method `[]=' for nil:NilClass\e[0m (NoMethodError)

get_version_number_from_xcodeproj(scheme: "MyApp", build_configuration_name: "Release") works and returns 3.3.0

Error

Traceback (most recent call last):
        27: from /usr/local/Cellar/fastlane/2.181.0/libexec/bin/fastlane:23:in `<main>'
        26: from /usr/local/Cellar/fastlane/2.181.0/libexec/bin/fastlane:23:in `load'
        25: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/bin/fastlane:23:in `<top (required)>'
        24: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/cli_tools_distributor.rb:122:in `take_off'
        23: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/commands_generator.rb:41:in `start'
        22: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/commands_generator.rb:352:in `run'
        21: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/commander-fastlane-4.4.6/lib/commander/delegates.rb:15:in `run!'
        20: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:76:in `run!'
        19: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/commander-fastlane-4.4.6/lib/commander/runner.rb:476:in `run_active_command'
        18: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/commander-fastlane-4.4.6/lib/commander/command.rb:153:in `run'
        17: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/commander-fastlane-4.4.6/lib/commander/command.rb:178:in `call'
        16: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/commands_generator.rb:108:in `block (2 levels) in run'
        15: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/command_line_handler.rb:36:in `handle'
        14: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/lane_manager.rb:47:in `cruise_lane'
        13: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:45:in `execute'
        12: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:45:in `chdir'
        11: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:49:in `block in execute'
        10: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/lane.rb:33:in `call'
         9: from Fastfile:28:in `block (2 levels) in parsing_binding'
         8: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/fast_file.rb:159:in `method_missing'
         7: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:157:in `trigger_action_by_name'
         6: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:229:in `execute_action'
         5: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:229:in `chdir'
         4: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:255:in `block in execute_action'
         3: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/actions/actions_helper.rb:69:in `execute_action'
         2: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:263:in `block (2 levels) in execute_action'
         1: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-plugin-versioning-0.4.4/lib/fastlane/plugin/versioning/actions/increment_version_number_in_xcodeproj.rb:44:in `run'
/usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-plugin-versioning-0.4.4/lib/fastlane/plugin/versioning/actions/increment_version_number_in_xcodeproj.rb:71:in `set_version_number_using_scheme': undefined method `[]=' for nil:NilClass (NoMethodError)
        27: from /usr/local/Cellar/fastlane/2.181.0/libexec/bin/fastlane:23:in `<main>'
        26: from /usr/local/Cellar/fastlane/2.181.0/libexec/bin/fastlane:23:in `load'
        25: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/bin/fastlane:23:in `<top (required)>'
        24: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/cli_tools_distributor.rb:122:in `take_off'
        23: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/commands_generator.rb:41:in `start'
        22: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/commands_generator.rb:352:in `run'
        21: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/commander-fastlane-4.4.6/lib/commander/delegates.rb:15:in `run!'
        20: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:76:in `run!'
        19: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/commander-fastlane-4.4.6/lib/commander/runner.rb:476:in `run_active_command'
        18: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/commander-fastlane-4.4.6/lib/commander/command.rb:153:in `run'
        17: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/commander-fastlane-4.4.6/lib/commander/command.rb:178:in `call'
        16: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/commands_generator.rb:108:in `block (2 levels) in run'
        15: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/command_line_handler.rb:36:in `handle'
        14: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/lane_manager.rb:47:in `cruise_lane'
        13: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:45:in `execute'
        12: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:45:in `chdir'
        11: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:49:in `block in execute'
        10: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/lane.rb:33:in `call'
         9: from Fastfile:28:in `block (2 levels) in parsing_binding'
         8: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/fast_file.rb:159:in `method_missing'
         7: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:157:in `trigger_action_by_name'
         6: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:229:in `execute_action'
         5: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:229:in `chdir'
         4: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:255:in `block in execute_action'
         3: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/actions/actions_helper.rb:69:in `execute_action'
         2: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-2.181.0/fastlane/lib/fastlane/runner.rb:263:in `block (2 levels) in execute_action'
         1: from /usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-plugin-versioning-0.4.4/lib/fastlane/plugin/versioning/actions/increment_version_number_in_xcodeproj.rb:44:in `run'
/usr/local/Cellar/fastlane/2.181.0/libexec/gems/fastlane-plugin-versioning-0.4.4/lib/fastlane/plugin/versioning/actions/increment_version_number_in_xcodeproj.rb:71:in `set_version_number_using_scheme': \e[31m[!] undefined method `[]=' for nil:NilClass\e[0m (NoMethodError)

I believe I have narrowed the error down to this line in increment_version_number_in_xcodeproj but I'm not sure whats causing the error

project.build_settings["MARKETING_VERSION"] = next_version_number

I was able to get it working as intended by modifying the code for set_all_xcodeproj_version_numbers and looping through each config and comparing it with the build_configuration_name param I pass in

def self.set_version_number_using_scheme(params, next_version_number)
      project = Xcodeproj::Project.open(params[:xcodeproj])
      configs = project.objects.select { |obj| select_build_configuration_predicate(nil, obj) }
      configs.each do |config|
        if config.to_s === params[:build_configuration_name]
            config.build_settings["MARKETING_VERSION"] = next_version_number
        end
      end
      project.save
  end

Targets

MyApp

Relevant Schemes

MyApp
Stg_MyApp

Relevant Build configurations

Release
StgRelease

Build Settings Marketing Version

build settings marketing version

info.plist

info.plist

My setup

OSX 10.15.7 XCode 12.2 Fastlane 2.181.0 Versioning 0.4.4

jdouglas-nz commented 3 years ago

Hey @n0490b,

Thanks for the code snippet ! I think this will actually help with another issue about a 'over zealous' version update. I know this 'nil' business can also be the result of not having first set a version/build through Xcode's UI. Your change makes total sense - if you feel like it, fork away and make that change! ❤️

jdouglas-nz commented 3 years ago

Otherwise - I'll see if I can find a few mins this weekend 😅

n0490b commented 3 years ago

hey @jdouglas-nz do you mean create a fork and make a PR?

jdouglas-nz commented 3 years ago

@n0490b Correct! If you don't want to - I'll try and bring it in this weekend sometime. If you can't wait until then, be my guest 😊

n0490b commented 3 years ago

@jdouglas-nz done