Sha256: 4301e67d37a99a8b5c6ca7df8e324df45b37620883b3d3b826f753fd513840c5

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'logger'

module Buildkite
  module Builder
    class Context
      include Definition::Helper

      PIPELINE_DEFINITION_FILE = Pathname.new('pipeline.rb').freeze

      attr_reader :logger
      attr_reader :root
      attr_reader :pipeline

      def self.build(root, logger: nil)
        context = new(root, logger: logger)
        context.build
        context
      end

      def initialize(root, logger: nil)
        @root = root
        @logger = logger || Logger.new(File::NULL)
      end

      def build
        unless @pipeline
          @pipeline = Pipelines::Pipeline.new

          load_manifests
          load_templates
          load_processors
          load_pipeline
          run_processors
        end

        @pipeline
      end

      private

      def load_manifests
        Loaders::Manifests.load(root).each do |name, asset|
          Manifest[name] = asset
        end
      end

      def load_templates
        Loaders::Templates.load(root).each do |name, asset|
          pipeline.template(name, &asset)
        end
      end

      def load_processors
        Loaders::Processors.load(root)
      end

      def run_processors
        pipeline.processors.each do |processor|
          processor.process(self)
        end
      end

      def load_pipeline
        pipeline.instance_eval(&pipeline_definition)
      end

      def pipeline_definition
        @pipeline_definition ||= load_definition(root.join(PIPELINE_DEFINITION_FILE), Definition::Pipeline)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
buildkite-builder-1.2.0 lib/buildkite/builder/context.rb