fastlane/lib/fastlane/lane_manager.rb in fastlane-2.10.0 vs fastlane/lib/fastlane/lane_manager.rb in fastlane-2.11.0

- old
+ new

@@ -159,35 +159,55 @@ else UI.user_error! "Run `fastlane` the next time you need to build, test or release your app 🚀" end end - def self.load_dot_env(env) - # find the first directory of [fastlane, its parent] containing dotenv files + # @param env_cl_param [String] an optional list of dotenv environment names separated by commas, without space + def self.load_dot_env(env_cl_param) + base_path = find_dotenv_directory + + return unless base_path + + load_dot_envs_from(env_cl_param, base_path) + end + + # finds the first directory of [fastlane, its parent] containing dotenv files + def self.find_dotenv_directory path = FastlaneCore::FastlaneFolder.path search_paths = [path] search_paths << path + "/.." unless path.nil? search_paths.compact! - base_path = search_paths.find do |dir| + search_paths.find do |dir| Dir.glob(File.join(dir, '*.env*'), File::FNM_DOTMATCH).count > 0 end - return unless base_path + end + + # loads the dotenvs. First the .env and .env.default and + # then override with all speficied extra environments + def self.load_dot_envs_from(env_cl_param, base_path) require 'dotenv' - Actions.lane_context[Actions::SharedValues::ENVIRONMENT] = env if env - # Making sure the default '.env' and '.env.default' get loaded env_file = File.join(base_path, '.env') env_default_file = File.join(base_path, '.env.default') Dotenv.load(env_file, env_default_file) - # Loads .env file for the environment passed in through options - if env + return unless env_cl_param + + Actions.lane_context[Actions::SharedValues::ENVIRONMENT] = env_cl_param + + # multiple envs? + envs = env_cl_param.split(",") + + # Loads .env file for the environment(s) passed in through options + envs.each do |env| env_file = File.join(base_path, ".env.#{env}") UI.success "Loading from '#{env_file}'" Dotenv.overload(env_file) end end + + private_class_method :find_dotenv_directory, :load_dot_envs_from def self.print_lane_context return if Actions.lane_context.empty? if $verbose