Skip to content
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ in the project module root directory run `bundle exec matrix_from_metadata_v3`
| --provision-include | NAME | all | Select provisioner |
| --provision-exclude | NAME | provision_service | Filter provisioner |
| --nightly | | | Install from the nightly puppetcore images |
| --latest-agent | | | Return the latest agent version as part of the matrix. Note: This changes how the collection is returned |

> Refer to the [built-in matrix.json](https://github.com/puppetlabs/puppet_litmus/blob/main/exe/matrix.json) for a list of supported collection, provisioners, and platforms.

Expand Down
39 changes: 36 additions & 3 deletions exe/matrix_from_metadata_v3
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ begin
opt.on('--provision-exclude NAME', String, "Filter provisioner (default: #{default_options[:'provision-exclude'] || 'none'})") { |o| options.provision_exclude.push(*o.split(',')) }

opt.on('--nightly', TrueClass, 'Enable nightly builds') { |o| options.nightly = o }
opt.on('--latest-agent', TrueClass, 'Return the latest agent build as part of the matrix') { |o| options.latest_agent = o }
end.parse!

Action.config(debug: true) if options[:debug]
Action.config(notice: false) if options[:quiet] && !options[:debug]

raise OptionParser::InvalidArgument, 'latest-agent and pe-include are mutually exclusive options' if options[:latest_agent] && options[:pe_include]

# validate provisioners
options[:provision_include].select! do |p|
options[:matrix]['provisioners'].key?(p) or raise OptionParser::InvalidArgument, "--provision-include '#{p}' not found in provisioners"
Expand Down Expand Up @@ -262,12 +265,42 @@ options[:metadata]['requirements']&.each do |req|
# 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_req.satisfied_by?(Gem::Version.new("#{collection['puppet'].to_i}.9999"))

# # If requested, return the latest agent version for the collection's puppet version
# # If not requested, return the value latest
agent_version = if options[:latest_agent] && collection['puppet'] != 'nightly'
require 'net/http'
require 'json'
require 'uri'

uri = URI('https://forgeapi.puppet.com/private/versions/puppet-agent')
response = Net::HTTP.get_response(uri)
json_data = JSON.parse(response.body)
all_versions = json_data.keys
versionx = all_versions.select { |v| v.start_with?("#{collection['puppet'].to_i}.") }
versionx.sort_by { |v| Gem::Version.new(v) }.last # rubocop:disable Style/RedundantSort
end

version = collection['puppet'].to_i
prefix = 'puppetcore'
matrix[:collection] << if options[:nightly]
"#{prefix}#{version}-nightly"
group = if options[:nightly]
"#{prefix}#{version}-nightly"
else
"#{prefix}#{version}"
end
matrix[:collection] << if options[:latest_agent] && collection['puppet'] != 'nightly'
require 'net/http'
require 'json'
require 'uri'

uri = URI('https://forgeapi.puppet.com/private/versions/puppet-agent')
response = Net::HTTP.get_response(uri)
json_data = JSON.parse(response.body)
all_versions = json_data.keys
versionx = all_versions.select { |v| v.start_with?("#{collection['puppet'].to_i}.") }
versionx.sort_by { |v| Gem::Version.new(v) }.last # rubocop:disable Style/RedundantSort
{ collection: group, version: agent_version }
else
"#{prefix}#{version}"
group
end

spec_matrix[:include] << {
Expand Down
21 changes: 21 additions & 0 deletions spec/exe/matrix_from_metadata_v3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,25 @@
)
end
end

context 'with argument --latest-agent' do
let(:result) { run_matrix_from_metadata_v3(['--puppetlabs', '--latest-agent']) }

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

it 'generates the matrix' 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 match(/{"collection":"puppetcore8","version":"\d+\.\d+\.\d+"}/)
expect(github_output_content).to include(
'spec_matrix={"include":[{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
)
end
end
end