Module: FastlaneEnvLanes::FastlaneRunnerExtensions

Included in:
Fastlane::Runner
Defined in:
lib/fastlane_env_lanes.rb

Instance Method Summary collapse

Instance Method Details

#execute(key) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fastlane_env_lanes.rb', line 20

def execute(key)

  env_key = key.to_s.gsub(':', '__')
  lane_key = env_key.split('__')[0]

  # Making sure the default '.env' and '.env.default' get loaded
  env_file = File.join(Fastlane::FastlaneFolder.path || "", '.env')
  env_default_file = File.join(Fastlane::FastlaneFolder.path || "", '.env.default')
  Dotenv.load(env_file, env_default_file)

  # Priority of environment goes to lane called with ":<env>"
  # Then uses environment passed in through options "--env <env>"
  env = nil
  if env_key.split('__').size > 1
    env = env_key.split('__')[1]
  else
    env = Fastlane::Actions.lane_context[ Fastlane::Actions::SharedValues::ENVIRONMENT ].to_s
    env_key = lane_key + '__' + env
  end

  # Loads .env file for the environment
  if env
    env_file = File.join(Fastlane::FastlaneFolder.path || "", ".env.#{env}")
    Fastlane::Helper.log.info "Loading from '#{env_file}'".green
    Dotenv.overload(env_file)
  end

  # Checking if the environment lane exists
  if FastlaneEnvLanes.env_lanes && FastlaneEnvLanes.env_lanes.include?(env_key.to_sym)
    super env_key.to_sym
  else
    super lane_key.to_sym
  end

end