Skip to content

Commit 81bc355

Browse files
committed
(CAT-2344) Updates matrix creation logic
Updates matrix creation logic to only include the version if requested. Introduces a check to ensure the `latest-agent` and `pe-include` options are not used simultaneously.
1 parent 42f8f13 commit 81bc355

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

exe/matrix_from_metadata_v3

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ begin
169169
Action.config(debug: true) if options[:debug]
170170
Action.config(notice: false) if options[:quiet] && !options[:debug]
171171

172+
raise OptionParser::InvalidArgument, 'latest-agent and pe-include are mutually exclusive options' if options[:latest_agent] && options[:pe_include]
173+
172174
# validate provisioners
173175
options[:provision_include].select! do |p|
174176
options[:matrix]['provisioners'].key?(p) or raise OptionParser::InvalidArgument, "--provision-include '#{p}' not found in provisioners"
@@ -276,8 +278,6 @@ options[:metadata]['requirements']&.each do |req|
276278
all_versions = json_data.keys
277279
versionx = all_versions.select { |v| v.start_with?("#{collection['puppet'].to_i}.") }
278280
versionx.sort_by { |v| Gem::Version.new(v) }.last # rubocop:disable Style/RedundantSort
279-
else
280-
'latest'
281281
end
282282

283283
version = collection['puppet'].to_i
@@ -287,7 +287,21 @@ options[:metadata]['requirements']&.each do |req|
287287
else
288288
"#{prefix}#{version}"
289289
end
290-
matrix[:collection] << { collection: group, version: agent_version }
290+
matrix[:collection] << if options[:latest_agent] && collection['puppet'] != 'nightly'
291+
require 'net/http'
292+
require 'json'
293+
require 'uri'
294+
295+
uri = URI('https://forgeapi.puppet.com/private/versions/puppet-agent')
296+
response = Net::HTTP.get_response(uri)
297+
json_data = JSON.parse(response.body)
298+
all_versions = json_data.keys
299+
versionx = all_versions.select { |v| v.start_with?("#{collection['puppet'].to_i}.") }
300+
versionx.sort_by { |v| Gem::Version.new(v) }.last # rubocop:disable Style/RedundantSort
301+
{ collection: group, version: agent_version }
302+
else
303+
group
304+
end
291305

292306
spec_matrix[:include] << {
293307
puppet_version: "~> #{collection['puppet']}",

spec/exe/matrix_from_metadata_v3_spec.rb

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
'{"label":"Ubuntu-22.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:22.04","runner":"ubuntu-latest"}',
3131
'],',
3232
'"collection":[',
33-
'{"collection":"puppetcore8","version":"latest"}',
33+
'"puppetcore8"',
3434
']',
3535
'}'
3636
].join
@@ -63,7 +63,7 @@
6363
'{"label":"Ubuntu-22.04-arm","provider":"provision_service","arch":"arm","image":"ubuntu-2204-lts-arm64","runner":"ubuntu-latest"}',
6464
'],',
6565
'"collection":[',
66-
'{"collection":"puppetcore8","version":"latest"}',
66+
'"puppetcore8"',
6767
']',
6868
'}'
6969
].join
@@ -103,7 +103,7 @@
103103
'{"label":"Ubuntu-22.04-arm","provider":"provision_service","arch":"arm","image":"ubuntu-2204-lts-arm64","runner":"ubuntu-latest"}',
104104
'],',
105105
'"collection":[',
106-
'{"collection":"puppetcore8","version":"latest"}',
106+
'"puppetcore8"',
107107
']',
108108
'}'
109109
].join
@@ -142,7 +142,7 @@
142142
'{"label":"Ubuntu-22.04-arm","provider":"provision_service","arch":"arm","image":"ubuntu-2204-lts-arm64","runner":"ubuntu-latest"}',
143143
'],',
144144
'"collection":[',
145-
'{"collection":"puppetcore8","version":"latest"}',
145+
'"puppetcore8"',
146146
']',
147147
'}'
148148
].join
@@ -175,7 +175,7 @@
175175
'"platforms":[',
176176
'],',
177177
'"collection":[',
178-
'{"collection":"puppetcore8","version":"latest"}',
178+
'"puppetcore8"',
179179
']',
180180
'}'
181181
].join
@@ -215,7 +215,7 @@
215215
'{"label":"Ubuntu-22.04","provider":"docker","arch":"x86_64","image":"litmusimage/ubuntu:22.04","runner":"ubuntu-latest"}',
216216
'],',
217217
'"collection":[',
218-
'{"collection":"puppetcore8","version":"latest"}',
218+
'"puppetcore8"',
219219
']',
220220
'}'
221221
].join
@@ -233,7 +233,7 @@
233233
'::group::spec_matrix'
234234
)
235235
expect(github_output_content).to include(
236-
'"collection":["2023.8.4-puppet_enterprise","2021.7.9-puppet_enterprise",{"collection":"puppetcore8","version":"latest"}'
236+
'"collection":["2023.8.4-puppet_enterprise","2021.7.9-puppet_enterprise","puppetcore8"'
237237
)
238238
expect(github_output_content).to include(
239239
'spec_matrix={"include":[{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
@@ -257,7 +257,7 @@
257257
'{"label":"Ubuntu-22.04-arm","provider":"provision_service","arch":"arm","image":"ubuntu-2204-lts-arm64","runner":"ubuntu-latest"}',
258258
'],',
259259
'"collection":[',
260-
'{"collection":"puppetcore8-nightly","version":"latest"}',
260+
'"puppetcore8-nightly"',
261261
']',
262262
'}'
263263
].join
@@ -280,4 +280,25 @@
280280
)
281281
end
282282
end
283+
284+
context 'with argument --latest-agent' do
285+
let(:result) { run_matrix_from_metadata_v3(['--puppetlabs', '--latest-agent']) }
286+
287+
it 'run successfully' do
288+
expect(result.status_code).to eq 0
289+
end
290+
291+
it 'generates the matrix' do
292+
expect(result.stdout).to include(
293+
'::warning::CentOS-6 no provisioner found',
294+
'::warning::Ubuntu-14.04 no provisioner found',
295+
'::group::matrix',
296+
'::group::spec_matrix'
297+
)
298+
expect(github_output_content).to match(/{"collection":"puppetcore8","version":"\d+\.\d+\.\d+"}/)
299+
expect(github_output_content).to include(
300+
'spec_matrix={"include":[{"puppet_version":"~> 8.0","ruby_version":3.2}]}'
301+
)
302+
end
303+
end
283304
end

0 commit comments

Comments
 (0)