Class: TinyCI::Runner

Inherits:
Object
  • Object
show all
Includes:
GitUtils, Logging, Subprocesses
Defined in:
lib/tinyci/runner.rb

Overview

Responsible for managing the running of TinyCI against a single git object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GitUtils

#git_cmd, #git_directory_path, #inside_bare_repo?, #inside_git_directory?, #inside_repository?, #inside_work_tree?, #repo_root

Methods included from Subprocesses

#execute, #execute_pipe, #execute_stream

Constructor Details

#initialize(working_dir: '.', commit:, time: nil, logger: nil, config: nil) ⇒ Runner

Constructor, allows injection of generic configuration params.

Parameters:

  • working_dir (String) (defaults to: '.')

    The working directory to execute against.

  • commit (String)

    SHA1 of git object to run against

  • logger (Logger) (defaults to: nil)

    Logger object

  • time (Time) (defaults to: nil)

    Override time of object creation. Used solely for testing at this time.

  • config (Hash) (defaults to: nil)

    Override TinyCI config object, normally loaded from .tinyci file. Used solely for testing at this time.



36
37
38
39
40
41
42
# File 'lib/tinyci/runner.rb', line 36

def initialize(working_dir: '.', commit:, time: nil, logger: nil, config: nil)
  @working_dir = working_dir
  @logger = logger
  @config = config
  @commit = commit
  @time = time || commit_time
end

Instance Attribute Details

#builderTinyCI::Executor

Returns the Builder object. Used solely for testing at this time.

Returns:



22
23
24
# File 'lib/tinyci/runner.rb', line 22

def builder
  @builder
end

#testerTinyCI::Executor

Returns the Tester object. Used solely for testing at this time.

Returns:



22
23
24
# File 'lib/tinyci/runner.rb', line 22

def tester
  @tester
end

Instance Method Details

#run!Boolean

Runs the TinyCI system against the single git object referenced in @commit.

Returns:

  • (Boolean)

    true if the commit was built and tested successfully, false otherwise



47
48
49
50
51
52
53
54
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
83
84
85
86
87
88
89
90
91
# File 'lib/tinyci/runner.rb', line 47

def run!
  begin
    ensure_path target_path
    setup_log
    
    log_info "Commit: #{@commit}"
    
    log_info "Cleaning..."
    clean
    
    log_info "Exporting..."
    ensure_path export_path
    export
    
    begin
      load_config
    rescue ConfigMissingError => e
      log_error e.message
      log_error 'Removing export...'
      clean
      
      return false
    end
    @builder ||= instantiate_builder
    @tester  ||= instantiate_tester
    
    log_info "Building..."
    @builder.build
    
    log_info "Testing..."
    @tester.test
    
    log_info "Finished #{@commit}"
  rescue => e
      raise e if ENV['TINYCI_ENV'] == 'test'
      
      log_error e
      log_error e.backtrace
    return false
  ensure

  end
  
  true
end