Class: Fastlane::LaneManager

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/lane_manager.rb

Class Method Summary collapse

Class Method Details

.choose_lane(ff, platform) ⇒ Object

Lane chooser if user didn't provide a lane

Parameters:

  • platform:

    is probably nil, but user might have called `fastlane android`, and only wants to list those actions


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fastlane/lane_manager.rb', line 72

def self.choose_lane(ff, platform)
  loop do
    Helper.log.error "You must provide a lane to drive. Available lanes:"
    available = ff.runner.available_lanes(platform)

    available.each_with_index do |lane, index|
      puts "#{index + 1}) #{lane}"
    end

    i = $stdin.gets.strip.to_i - 1
    if i >= 0 and (available[i] rescue nil)
      selection = available[i]
      Helper.log.info "Driving the lane #{selection}. Next time launch fastlane using `fastlane #{selection}`".yellow
      platform = selection.split(' ')[0]
      lane_name = selection.split(' ')[1]

      unless lane_name # no specific platform, just a root lane
        lane_name = platform
        platform = nil
      end

      return platform, lane_name # yeah
    end

    Helper.log.error "Invalid input. Please enter the number of the lane you want to use".red
  end
end

.cruise_lane(platform, lane, parameters = nil, env = nil) ⇒ Object

Parameters:

  • platform

    The name of the platform to execute

  • lane_name

    The name of the lane to execute

  • parameters (Hash) (defaults to: nil)

    The parameters passed from the command line to the lane

  • env (defaults to: nil)

    Dot Env Information


7
8
9
10
11
12
13
14
15
16
17
18
19
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
# File 'lib/fastlane/lane_manager.rb', line 7

def self.cruise_lane(platform, lane, parameters = nil, env = nil)
  raise 'lane must be a string' unless (lane.is_a?(String) or lane.nil?)
  raise 'platform must be a string' unless (platform.is_a?(String) or platform.nil?)
  raise 'parameters must be a hash' unless (parameters.is_a?(Hash) or parameters.nil?)

  ff = Fastlane::FastFile.new(File.join(Fastlane::FastlaneFolder.path, 'Fastfile'))

  unless (ff.is_platform_block?lane rescue false) # rescue, because this raises an exception if it can't be found at all
    # maybe the user specified a default platform
    # We'll only do this, if the lane specified isn't a platform, as we want to list all platforms then
    platform ||= Actions.lane_context[Actions::SharedValues::DEFAULT_PLATFORM]
  end

  if not platform and lane
    # Either, the user runs a specific lane in root or want to auto complete the available lanes for a platform
    # e.g. `fastlane ios` should list all available iOS actions
    if ff.is_platform_block?lane
      platform = lane
      lane = nil
    end
  end

  platform, lane = choose_lane(ff, platform) unless lane

  load_dot_env(env)

  started = Time.now
  e = nil
  begin
    ff.runner.execute(lane, platform, parameters)
  rescue => ex
    Helper.log.info 'Variable Dump:'.yellow
    Helper.log.info Actions.lane_context
    Helper.log.fatal ex
    e = ex
  end

  duration = ((Time.now - started) / 60.0).round

  finish_fastlane(ff, duration, e)

  return ff
end

.finish_fastlane(ff, duration, error) ⇒ Object

All the finishing up that needs to be done


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fastlane/lane_manager.rb', line 52

def self.finish_fastlane(ff, duration, error)
  ff.runner.did_finish

  # Finished with all the lanes
  Fastlane::JUnitGenerator.generate(Fastlane::Actions.executed_actions)

  unless error
    if duration > 5
      Helper.log.info "fastlane.tools just saved you #{duration} minutes! 🎉".green
    else
      Helper.log.info 'fastlane.tools finished successfully 🎉'.green
    end
  else
    Helper.log.fatal 'fastlane finished with errors'.red
    raise error
  end
end

.load_dot_env(env) ⇒ Object


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fastlane/lane_manager.rb', line 100

def self.load_dot_env(env)
  require 'dotenv'

  Actions.lane_context[Actions::SharedValues::ENVIRONMENT] = env

  # 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)

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