class Ski::Project

Attributes

credentials[R]
description[R]
pipelines[R]
title[R]

Public Class Methods

new(config) click to toggle source
# File lib/project.rb, line 11
def initialize(config)
  @targets = config.dig('targets')
  @title = config.dig('title')
  @description = config.dig('description')
  @pipelines = config.dig('pipelines')
  @credentials = config.dig('pipelines')
  @fail = false
end

Public Instance Methods

kick_off(pipeline_name) click to toggle source
# File lib/project.rb, line 20
def kick_off(pipeline_name)
  @pipeline = @pipelines.dig(pipeline_name) || nil
  if @pipeline.nil?
    puts 'ERROR: Pipeline does not exist!'
    exit 255
  end
  puts "PROJECT: #{@title}"
  puts "DESCRIPTION: #{@description}"
  puts "PIPELINE: #{pipeline_name}"
  puts "DESCRIPTION: #{@pipeline.dig('description')}"
  puts "TASKS: #{@pipeline.dig('tasks').count}"
  run(tasks, 'TASK:')
  if @fail
    run(error_tasks, 'CATCH:')
  else
    run(success_tasks, 'THEN:')
  end
end

Private Instance Methods

error_tasks() click to toggle source
# File lib/project.rb, line 41
def error_tasks
  @pipeline.dig('catch') || []
end
ff() click to toggle source
# File lib/project.rb, line 53
def ff
  @pipeline.dig('fail-fast')
end
interactive?() click to toggle source
# File lib/project.rb, line 57
def interactive?
  @pipeline.dig('interactive')
end
prompt_next() click to toggle source
# File lib/project.rb, line 61
def prompt_next
  puts 'Run task? (yes/no)'
  input = $stdin.gets.chomp
  if input != 'yes'
    puts 'INFO: Process aborted by user!'
    exit 255
  end
end
run(tasks, prefix) click to toggle source
# File lib/project.rb, line 70
def run(tasks, prefix)
  counter = 1
  tasks.each do |key, value|
    puts "************ #{prefix} Running: #{key} (#{counter}/#{tasks.count}) ************"
    prompt_next if interactive?
    stdout, stderr, status = Open3.capture3(value.dig('command').to_s)
    if status.exitstatus != 0
      @fail = true
      puts "STDERR: #{status.exitstatus} #{ stderr if stderr != ''}"
      break if ff
    end
    puts stdout
    counter += 1
  end
end
success_tasks() click to toggle source
# File lib/project.rb, line 45
def success_tasks
  @pipeline.dig('then') || []
end
tasks() click to toggle source
# File lib/project.rb, line 49
def tasks
  @pipeline.dig('tasks') || []
end