Class: Highway::Runtime::Context
- Inherits:
-
Object
- Object
- Highway::Runtime::Context
- Defined in:
- lib/highway/runtime/context.rb
Overview
This class is responsible for maintaining runtime context between step invocations, allowing steps to access runtimes of both Fastlane and Highway.
Context and environment collapse
-
#env ⇒ Highway::Runtime::Environment
readonly
The environment of the runtime context.
-
#fastlane_lane_context ⇒ Hash
readonly
The Fastlane lane context.
-
#interface ⇒ Highway::Interface
readonly
The interface.
Reports collapse
-
#reports ⇒ Array<Highway::Runtime::Report>
readonly
All reports in the runtime context.
Context and environment collapse
-
#artifacts_dir ⇒ String
The path to directory containing artifacts.
-
#with_modified_env(new_env, &block) ⇒ Object
Execute the given block in the scope of overridden ENV variables.
Reports collapse
-
#add_report(report) ⇒ Void
Add a runtime report to the context.
-
#archive_reports ⇒ Array<Highway::Runtime::Report>
Reports containing information about archives.
-
#deployment_reports ⇒ Array<Highway::Runtime::Report>
Reports containing information about deployments.
-
#duration_so_far ⇒ Numeric
Total duration of all previous reports.
-
#reports_any_failed? ⇒ Boolean
Whether any of the previous reports failed.
-
#test_reports ⇒ Array<Highway::Runtime::Report>
Reports containing information about tests.
Assertions collapse
-
#assert_executable_available!(name) ⇒ Object
Assert that an executable with specified name is available.
-
#assert_gem_available!(name) ⇒ Object
Assert that a gem with specified name is available.
Interfacing with Fastlane collapse
-
#run_action(name, options:) ⇒ Object
Run a Fastlane action.
-
#run_lane(name, options:) ⇒ Object
Run a Fastlane lane.
Interfacing with shell collapse
-
#run_sh(command, bundle_exec: false, silent: false, on_error: nil) ⇒ Object
Run a shell command.
-
#should_use_bundle_exec? ⇒ Boolean
Whether ‘bundle exec` is available and should be used if possible.
Instance Method Summary collapse
-
#initialize(fastlane_runner:, fastlane_lane_context:, env:, interface:) ⇒ Context
constructor
Initialize an instance.
Constructor Details
#initialize(fastlane_runner:, fastlane_lane_context:, env:, interface:) ⇒ Context
Initialize an instance.
26 27 28 29 30 31 32 |
# 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 |
Instance Attribute Details
#env ⇒ Highway::Runtime::Environment (readonly)
The environment of the runtime context.
39 40 41 |
# File 'lib/highway/runtime/context.rb', line 39 def env @env end |
#fastlane_lane_context ⇒ Hash (readonly)
The Fastlane lane context.
44 45 46 |
# File 'lib/highway/runtime/context.rb', line 44 def fastlane_lane_context @fastlane_lane_context end |
#interface ⇒ Highway::Interface (readonly)
The interface.
49 50 51 |
# File 'lib/highway/runtime/context.rb', line 49 def interface @interface end |
#reports ⇒ Array<Highway::Runtime::Report> (readonly)
All reports in the runtime context.
86 87 88 |
# File 'lib/highway/runtime/context.rb', line 86 def reports @reports end |
Instance Method Details
#add_report(report) ⇒ Void
Add a runtime report to the context.
93 94 95 |
# File 'lib/highway/runtime/context.rb', line 93 def add_report(report) @reports << report end |
#archive_reports ⇒ Array<Highway::Runtime::Report>
Reports containing information about archives.
121 122 123 |
# File 'lib/highway/runtime/context.rb', line 121 def archive_reports @reports.select { |report| report[:archive] != nil } end |
#artifacts_dir ⇒ String
The path to directory containing artifacts.
54 55 56 |
# File 'lib/highway/runtime/context.rb', line 54 def artifacts_dir File.join(File.(FastlaneCore::FastlaneFolder.path), "highway") end |
#assert_executable_available!(name) ⇒ Object
Assert that an executable with specified name is available.
144 145 146 147 148 |
# 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_gem_available!(name) ⇒ Object
Assert that a gem with specified name is available.
137 138 139 |
# File 'lib/highway/runtime/context.rb', line 137 def assert_gem_available!(name) Fastlane::Actions.verify_gem!(name) end |
#deployment_reports ⇒ Array<Highway::Runtime::Report>
Reports containing information about deployments.
128 129 130 |
# File 'lib/highway/runtime/context.rb', line 128 def deployment_reports @reports.select { |report| report[:deployment] != nil } end |
#duration_so_far ⇒ Numeric
Total duration of all previous reports.
107 108 109 |
# File 'lib/highway/runtime/context.rb', line 107 def duration_so_far @reports.reduce(0) { |memo, report| memo + report.duration } end |
#reports_any_failed? ⇒ Boolean
Whether any of the previous reports failed.
100 101 102 |
# File 'lib/highway/runtime/context.rb', line 100 def reports_any_failed? @reports.any? { |report| report.result == :failure } end |
#run_action(name, options:) ⇒ Object
Run a Fastlane action.
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# 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, ) end |
#run_lane(name, options:) ⇒ Object
Run a Fastlane lane.
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# 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, ) end |
#run_sh(command, bundle_exec: false, silent: false, on_error: nil) ⇒ Object
Run a shell command.
203 204 205 206 |
# File 'lib/highway/runtime/context.rb', line 203 def run_sh(command, bundle_exec: false, silent: false, on_error: nil) command = ["bundle exec", command].flatten if bundle_exec && should_use_bundle_exec? Fastlane::Actions.sh(command, log: !silent, error_callback: on_error) end |
#should_use_bundle_exec? ⇒ Boolean
Whether ‘bundle exec` is available and should be used if possible.
193 194 195 |
# File 'lib/highway/runtime/context.rb', line 193 def should_use_bundle_exec? return File.exist?("Gemfile") end |
#test_reports ⇒ Array<Highway::Runtime::Report>
Reports containing information about tests.
114 115 116 |
# File 'lib/highway/runtime/context.rb', line 114 def test_reports @reports.select { |report| report[:test] != nil } end |
#with_modified_env(new_env, &block) ⇒ Object
Execute the given block in the scope of overridden ENV variables. After that, old values will be restored.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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 |