diff --git a/bin/metadata2gha b/bin/metadata2gha index d057f1f..eb51f97 100755 --- a/bin/metadata2gha +++ b/bin/metadata2gha @@ -10,6 +10,7 @@ options = { beaker_pidfile_workaround: false, domain: nil, minimum_major_puppet_version: nil, + beaker_fact: nil, } OptionParser.new do |opts| @@ -30,6 +31,15 @@ OptionParser.new do |opts| opts.on('--pidfile-workaround VALUE', 'Generate the systemd PIDFile workaround to work around a docker bug', PidfileWorkaround) { |opt| options[:beaker_pidfile_workaround] = opt } opts.on('-d', '--domain VALUE', 'the domain for the box, only used when --use-fqdn is set to true') { |opt| options[:domain] = opt } opts.on('--minimum-major-puppet-version VERSION', "Don't create actions for Puppet versions less than this major version") { |opt| options[:minimum_major_puppet_version] = opt } + opts.on('--beaker-facter FACT:LABEL:VALUES', 'Expand the matrix based on a fact. Separate values using commas') do |opt| + if opt != 'false' + fact, label, values = opt.split(':', 3) + label = fact if !label || label.empty? + raise OptionParser::InvalidArgument unless values + + options[:beaker_facter] = [fact, label, values.split(',')] + end + end end.parse! filename = ARGV[0] diff --git a/lib/puppet_metadata/github_actions.rb b/lib/puppet_metadata/github_actions.rb index b295271..0b3eb55 100644 --- a/lib/puppet_metadata/github_actions.rb +++ b/lib/puppet_metadata/github_actions.rb @@ -14,6 +14,8 @@ def outputs { puppet_major_versions: puppet_major_versions, puppet_unit_test_matrix: puppet_unit_test_matrix, + puppet_beaker_test_matrix: puppet_beaker_test_matrix, + # Deprecated github_action_test_matrix: github_action_test_matrix, } end @@ -70,16 +72,49 @@ def beaker_os_releases end end - def github_action_test_matrix + def puppet_beaker_test_matrix matrix_include = [] beaker_os_releases do |os, release, puppet_version| - setfile = PuppetMetadata::Beaker.os_release_to_setfile( - os, release, use_fqdn: options[:beaker_use_fqdn], pidfile_workaround: options[:beaker_pidfile_workaround], domain: options[:domain], puppet_version: puppet_version[:collection] - ) + next if puppet_version_below_minimum?(puppet_version[:value]) + + setfile = os_release_to_beaker_setfile(os, release, puppet_version[:collection]) next unless setfile + + name = "#{puppet_version[:name]} - #{setfile[1]}" + env = { + 'BEAKER_PUPPET_COLLECTION' => puppet_version[:collection], + 'BEAKER_SETFILE' => setfile[0], + } + + if options[:beaker_facter] + fact, label, values = options[:beaker_facter] + values.each do |value| + matrix_include << { + name: "#{name} - #{label || fact} #{value}", + env: env.merge("BEAKER_FACTER_#{fact}" => value), + } + end + else + matrix_include << { + name: name, + env: env, + } + end + end + + matrix_include + end + + def github_action_test_matrix + matrix_include = [] + + beaker_os_releases do |os, release, puppet_version| next if puppet_version_below_minimum?(puppet_version[:value]) + setfile = os_release_to_beaker_setfile(os, release, puppet_version[:collection]) + next unless setfile + matrix_include << { name: "#{puppet_version[:name]} - #{setfile[1]}", setfile: { @@ -98,5 +133,16 @@ def puppet_version_below_minimum?(version) Gem::Version.new(version) < Gem::Version.new(options[:minimum_major_puppet_version]) end + + def os_release_to_beaker_setfile(os, release, puppet_collection) + PuppetMetadata::Beaker.os_release_to_setfile( + os, + release, + use_fqdn: options[:beaker_use_fqdn], + pidfile_workaround: options[:beaker_pidfile_workaround], + domain: options[:domain], + puppet_version: puppet_collection, + ) + end end end diff --git a/spec/github_actions_spec.rb b/spec/github_actions_spec.rb index 37b4541..39ca228 100644 --- a/spec/github_actions_spec.rb +++ b/spec/github_actions_spec.rb @@ -52,7 +52,7 @@ let(:beaker_use_fqdn) { false } it { is_expected.to be_an_instance_of(Hash) } - it { expect(subject.keys).to contain_exactly(:puppet_major_versions, :puppet_unit_test_matrix, :github_action_test_matrix) } + it { expect(subject.keys).to contain_exactly(:puppet_major_versions, :puppet_unit_test_matrix, :puppet_beaker_test_matrix, :github_action_test_matrix) } describe 'puppet_major_versions' do subject { super()[:puppet_major_versions] } @@ -111,6 +111,47 @@ end end + describe 'puppet_beaker_test_matrix' do + subject { super()[:puppet_beaker_test_matrix] } + + it { is_expected.to be_an_instance_of(Array) } + + it 'is expected to contain supported os / puppet version combinations' do + expect(subject).to contain_exactly( + { name: 'Distro Puppet - Archlinux rolling', env: { 'BEAKER_PUPPET_COLLECTION' => 'none', 'BEAKER_SETFILE' => 'archlinuxrolling-64' } }, + { name: 'Puppet 5 - CentOS 7', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet5', 'BEAKER_SETFILE' => 'centos7-64' } }, + { name: 'Puppet 6 - CentOS 7', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'centos7-64' } }, + { name: 'Puppet 7 - CentOS 7', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'centos7-64' } }, + { name: 'Puppet 8 - CentOS 7', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet8', 'BEAKER_SETFILE' => 'centos7-64' } }, + { name: 'Puppet 5 - CentOS 8', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet5', 'BEAKER_SETFILE' => 'centos8-64' } }, + { name: 'Puppet 6 - CentOS 8', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'centos8-64' } }, + { name: 'Puppet 7 - CentOS 8', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'centos8-64' } }, + { name: 'Puppet 8 - CentOS 8', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet8', 'BEAKER_SETFILE' => 'centos8-64' } }, + { name: 'Puppet 6 - CentOS 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'centos9-64' } }, + { name: 'Puppet 7 - CentOS 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'centos9-64' } }, + { name: 'Puppet 8 - CentOS 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet8', 'BEAKER_SETFILE' => 'centos9-64' } }, + { name: 'Puppet 5 - Debian 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet5', 'BEAKER_SETFILE' => 'debian9-64' } }, + { name: 'Puppet 6 - Debian 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'debian9-64' } }, + { name: 'Puppet 7 - Debian 9', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'debian9-64' } }, + { name: 'Puppet 5 - Debian 10', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet5', 'BEAKER_SETFILE' => 'debian10-64' } }, + { name: 'Puppet 6 - Debian 10', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet6', 'BEAKER_SETFILE' => 'debian10-64' } }, + { name: 'Puppet 7 - Debian 10', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet7', 'BEAKER_SETFILE' => 'debian10-64' } }, + { name: 'Puppet 8 - Debian 10', env: { 'BEAKER_PUPPET_COLLECTION' => 'puppet8', 'BEAKER_SETFILE' => 'debian10-64' } }, + ) + end + + context 'with beaker_facter option' do + let(:options) { super().merge(beaker_facter: ['pulpcore_version', 'Pulp', %w[2 3]]) } + + it 'is expected to contain supported os / puppet version / fact combinations' do + expect(subject).to include( + { name: 'Distro Puppet - Archlinux rolling - Pulp 2', env: { 'BEAKER_PUPPET_COLLECTION' => 'none', 'BEAKER_SETFILE' => 'archlinuxrolling-64', 'BEAKER_FACTER_pulpcore_version' => '2' } }, + { name: 'Distro Puppet - Archlinux rolling - Pulp 3', env: { 'BEAKER_PUPPET_COLLECTION' => 'none', 'BEAKER_SETFILE' => 'archlinuxrolling-64', 'BEAKER_FACTER_pulpcore_version' => '3' } }, + ) + end + end + end + describe 'github_action_test_matrix' do subject { super()[:github_action_test_matrix] }