Skip to content

Commit 8f3d896

Browse files
committed
(CAT-2433) Adds option to return latest agent build
Adds a command-line option to specify whether the latest agent build should be included in the matrix. This is due to the Mac and Windows puppet_agent install tasks requiring a specific version when installing.
1 parent c8e9760 commit 8f3d896

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

exe/matrix_from_metadata_v3

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ begin
163163
opt.on('--provision-exclude NAME', String, "Filter provisioner (default: #{default_options[:'provision-exclude'] || 'none'})") { |o| options.provision_exclude.push(*o.split(',')) }
164164

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

168169
Action.config(debug: true) if options[:debug]
@@ -262,13 +263,33 @@ options[:metadata]['requirements']&.each do |req|
262263
# 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.
263264
next unless gem_req.satisfied_by?(Gem::Version.new("#{collection['puppet'].to_i}.9999"))
264265

266+
# # If requested, return the latest agent version for the collection's puppet version
267+
# # If not requested, return the value latest
268+
agent_version = if options[:latest_agent] && collection['puppet'] != 'nightly'
269+
require 'net/http'
270+
require 'json'
271+
require 'uri'
272+
273+
require 'pry'
274+
binding.pry
275+
uri = URI('https://forgeapi.puppet.com/private/versions/puppet-agent')
276+
response = Net::HTTP.get_response(uri)
277+
json_data = JSON.parse(response.body)
278+
all_versions = json_data.keys
279+
versionx = all_versions.select { |v| v.start_with?("#{collection['puppet'].to_i}.") }
280+
versionx.sort_by { |v| Gem::Version.new(v) }.last # rubocop:disable Style/RedundantSort
281+
else
282+
'latest'
283+
end
284+
265285
version = collection['puppet'].to_i
266286
prefix = 'puppetcore'
267-
matrix[:collection] << if options[:nightly]
268-
"#{prefix}#{version}-nightly"
269-
else
270-
"#{prefix}#{version}"
271-
end
287+
group = if options[:nightly]
288+
"#{prefix}#{version}-nightly"
289+
else
290+
"#{prefix}#{version}"
291+
end
292+
matrix[:collection] << { collection: group, version: agent_version }
272293

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

spec/exe/matrix_from_metadata_v3_spec.rb

Lines changed: 8 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-
'"puppetcore8"',
33+
'{"collection":"puppetcore8","version":"latest"}',
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-
'"puppetcore8"',
66+
'{"collection":"puppetcore8","version":"latest"}',
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-
'"puppetcore8"',
106+
'{"collection":"puppetcore8","version":"latest"}',
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-
'"puppetcore8"',
145+
'{"collection":"puppetcore8","version":"latest"}',
146146
']',
147147
'}'
148148
].join
@@ -175,7 +175,7 @@
175175
'"platforms":[',
176176
'],',
177177
'"collection":[',
178-
'"puppetcore8"',
178+
'{"collection":"puppetcore8","version":"latest"}',
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-
'"puppetcore8"',
218+
'{"collection":"puppetcore8","version":"latest"}',
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","puppetcore8"'
236+
'"collection":["2023.8.4-puppet_enterprise","2021.7.9-puppet_enterprise",{"collection":"puppetcore8","version":"latest"}'
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-
'"puppetcore8-nightly"',
260+
'{"collection":"puppetcore8-nightly","version":"latest"}',
261261
']',
262262
'}'
263263
].join

0 commit comments

Comments
 (0)