Class: FunCi::Pipeline::Trigger
- Inherits:
-
Object
- Object
- FunCi::Pipeline::Trigger
- Includes:
- ProcessRunner
- Defined in:
- lib/fun_ci/pipeline/trigger.rb
Constant Summary collapse
- NULL_SHA =
("0" * 40).freeze
- DEFAULT_BUDGETS =
{ "lint" => 30, "build" => 30, "fast" => 10, "slow" => 300 }.freeze
Instance Attribute Summary collapse
-
#command_runner ⇒ Object
writeonly
Sets the attribute command_runner.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(project_root:, commit_hash:, branch:, stdout: $stdout, stderr: $stderr, command_runner: nil, time_budgets: {}, commit_validator: nil, recorder: Persistence::NullRecorder.new, background_launcher: nil) ⇒ Trigger
constructor
A new instance of Trigger.
- #run ⇒ Object
Methods included from ProcessRunner
Constructor Details
#initialize(project_root:, commit_hash:, branch:, stdout: $stdout, stderr: $stderr, command_runner: nil, time_budgets: {}, commit_validator: nil, recorder: Persistence::NullRecorder.new, background_launcher: nil) ⇒ Trigger
Returns a new instance of Trigger.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fun_ci/pipeline/trigger.rb', line 42 def initialize(project_root:, commit_hash:, branch:, stdout: $stdout, stderr: $stderr, command_runner: nil, time_budgets: {}, commit_validator: nil, recorder: Persistence::NullRecorder.new, background_launcher: nil) @project_root = project_root @commit_hash = commit_hash @branch = branch @stdout = stdout @stderr = stderr @command_runner = command_runner @time_budgets = DEFAULT_BUDGETS.merge(time_budgets) @commit_validator = commit_validator || method(:default_commit_validator) @recorder = recorder @background_launcher = background_launcher || method(:default_background_launcher) end |
Instance Attribute Details
#command_runner=(value) ⇒ Object (writeonly)
Sets the attribute command_runner
40 41 42 |
# File 'lib/fun_ci/pipeline/trigger.rb', line 40 def command_runner=(value) @command_runner = value end |
Class Method Details
.run_from_args(args, stdout: $stdout, stderr: $stderr, recorder: Persistence::NullRecorder.new, pipeline_forker: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fun_ci/pipeline/trigger.rb', line 20 def self.run_from_args(args, stdout: $stdout, stderr: $stderr, recorder: Persistence::NullRecorder.new, pipeline_forker: nil) positional = args.reject { |a| a.start_with?("--") } if positional.length < 2 stderr.puts "fun-ci: commit hash and branch name are required." stderr.puts "Usage: fun-ci trigger <commit-hash> <branch>" return 1 end commit_hash, branch = positional if args.include?("--no-validate") db_path = recorder.db_path recorder.close (pipeline_forker || PipelineForker.method(:fork_pipeline)).call( commit_hash: commit_hash, branch: branch, db_path: db_path ) return 0 end new(project_root: Dir.pwd, commit_hash: commit_hash, branch: branch, stdout: stdout, stderr: stderr, recorder: recorder).run end |
Instance Method Details
#run ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fun_ci/pipeline/trigger.rb', line 55 def run config = Setup::ProjectConfig.new(@project_root) return handle_config_errors(config) if config.validate.any? unless @commit_hash == NULL_SHA || @commit_validator.call(@commit_hash) @stderr.puts "fun-ci: commit #{@commit_hash} not found in this repository." return 1 end cancel_stale_pipelines @recorder.create_run(commit_hash: @commit_hash, branch: @branch, project_path: @project_root) stage_runner = make_stage_runner progress = ProgressReporter.new(stdout: @stdout) results = run_phase_one(stage_runner, config) progress.phase_one_result(results) unless results.values.all? @recorder.fail_run return 1 end spawn_slow_suite(config) progress.slow_launched fast_runner = make_stage_runner fast_passed = fast_runner.run_stage(config, "fast") progress.fast_result(fast_passed) unless fast_passed @recorder.fail_run return 1 end 0 end |