Skip to content

Commit dae4f1d

Browse files
committed
(FEAT) Add PE to matrix_from_metadata_v3
1 parent 1d97e8f commit dae4f1d

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

exe/matrix_from_metadata_v3

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ begin
147147

148148
opt.on('--runner NAME', String, "Default Github action runner (default: #{default_options[:runner]})") { |o| options.runner = o }
149149

150+
opt.on('--pe-include', TrueClass, 'Include Puppet Enterprise LTS') { |o| options.pe_include = o }
151+
150152
opt.on('--puppet-include MAJOR', Integer, 'Select puppet major version') { |o| options.puppet_include << o }
151153
opt.on('--puppet-exclude MAJOR', Integer, 'Filter puppet major version') { |o| options.puppet_exclude << o }
152154

@@ -219,6 +221,27 @@ options[:metadata]['requirements']&.each do |req|
219221
break
220222
end
221223

224+
gem_req = Gem::Requirement.create(puppet_version_reqs)
225+
226+
# Add PE LTS to the collection matrix
227+
if options[:pe_include]
228+
require 'puppet_forge'
229+
230+
PuppetForge.user_agent = 'Puppet/Litmus'
231+
232+
forge_conn = PuppetForge::Connection.make_connection('https://forge.puppet.com')
233+
pe_tracks = forge_conn.get('/private/versions/pe')
234+
lts_tracklist = pe_tracks.body.select { |ver| ver[:lts] == true }
235+
236+
lts_tracklist.each do |track|
237+
if gem_req.satisfied_by?(Gem::Version.new(track[:versions][0][:puppet].to_s))
238+
matrix[:collection] << "#{track[:latest]}-puppet_enterprise"
239+
else
240+
Action.debug("PE #{track[:latest]} (puppet v#{track[:versions][0][:puppet]}) outside requirements #{puppet_version_reqs}")
241+
end
242+
end
243+
end
244+
222245
options[:matrix]['collections'].each do |collection|
223246
next unless options[:puppet_include].each do |major|
224247
break if major != collection['puppet'].to_i
@@ -235,7 +258,6 @@ options[:metadata]['requirements']&.each do |req|
235258

236259
# 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.
237260
# 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.
238-
gem_req = Gem::Requirement.create(puppet_version_reqs)
239261
next unless gem_req.satisfied_by?(Gem::Version.new("#{collection['puppet'].to_i}.9999"))
240262

241263
matrix[:collection] << "puppet#{collection['puppet'].to_i}-nightly"

spec/exe/matrix_from_metadata_v3_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,42 @@
202202
)
203203
end
204204
end
205+
206+
context 'with --pe-include' do
207+
let(:result) { run_matrix_from_metadata_v3(['--puppetlabs', '--pe-include']) }
208+
let(:matrix) do
209+
[
210+
'matrix={',
211+
'"platforms":[',
212+
'{"label":"AmazonLinux-2","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2","runner":"ubuntu-20.04"},',
213+
'{"label":"AmazonLinux-2023","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2023","runner":"ubuntu-20.04"},',
214+
'{"label":"Ubuntu-18.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:18.04","runner":"ubuntu-20.04"},',
215+
'{"label":"Ubuntu-22.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:22.04","runner":"ubuntu-latest"}',
216+
'],',
217+
'"collection":[',
218+
'"puppet7-nightly","puppet8-nightly"',
219+
']',
220+
'}'
221+
].join
222+
end
223+
224+
it 'run successfully' do
225+
expect(result.status_code).to eq 0
226+
end
227+
228+
it 'generates the matrix with PE LTS versions' do
229+
expect(result.stdout).to include(
230+
'::warning::CentOS-6 no provisioner found',
231+
'::warning::Ubuntu-14.04 no provisioner found',
232+
'::group::matrix',
233+
'::group::spec_matrix'
234+
)
235+
expect(github_output_content).to include(
236+
'"collection":["2023.8.0-puppet_enterprise","2021.7.9-puppet_enterprise","puppet7-nightly","puppet8-nightly"'
237+
)
238+
expect(github_output_content).to include(
239+
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
240+
)
241+
end
242+
end
205243
end

0 commit comments

Comments
 (0)