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

get_build_number_from_xcodeproj produces NoMethodError: undefined method `resolved_build_setting' for nil:NilClass when using sorted array #53

Closed kevint727 closed 4 years ago

kevint727 commented 4 years ago

I get an error whenever I try and do a sort on the array of environment variables prior to doing the rest of my work. Driving me crazy trying to figure out what is wrong.

schemeList = Dir.glob(".env.*") schemeList = schemeList.sort
schemeList.each do |file| Dotenv.overload(file) yield end

if ENV['SCHEME'] != nil puts(ENV['SCHEME'])

build_number = get_build_number_from_xcodeproj(
    target: ENV['SCHEME']
    )

else end The "schemeList = schemeList.sort" causes it to error when trying to get the build number with the following:

bundler: failed to load command: fastlane (/usr/local/bin/fastlane) NoMethodError: [!] undefined method resolved_build_setting' for nil:NilClass /Library/Ruby/Gems/2.3.0/gems/fastlane-plugin-versioning-0.4.2/lib/fastlane/plugin/versioning/actions/get_build_number_from_xcodeproj.rb:55:inget_build_number_using_target' /Library/Ruby/Gems/2.3.0/gems/fastlane-plugin-versioning-0.4.2/lib/fastlane/plugin/versioning/actions/get_build_number_from_xcodeproj.rb:17:in run' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:261:inblock (2 levels) in execute_action' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/actions/actions_helper.rb:50:in execute_action' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:253:inblock in execute_action' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:227:in chdir' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:227:inexecute_action' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:157:in trigger_action_by_name' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/fast_file.rb:159:inmethod_missing' Fastfile:378:in block (2 levels) in parsing_binding' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/lane.rb:33:incall' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:204:in try_switch_to_lane' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:146:intrigger_action_by_name' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/fast_file.rb:159:in method_missing' Fastfile:391:inblock (3 levels) in parsing_binding' Fastfile:368:in block in execute_for_all_envs' Fastfile:366:ineach' Fastfile:366:in execute_for_all_envs' Fastfile:391:inblock (2 levels) in parsing_binding' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/lane.rb:33:in call' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:49:inblock in execute' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:45:in chdir' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/runner.rb:45:inexecute' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/lane_manager.rb:56:in cruise_lane' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/command_line_handler.rb:36:inhandle' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/commands_generator.rb:108:in block (2 levels) in run' /Library/Ruby/Gems/2.3.0/gems/commander-fastlane-4.4.6/lib/commander/command.rb:178:incall' /Library/Ruby/Gems/2.3.0/gems/commander-fastlane-4.4.6/lib/commander/command.rb:153:in run' /Library/Ruby/Gems/2.3.0/gems/commander-fastlane-4.4.6/lib/commander/runner.rb:476:inrun_active_command' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:76:in run!' /Library/Ruby/Gems/2.3.0/gems/commander-fastlane-4.4.6/lib/commander/delegates.rb:15:inrun!' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/commands_generator.rb:349:in run' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/commands_generator.rb:41:instart' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/fastlane/lib/fastlane/cli_tools_distributor.rb:119:in take_off' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.143.0/bin/fastlane:23:in<top (required)>' /usr/local/bin/fastlane:22:in load' /usr/local/bin/fastlane:22:in<top (required)>'

If I remove the sort line, everything works. Everything else I run with the sort line in there seems to be perfectly fine, like using Gym, etc. I can also print the ENV['SCHEME'] and the ordered array with no problem. In addition, if I pass it just a hardcoded string as the target in:

build_number = get_build_number_from_xcodeproj( target: ENV['SCHEME'] )

it works fine. Even though I can print out (put) that variable correctly so I know it is not nil.

Any help would be greatly appreciated.

kevint727 commented 4 years ago

Still haven't received a response to this question...

jdouglas-nz commented 4 years ago

@kevint727,

Apologies for late response.

Here’s a couple thoughts I had looking at the snippets you’ve sent.

on the .each: I am curious why you need the yield actually. could you try putting the build_number block inside of the .each? Just everything that you’d want to do for each of your .env files - try put it in the .each, and try removing the yield. I haven’t really used yields in my ruby time, but if I enter in something like what you have, I get a ruby LocalJumpError (no block given(yield)).

On the SCHEME env vars: Also, can you confirm that none of the .env files are malformed and actually declare a “SCHEME=value” ?

I wouldn’t say it would be this, but make sure those schemes map to a scheme within your project too !

kevint727 commented 4 years ago

The SCHEME env cars are definitely not malformed and do declare a scheme. It also works perfectly when I remove your plugin call. I also reworked the script to not have "yield" in it and that did not fix the problem.

jdouglas-nz commented 4 years ago

@kevint727, do you run a post xcode11 style of version/ build number? (Where the plist values are build settings). Or a pre xcode11 style? (Where the plist holds the actual values)

I’d love to add a unit test to the test suite and ensure that your issue is resolved. Would you be able to share some of your setup ?

kevint727 commented 4 years ago

I'll look into that ASAP and here is a shortened script that I am currently testing with and fails. It does work perfectly if you remove the "schemeList = schemeList.sort" line.

desc "Create new buildTest3" lane :buildTest3 do |options| startEnv = options[:startEnv] schemeList = Dir.glob(".env.*") schemeList = schemeList.sort schemeList.each do |file| Dotenv.overload(file) puts(ENV['SCHEME']) build_number = get_build_number_from_xcodeproj( target: ENV['SCHEME'] ) end end

kevint727 commented 4 years ago

My Xcode targets and project have the versioning system set to "none."

I am using Xcode 11. And my plists pull from build settings.

jdouglas-nz commented 4 years ago

@kevint727 this one seems tricky! I’m struggling to see the link between the .sort line and a nil scheme. Especially if it works without the .sort..

I ran your lane in a work project, and it works - with the sort :(

Hate to ask, but is there any chance of you redacting/obfuscating your .env files / project file so that I can experiment in an environment closer to yours?

kevint727 commented 4 years ago

Wow, so I just figured out the problem. It was totally my fault... It just so happened that out of the 80+ .env files, when sorted, the one it started out with did indeed have a scheme, but the scheme casing in the .env file did not match the target's casing. Example: FooBar vs FOOBar. That was apparently not a problem for anything else I'm doing (my scripts are much more complicated than what I sent you), but your plugin in particular did not like it. To further complicate things, when I ran the lane on that problem .env file directly, it worked fine because it was using the scheme I specified in the command rather than the one actually in the .env file, so no problems... My sincere apologies for wasting your time looking into this and thanks so much for the responses.

jdouglas-nz commented 4 years ago

@kevint727, that is great news!

not a problem at all!
I’m glad it’s working for you!!

jdouglas-nz commented 4 years ago

@kevint727 I’ll close this issue for now, but feel free to raise any more !