Class: Fastlane::Runner

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

Instance Method Summary collapse

Instance Method Details

#after_all_blocksObject



108
109
110
# File 'lib/fastlane/runner.rb', line 108

def after_all_blocks
  @after_all ||= {}
end

#available_lanes(filter_platform = nil) ⇒ Object

Parameters:

  • filter_platform:

    Filter, to only show the lanes of a given platform



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/runner.rb', line 61

def available_lanes(filter_platform = nil)
  all = []
  blocks.each do |platform, lane| 
    next if (filter_platform and filter_platform.to_s != platform.to_s) # skip actions that don't match

    lane.each do |lane_name, block|
      all << [platform, lane_name].reject(&:nil?).join(' ')
    end
  end
  all
end

#before_all_blocksObject



104
105
106
# File 'lib/fastlane/runner.rb', line 104

def before_all_blocks
  @before_all ||= {}
end

#blocksObject



100
101
102
# File 'lib/fastlane/runner.rb', line 100

def blocks
  @blocks ||= {}
end

#description_blocksObject



116
117
118
# File 'lib/fastlane/runner.rb', line 116

def description_blocks
  @description_blocks ||= {}
end

#error_blocksObject



112
113
114
# File 'lib/fastlane/runner.rb', line 112

def error_blocks
  @error_blocks ||= {}
end

#execute(lane, platform = nil, parameters = nil) ⇒ Object

This will take care of executing one lane.

Parameters:

  • lane_name

    The name of the lane to execute

  • platform (defaults to: nil)

    The name of the platform to execute

  • parameters (Hash) (defaults to: nil)

    The parameters passed from the command line to the lane



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
50
51
52
53
54
55
56
57
58
# File 'lib/fastlane/runner.rb', line 8

def execute(lane, platform = nil, parameters = nil)
  raise "No lane given" unless lane

  ENV["FASTLANE_LANE_NAME"] = lane.to_s
  if platform
    ENV["FASTLANE_PLATFORM_NAME"] = platform.to_s
  else
    ENV["FASTLANE_PLATFORM_NAME"] = nil
  end
  
  lane = lane.to_sym
  platform = platform.to_sym if platform # might be nil, which is okay => root element

  Actions.lane_context[Actions::SharedValues::PLATFORM_NAME] = platform # set this in any case: important

  full_lane_name = [platform, lane].reject(&:nil?).join(' ')
  Helper.log.info "Driving the lane '#{full_lane_name}' 🚀".green
  Actions.lane_context[Actions::SharedValues::LANE_NAME] = full_lane_name

  return_val = nil

  path_to_use = Fastlane::FastlaneFolder.path || Dir.pwd
  Dir.chdir(path_to_use) do # the file is located in the fastlane folder

    unless (blocks[platform][lane] rescue nil)
      raise "Could not find lane '#{full_lane_name}'. Available lanes: #{available_lanes.join(', ')}".red
    end

    # Call the platform specific before_all block and then the general one
    before_all_blocks[platform].call(lane) if (before_all_blocks[platform] and platform != nil)
    before_all_blocks[nil].call(lane) if before_all_blocks[nil]
    
    return_val = blocks[platform][lane].call(parameters || {}) # by default no parameters
    
    # `after_all` is only called if no exception was raised before
    # Call the platform specific before_all block and then the general one
    after_all_blocks[platform].call(lane) if (after_all_blocks[platform] and platform != nil)
    after_all_blocks[nil].call(lane) if (after_all_blocks[nil])
  end

  return return_val
rescue => ex
  Dir.chdir(path_to_use) do
    # Provide error block exception without colour code
    error_ex = ex.exception(ex.message.gsub(/\033\[\d+m/, ''))

    error_blocks[platform].call(lane, error_ex) if (error_blocks[platform] and platform != nil)
    error_blocks[nil].call(lane, error_ex) if error_blocks[nil]
  end
  raise ex
end

#set_after_all(platform, block) ⇒ Object



78
79
80
# File 'lib/fastlane/runner.rb', line 78

def set_after_all(platform, block)
  after_all_blocks[platform] = block
end

#set_before_all(platform, block) ⇒ Object

Called internally



74
75
76
# File 'lib/fastlane/runner.rb', line 74

def set_before_all(platform, block)
  before_all_blocks[platform] = block
end

#set_block(lane, platform, block, desc = nil) ⇒ Object

Parameters:

  • lane:

    The name of the lane

  • platform:

    The platform for the given block - might be nil - nil is actually the root of Fastfile with no specific platform

  • block:

    The block of the lane

  • desc:

    Description of this action



90
91
92
93
94
95
96
97
98
# File 'lib/fastlane/runner.rb', line 90

def set_block(lane, platform, block, desc = nil)
  blocks[platform] ||= {}
  description_blocks[platform] ||= {}

  raise "Lane '#{lane}' was defined multiple times!".red if blocks[platform][lane]
  
  blocks[platform][lane] = block
  description_blocks[platform][lane] = desc
end

#set_error(platform, block) ⇒ Object



82
83
84
# File 'lib/fastlane/runner.rb', line 82

def set_error(platform, block)
  error_blocks[platform] = block
end