Skip to content

Commit bdf0e7a

Browse files
authored
Merge pull request #395 from sanfrancrisko/IAC-1307/main/ghactions_spec_tests
(IAC-1307) Generate spec test matrix merged
2 parents 83b824f + 5a7739a commit bdf0e7a

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/doc/
88
/vendor/gems/
99
/Gemfile.local
10+
/.idea/

exe/matrix_from_metadata_v2

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,26 @@ DOCKER_PLATFORMS = {
3434

3535
# This table uses the latest version in each collection for accurate
3636
# comparison when evaluating puppet requirements from the metadata
37-
COLLECTION_TABLE = {
38-
'6.24.0' => 'puppet6-nightly',
39-
'7.4.0' => 'puppet7-nightly',
40-
}.freeze
37+
COLLECTION_TABLE = [
38+
{
39+
puppet_maj_version: 6,
40+
ruby_version: 2.5,
41+
},
42+
{
43+
puppet_maj_version: 7,
44+
ruby_version: 2.7,
45+
},
46+
].freeze
4147

4248
matrix = {
4349
platforms: [],
4450
collection: [],
4551
}
4652

53+
spec_matrix = {
54+
include: [],
55+
}
56+
4757
metadata = JSON.parse(File.read('metadata.json'))
4858
# Set platforms based on declared operating system support
4959
metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
@@ -83,23 +93,32 @@ if metadata.key?('requirements') && metadata['requirements'].length.positive?
8393
cmp_one, ver_one, cmp_two, ver_two = match.captures
8494
reqs = ["#{cmp_one} #{ver_one}", "#{cmp_two} #{ver_two}"]
8595

86-
COLLECTION_TABLE.each do |key, val|
87-
if Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new(key))
88-
matrix[:collection] << val
89-
end
96+
COLLECTION_TABLE.each do |collection|
97+
# 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.
98+
# 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.
99+
next unless Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new("#{collection[:puppet_maj_version]}.9999"))
100+
101+
matrix[:collection] << "puppet#{collection[:puppet_maj_version]}-nightly"
102+
spec_matrix[:include] << { puppet_version: "~> #{collection[:puppet_maj_version]}.0", ruby_version: collection[:ruby_version] }
90103
end
91104
end
92105
end
93106

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

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

103116
puts "::set-output name=matrix::#{JSON.generate(matrix)}"
117+
puts "::set-output name=spec_matrix::#{JSON.generate(spec_matrix)}"
118+
119+
acceptance_test_cell_count = matrix[:platforms].length * matrix[:collection].length
120+
spec_test_cell_count = spec_matrix[:include].length
104121

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

0 commit comments

Comments
 (0)