Sha256: 4596ade362856bcba6167b842cef6776b6e315667952baf9d452daf2a00884b9

Contents?: true

Size: 1.6 KB

Versions: 10

Compression:

Stored size: 1.6 KB

Contents

module Gemika
  class Matrix

    ##
    # Load Github Action `.yml` files.
    #
    # @!visibility private
    #
    class GithubActionsConfig
      class << self

        def load_rows(options)
          path = options.fetch(:path, '.github/workflows/test.yml')
          workflow_yml = YAML.load_file(path)

          matrices = workflow_yml.fetch('jobs', {}).values.map do |job|
            job.fetch('strategy', {})['matrix']
          end.reject(&:nil?)

          matrices.map do |matrix|
            matrix_to_rows(matrix)
          end.flatten(1)
        end

        private

        def matrix_to_rows(matrix)
          if (!matrix['ruby'] || !matrix['gemfile']) && (!matrix['include'])
            raise InvalidMatrixDefinition, 'matrix must use the keys "ruby" and "gemfile"'
          end

          rubies = matrix.fetch('ruby', [])
          gemfiles = matrix.fetch('gemfile', [])

          includes = matrix.fetch('include', [])
          excludes = matrix.fetch('exclude', [])

          rows = []
          rubies.each do |ruby|
            gemfiles.each do |gemfile|
              row = { 'ruby' => ruby, 'gemfile' => gemfile }
              rows << row unless excludes.include?(row)
            end
          end

          rows = rows + includes
          rows.map { |row| convert_row(row) }
        end

        def convert_row(row_hash)
          if !row_hash['ruby'] || !row_hash['gemfile']
            raise InvalidMatrixDefinition, 'matrix must use the keys "ruby" and "gemfile"'
          end
          Row.new(:ruby => row_hash['ruby'], :gemfile => row_hash['gemfile'])
        end

      end
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gemika-0.8.4 lib/gemika/matrix/github_actions_config.rb
gemika-0.8.3 lib/gemika/matrix/github_actions_config.rb
gemika-0.8.2 lib/gemika/matrix/github_actions_config.rb
gemika-0.8.1 lib/gemika/matrix/github_actions_config.rb
gemika-0.8.0 lib/gemika/matrix/github_actions_config.rb
gemika-0.7.1 lib/gemika/matrix/github_actions_config.rb
gemika-0.7.0 lib/gemika/matrix/github_actions_config.rb
gemika-0.6.1 lib/gemika/matrix/github_actions_config.rb
gemika-0.6.0 lib/gemika/matrix/github_actions_config.rb
gemika-0.5.0 lib/gemika/matrix/github_actions_config.rb