Skip to content

Commit

Permalink
(FEAT) Add PE to matrix_from_metadata_v3
Browse files Browse the repository at this point in the history
  • Loading branch information
coreymbe committed Oct 24, 2024
1 parent 1d97e8f commit dae4f1d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
24 changes: 23 additions & 1 deletion exe/matrix_from_metadata_v3
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ begin

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

opt.on('--pe-include', TrueClass, 'Include Puppet Enterprise LTS') { |o| options.pe_include = o }

opt.on('--puppet-include MAJOR', Integer, 'Select puppet major version') { |o| options.puppet_include << o }
opt.on('--puppet-exclude MAJOR', Integer, 'Filter puppet major version') { |o| options.puppet_exclude << o }

Expand Down Expand Up @@ -219,6 +221,27 @@ options[:metadata]['requirements']&.each do |req|
break
end

gem_req = Gem::Requirement.create(puppet_version_reqs)

# Add PE LTS to the collection matrix
if options[:pe_include]
require 'puppet_forge'

PuppetForge.user_agent = 'Puppet/Litmus'

forge_conn = PuppetForge::Connection.make_connection('https://forge.puppet.com')
pe_tracks = forge_conn.get('/private/versions/pe')
lts_tracklist = pe_tracks.body.select { |ver| ver[:lts] == true }

lts_tracklist.each do |track|
if gem_req.satisfied_by?(Gem::Version.new(track[:versions][0][:puppet].to_s))
matrix[:collection] << "#{track[:latest]}-puppet_enterprise"
else
Action.debug("PE #{track[:latest]} (puppet v#{track[:versions][0][:puppet]}) outside requirements #{puppet_version_reqs}")
end
end
end

options[:matrix]['collections'].each do |collection|
next unless options[:puppet_include].each do |major|
break if major != collection['puppet'].to_i
Expand All @@ -235,7 +258,6 @@ options[:metadata]['requirements']&.each do |req|

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

matrix[:collection] << "puppet#{collection['puppet'].to_i}-nightly"
Expand Down
38 changes: 38 additions & 0 deletions spec/exe/matrix_from_metadata_v3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,42 @@
)
end
end

context 'with --pe-include' do
let(:result) { run_matrix_from_metadata_v3(['--puppetlabs', '--pe-include']) }
let(:matrix) do
[
'matrix={',
'"platforms":[',
'{"label":"AmazonLinux-2","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2","runner":"ubuntu-20.04"},',
'{"label":"AmazonLinux-2023","provider":"docker","arch":"x86_64","image":"litmusimage/amazonlinux:2023","runner":"ubuntu-20.04"},',
'{"label":"Ubuntu-18.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:18.04","runner":"ubuntu-20.04"},',
'{"label":"Ubuntu-22.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:22.04","runner":"ubuntu-latest"}',
'],',
'"collection":[',
'"puppet7-nightly","puppet8-nightly"',
']',
'}'
].join
end

it 'run successfully' do
expect(result.status_code).to eq 0
end

it 'generates the matrix with PE LTS versions' do
expect(result.stdout).to include(
'::warning::CentOS-6 no provisioner found',
'::warning::Ubuntu-14.04 no provisioner found',
'::group::matrix',
'::group::spec_matrix'
)
expect(github_output_content).to include(
'"collection":["2023.8.0-puppet_enterprise","2021.7.9-puppet_enterprise","puppet7-nightly","puppet8-nightly"'
)
expect(github_output_content).to include(
'spec_matrix={"include":[{"puppet_version":"~> 7.24","ruby_version":2.7},{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
)
end
end
end

0 comments on commit dae4f1d

Please sign in to comment.