Skip to content

Commit

Permalink
Merge pull request #385 from carabasdaniel/dockermatrix
Browse files Browse the repository at this point in the history
Add docker images to matrix from metadata
  • Loading branch information
DavidS authored Feb 18, 2021
2 parents 877ab3e + befbb02 commit 624b699
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions exe/matrix_from_metadata_v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# this script creates a build matrix for github actions from the claimed supported platforms and puppet versions in metadata.json

require 'json'

IMAGE_TABLE = {
'RedHat-7' => 'rhel-7',
'RedHat-8' => 'rhel-8',
'SLES-12' => 'sles-12',
'SLES-15' => 'sles-15',
'Windows-2012 R2' => 'windows-2012-r2-core',
'Windows-2016' => 'windows-2016',
'Windows-2019' => 'windows-2019-core',
}.freeze

DOCKER_PLATFORMS = {
'CentOS-6' => 'litmusimage/centos:6',
'CentOS-7' => 'litmusimage/centos:7',
'CentOS-8' => 'litmusimage/centos:8',
'Debian-10' => 'litmusimage/debian:10',
'Debian-8' => 'litmusimage/debian:8',
'Debian-9' => 'litmusimage/debian:9',
'OracleLinux-6' => 'litmusimage/oraclelinux:6',
'OracleLinux-7' => 'litmusimage/oraclelinux:7',
'Scientific-6' => 'litmusimage/scientificlinux:6',
'Scientific-7' => 'litmusimage/scientificlinux:7',
'Ubuntu-14.04' => 'litmusimage/ubuntu:14.04',
'Ubuntu-16.04' => 'litmusimage/ubuntu:16.04',
'Ubuntu-18.04' => 'litmusimage/ubuntu:18.04',
'Ubuntu-20.04' => 'litmusimage/ubuntu:20.04',
}.freeze

# This table uses the latest version in each collection for accurate
# comparison when evaluating puppet requirements from the metadata
COLLECTION_TABLE = {
'6.24.0' => 'puppet6-nightly',
'7.4.0' => 'puppet7-nightly',
}.freeze

matrix = {
platforms: [],
collection: [],
}

metadata = JSON.parse(File.read('metadata.json'))
# Set platforms based on declared operating system support
metadata['operatingsystem_support'].sort_by { |a| a['operatingsystem'] }.each do |sup|
os = sup['operatingsystem']
sup['operatingsystemrelease'].sort_by { |a| a.to_i }.each do |ver|
image_key = "#{os}-#{ver}"
if IMAGE_TABLE.key? image_key
matrix[:platforms] << {
label: image_key,
provider: 'provision::provision_service',
image: IMAGE_TABLE[image_key],
}
elsif DOCKER_PLATFORMS.key? image_key
matrix[:platforms] << {
label: image_key,
provider: 'provision::docker',
image: DOCKER_PLATFORMS[image_key],
}
else
puts "::warning::Cannot find image for #{image_key}"
end
end
end

# Set collections based on puppet version requirements
if metadata.key?('requirements') && metadata['requirements'].length.positive?
metadata['requirements'].each do |req|
next unless req.key?('name') && req.key?('version_requirement') && req['name'] == 'puppet'

ver_regexp = %r{^([>=<]{1,2})\s*([\d.]+)\s+([>=<]{1,2})\s*([\d.]+)$}
match = ver_regexp.match(req['version_requirement'])
if match.nil?
puts "::warning::Didn't recognize version_requirement '#{req['version_requirement']}'"
break
end

cmp_one, ver_one, cmp_two, ver_two = match.captures
reqs = ["#{cmp_one} #{ver_one}", "#{cmp_two} #{ver_two}"]

COLLECTION_TABLE.each do |key, val|
if Gem::Requirement.create(reqs).satisfied_by?(Gem::Version.new(key))
matrix[:collection] << val
end
end
end
end

# Set to defaults (all collections) if no matches are found
if matrix[:collection].empty?
matrix[:collection] = COLLECTION_TABLE.values
end

# Just to make sure there aren't any duplicates
matrix[:platforms] = matrix[:platforms].uniq.sort { |a, b| a[:label] <=> b[:label] }
matrix[:collection] = matrix[:collection].uniq.sort

puts "::set-output name=matrix::#{JSON.generate(matrix)}"

puts "Created matrix with #{matrix[:platforms].length * matrix[:collection].length} cells."

0 comments on commit 624b699

Please sign in to comment.