class Highway::Runtime::Context
This class is responsible for maintaining runtime context between step invocations, allowing steps to access runtimes of both Fastlane
and Highway
.
Attributes
The environment of the runtime context.
@return [Highway::Runtime::Environment]
The Fastlane
lane context.
@return [Hash]
The interface.
@return [Highway::Interface]
All reports in the runtime context.
@return [Array<Highway::Runtime::Report>]
Public Class Methods
Initialize an instance.
@param fastlane_runner [Fastlane::Runner] The Fastlane
runner. @param fastlane_lane_context
[Hash] The Fastlane
lane context. @param env [Highway::Runtime::Environment] The runtime environment. @param reporter [Highway::Interface] The interface.
# File lib/highway/runtime/context.rb, line 26 def initialize(fastlane_runner:, fastlane_lane_context:, env:, interface:) @fastlane_runner = fastlane_runner @fastlane_lane_context = fastlane_lane_context @env = env @interface = interface @reports = Array.new() end
Public Instance Methods
Add a runtime report to the context.
@param report [Highway::Runtime::Report] The report.
@return [Void]
# File lib/highway/runtime/context.rb, line 93 def add_report(report) @reports << report end
Reports containing information about archives.
@return [Array<Highway::Runtime::Report>]
# File lib/highway/runtime/context.rb, line 121 def archive_reports @reports.select { |report| report[:archive] != nil } end
The path to directory containing artifacts.
@return [String]
# File lib/highway/runtime/context.rb, line 54 def artifacts_dir File.join(File.expand_path(FastlaneCore::FastlaneFolder.path), "highway") end
Assert that an executable with specified name is available.
@param name [String] Name of executable.
# File lib/highway/runtime/context.rb, line 144 def assert_executable_available!(name) unless FastlaneCore::CommandExecutor.which(name) != nil @interface.fatal!("Required executable '#{name}' could not be found. Make sure it's installed.") end end
Assert that a gem with specified name is available.
@param name [String] Name of the gem.
# File lib/highway/runtime/context.rb, line 137 def assert_gem_available!(name) Fastlane::Actions.verify_gem!(name) end
Reports containing information about deployments.
@return [Array<Highway::Runtime::Report>]
# File lib/highway/runtime/context.rb, line 128 def deployment_reports @reports.select { |report| report[:deployment] != nil } end
Total duration of all previous reports.
@return [Numeric]
# File lib/highway/runtime/context.rb, line 107 def duration_so_far @reports.reduce(0) { |memo, report| memo + report.duration } end
Whether any of the previous reports failed.
@return [Boolean]
# File lib/highway/runtime/context.rb, line 100 def reports_any_failed? @reports.any? { |report| report.result == :failure } end
Run a Fastlane
action.
@param name [String, Symbol] Name of the action. @param options [Hash] Options passed to the action.
# File lib/highway/runtime/context.rb, line 174 def run_action(name, options:) unless contains_action?(name) @interface.fatal!("Can't execute action '#{name}' because it doesn't exist.") end unless !contains_lane?(name) @interface.fatal!("Can't execute action '#{name}' because a lane with the same name exists.") end run_lane_or_action(name, options) end
Run a Fastlane
lane.
@param name [String, Symbol] Name of the lane. @param options [Hash] Options passed to the lane.
# File lib/highway/runtime/context.rb, line 156 def run_lane(name, options:) unless contains_lane?(name) @interface.fatal!("Can't execute lane '#{name}' because it doesn't exist.") end unless !contains_action?(name) @interface.fatal!("Can't execute lane '#{name}' because an action with the same name exists.") end run_lane_or_action(name, options) end
Run a shell command.
@param command [String, Array] A shell command. @param bundle_exec [Boolean] Whether to use `bundle exec` if possible. @param silent [Boolean] Whether to run the command silently. @param on_error [Proc] Called if command exits with a non-zero code.
# File lib/highway/runtime/context.rb, line 203 def run_sh(command, bundle_exec: false, silent: false, rescue_error: nil) command = ["bundle exec", command].flatten if bundle_exec && should_use_bundle_exec? Fastlane::Actions.sh(command, log: !silent, error_callback: rescue_error) end
Whether `bundle exec` is available and should be used if possible.
@return [Boolean]
# File lib/highway/runtime/context.rb, line 193 def should_use_bundle_exec? return File.exist?("Gemfile") end
Reports containing information about tests.
@return [Array<Highway::Runtime::Report>]
# File lib/highway/runtime/context.rb, line 114 def test_reports @reports.select { |report| report[:test] != nil } end
Execute the given block in the scope of overridden ENV variables. After that, old values will be restored.
@param new_env [Hash] ENV variables to override. @param &block [Proc] A block to execute.
# File lib/highway/runtime/context.rb, line 63 def with_modified_env(new_env, &block) old_env = Utilities::hash_map(new_env.keys) { |name| [name, ENV[name]] } new_env.each_pair { |name, value| ENV[name] = value } block.call() old_env.each_pair { |name, value| ENV[name] = value } end
Private Instance Methods
# File lib/highway/runtime/context.rb, line 215 def contains_action?(action_name) action = @fastlane_runner.class_reference_from_action_name(action_name.to_sym) action ||= @fastlane_runner.class_reference_from_action_alias(action_name.to_sym) action != nil end
# File lib/highway/runtime/context.rb, line 210 def contains_lane?(lane_name) lane = @fastlane_runner.lanes.fetch(nil, {}).fetch(lane_name.to_sym, nil) lane != nil end
# File lib/highway/runtime/context.rb, line 221 def run_lane_or_action(name, args) symbolicated_args = Utilities::hash_map(args || {}) { |key, value| [key.to_sym, value] } @fastlane_runner.trigger_action_by_name(name.to_sym, Dir.pwd, true, *[symbolicated_args]) end