Sha256: 42cf5ec182ee4aab033253dccf31c6267a3b9ee3a95281b9a9b598877a6a2753

Contents?: true

Size: 1.64 KB

Versions: 6

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module Buildkite
  module Builder
    module Processors
      class Abstract
        include LoggingUtils
        using Rainbow

        def self.process(runner)
          new(runner).run
        end

        def initialize(runner)
          @runner = runner
        end

        def run
          _log_run { process }
        end

        private

        attr_reader :runner

        def process
          raise NotImplementedError
        end

        def log
          runner.log
        end

        def pipeline
          runner.pipeline
        end

        def buildkite
          @buildkite ||= begin
            unless Buildkite.env
              raise 'Must be in Buildkite environment to access the Buildkite API'
            end

            Buildkite::Pipelines::Api.new(Buildkite.env.api_token)
          end
        end

        def pipeline_steps(*types)
          steps = pipeline.steps
          types = types.flatten
          steps = steps.select { |step| types.include?(step.class.to_sym) } if types.any?
          steps
        end

        def _log_run
          log.info "\nProcessing ".color(:dimgray) + self.class.name.color(:springgreen)

          results = benchmark('└──'.color(:springgreen) + ' Finished in %s'.color(:dimgray)) do
            formatter = log.formatter
            log.formatter = proc do |_severity, _datetime, _progname, msg|
              '│'.color(:springgreen) + " #{msg}\n"
            end

            begin
              yield
            ensure
              log.formatter = formatter
            end
          end

          log.info results
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
buildkite-builder-1.0.0 lib/buildkite/builder/processors/abstract.rb
buildkite-builder-1.0.0.beta.5 lib/buildkite/builder/processors/abstract.rb
buildkite-builder-1.0.0.beta.4 lib/buildkite/builder/processors/abstract.rb
buildkite-builder-1.0.0.beta.3 lib/buildkite/builder/processors/abstract.rb
buildkite-builder-1.0.0.beta.2 lib/buildkite/builder/processors/abstract.rb
buildkite-builder-1.0.0.beta.1 lib/buildkite/builder/processors/abstract.rb