fastlane/lib/fastlane/actions/get_version_number.rb in fastlane-2.178.0 vs fastlane/lib/fastlane/actions/get_version_number.rb in fastlane-2.179.0

- old
+ new

@@ -6,18 +6,19 @@ class GetVersionNumberAction < Action require 'shellwords' def self.run(params) - folder = params[:xcodeproj] ? File.join(params[:xcodeproj], '..') : '.' + xcodeproj_path_or_dir = params[:xcodeproj] || '.' + xcodeproj_dir = File.extname(xcodeproj_path_or_dir) == ".xcodeproj" ? File.dirname(xcodeproj_path_or_dir) : xcodeproj_path_or_dir target_name = params[:target] configuration = params[:configuration] # Get version_number - project = get_project!(folder) + project = get_project!(xcodeproj_path_or_dir) target = get_target!(project, target_name) - plist_file = get_plist!(folder, target, configuration) + plist_file = get_plist!(xcodeproj_dir, target, configuration) version_number = get_version_number_from_plist!(plist_file) # Get from build settings (or project settings) if needed (ex: $(MARKETING_VERSION) is default in Xcode 11) if version_number =~ /\$\(([\w\-]+)\)/ version_number = get_version_number_from_build_settings!(target, $1, configuration) || get_version_number_from_build_settings!(project, $1, configuration) @@ -37,17 +38,22 @@ # Return the version number because Swift might need this return value return version_number end - def self.get_project!(folder) + def self.get_project!(xcodeproj_path_or_dir) require 'xcodeproj' - project_path = Dir.glob("#{folder}/*.xcodeproj").first - if project_path + if File.extname(xcodeproj_path_or_dir) == ".xcodeproj" + project_path = xcodeproj_path_or_dir + else + project_path = Dir.glob("#{xcodeproj_path_or_dir}/*.xcodeproj").first + end + + if project_path && File.exist?(project_path) return Xcodeproj::Project.open(project_path) else - UI.user_error!("Unable to find Xcode project in folder: #{folder}") + UI.user_error!("Unable to find Xcode project at #{project_path || xcodeproj_path_or_dir}") end end def self.get_target!(project, target_name) targets = project.targets @@ -145,14 +151,15 @@ def self.available_options [ FastlaneCore::ConfigItem.new(key: :xcodeproj, env_name: "FL_VERSION_NUMBER_PROJECT", - description: "Path to the main Xcode project to read version number from, optional. By default will use the first Xcode project found within the project root directory", + description: "Path to the Xcode project to read version number from, or its containing directory, optional. If ommitted, or if a directory is passed instead, it will use the first Xcode project found within the given directory, or the project root directory if none is passed", optional: true, verify_block: proc do |value| - UI.user_error!("Please pass the path to the project, not the workspace") if value.end_with?(".xcworkspace") - UI.user_error!("Could not find Xcode project at path '#{File.expand_path(value)}'") if !File.exist?(value) && !Helper.test? + UI.user_error!("Please pass the path to the project or its containing directory, not the workspace path") if value.end_with?(".xcworkspace") + UI.user_error!("Could not find file or directory at path '#{File.expand_path(value)}'") unless File.exist?(value) + UI.user_error!("Could not find Xcode project in directory at path '#{File.expand_path(value)}'") if File.extname(value) != ".xcodeproj" && Dir.glob("#{value}/*.xcodeproj").empty? end), FastlaneCore::ConfigItem.new(key: :target, env_name: "FL_VERSION_NUMBER_TARGET", description: "Target name, optional. Will be needed if you have more than one non-test target to avoid being prompted to select one", optional: true),