Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(IAC-1307) Generate spec test matrix #395

Merged
merged 2 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"