Class: Bard::CI::Runner

Inherits:
Struct
  • Object
show all
Includes:
Retryable
Defined in:
lib/bard/plugins/deploy/ci/runner.rb

Direct Known Subclasses

GithubActions, Jenkins, Local

Constant Summary

Constants included from Retryable

Retryable::INITIAL_DELAY, Retryable::MAX_RETRIES

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Retryable

#retry_with_backoff

Class Attribute Details

.runnersObject (readonly)

Returns the value of attribute runners.



12
13
14
# File 'lib/bard/plugins/deploy/ci/runner.rb', line 12

def runners
  @runners
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch

Returns:

  • (Object)

    the current value of branch



6
7
8
# File 'lib/bard/plugins/deploy/ci/runner.rb', line 6

def branch
  @branch
end

#project_nameObject

Returns the value of attribute project_name

Returns:

  • (Object)

    the current value of project_name



6
7
8
# File 'lib/bard/plugins/deploy/ci/runner.rb', line 6

def project_name
  @project_name
end

#shaObject

Returns the value of attribute sha

Returns:

  • (Object)

    the current value of sha



6
7
8
# File 'lib/bard/plugins/deploy/ci/runner.rb', line 6

def sha
  @sha
end

Class Method Details

.[](name) ⇒ Object



20
21
22
# File 'lib/bard/plugins/deploy/ci/runner.rb', line 20

def [](name)
  runners[name.to_sym]
end

.defaultObject

Returns the last registered runner (most recently loaded wins)



25
26
27
# File 'lib/bard/plugins/deploy/ci/runner.rb', line 25

def default
  runners.values.last
end

.inherited(subclass) ⇒ Object



14
15
16
17
18
# File 'lib/bard/plugins/deploy/ci/runner.rb', line 14

def inherited(subclass)
  super
  name = extract_runner_name(subclass)
  runners[name] = subclass if name
end

Instance Method Details

#resumeObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/bard/plugins/deploy/ci/runner.rb', line 53

def resume
  saved_state = state.load
  raise "No saved CI state found for #{project_name}. Start a new build with 'bard ci'." if saved_state.nil?

  restore_state(saved_state)
  poll_until_complete { |elapsed, last_time| yield elapsed, last_time }

  state.delete
  success?
end

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bard/plugins/deploy/ci/runner.rb', line 40

def run
  start
  @start_time = Time.new.to_i
  @last_time_elapsed = get_last_time_elapsed
  save_state
  wait_until_started

  poll_until_complete { |elapsed, last_time| yield elapsed, last_time }

  state.delete
  success?
end