Skip to content

Commit

Permalink
Merge pull request #395 from sanfrancrisko/IAC-1307/main/ghactions_sp…
Browse files Browse the repository at this point in the history
…ec_tests

(IAC-1307) Generate spec test matrix merged
  • Loading branch information
Disha-maker authored Mar 10, 2021
2 parents 83b824f + 5a7739a commit bdf0e7a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/doc/
/vendor/gems/
/Gemfile.local
/.idea/
39 changes: 29 additions & 10 deletions exe/matrix_from_metadata_v2
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,26 @@ DOCKER_PLATFORMS = {

# This table uses the latest version in each collection for accurate
# comparison when evaluating puppet requirements from the metadata
COLLECTION_TABLE = {
'6.24.0' => 'puppet6-nightly',
'7.4.0' => 'puppet7-nightly',
}.freeze
COLLECTION_TABLE = [
{
puppet_maj_version: 6,
ruby_version: 2.5,
},
{
puppet_maj_version: 7,
ruby_version: 2.7,
},
].freeze

matrix = {
platforms: [],
collection: [],
}

spec_matrix = {
include: [],
}

metadata = JSON.parse(File.read('metadata.json'))
# Set platforms based on declared operating system support
metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
Expand Down Expand Up @@ -83,23 +93,32 @@ if metadata.key?('requirements') && metadata['requirements'].length.positive?
cmp_one, ver_one, cmp_two, ver_two = match.captures
reqs = ["#{cmp_one} #{ver_one}", "#{cmp_two} #{ver_two}"]

COLLECTION_TABLE.each do |key, val|
if Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new(key))
matrix[:collection] << val
end
COLLECTION_TABLE.each do |collection|
# Test against the "largest" puppet version in a collection, e.g. `7.9999` to allow puppet requirements with a non-zero lower bound on minor/patch versions.
# This assumes that such a boundary will always allow the latest actually existing puppet version of a release stream, trading off simplicity vs accuracy here.
next unless Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new("#{collection[:puppet_maj_version]}.9999"))

matrix[:collection] << "puppet#{collection[:puppet_maj_version]}-nightly"
spec_matrix[:include] << { puppet_version: "~> #{collection[:puppet_maj_version]}.0", ruby_version: collection[:ruby_version] }
end
end
end

# Set to defaults (all collections) if no matches are found
if matrix[:collection].empty?
matrix[:collection] = COLLECTION_TABLE.values
matrix[:collection] = COLLECTION_TABLE.map { |collection| "puppet#{collection[:puppet_maj_version]}-nightly" }
end

# Just to make sure there aren't any duplicates
matrix[:platforms] = matrix[:platforms].uniq.sort { |a, b| a[:label] <=> b[:label] }
matrix[:collection] = matrix[:collection].uniq.sort

puts "::set-output name=matrix::#{JSON.generate(matrix)}"
puts "::set-output name=spec_matrix::#{JSON.generate(spec_matrix)}"

acceptance_test_cell_count = matrix[:platforms].length * matrix[:collection].length
spec_test_cell_count = spec_matrix[:include].length

puts "Created matrix with #{matrix[:platforms].length * matrix[:collection].length} cells."
puts "Created matrix with #{acceptance_test_cell_count + spec_test_cell_count} cells:"
puts " - Acceptance Test Cells: #{acceptance_test_cell_count}"
puts " - Spec Test Cells: #{spec_test_cell_count}"

0 comments on commit bdf0e7a

Please sign in to comment.