From 86236ff11b796be1a4b4586ca216f2dedd05184c Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Thu, 11 Apr 2024 14:03:37 -0400 Subject: [PATCH] Test using rbenv for foreman-installer tests --- theforeman.org/pipelines/lib/rbenv.groovy | 32 +++++++++++++++++++ .../pipelines/test/foreman-installer.groovy | 30 +++++++---------- .../jobs/tests/foreman-installer-pr-test.yaml | 1 + 3 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 theforeman.org/pipelines/lib/rbenv.groovy diff --git a/theforeman.org/pipelines/lib/rbenv.groovy b/theforeman.org/pipelines/lib/rbenv.groovy new file mode 100644 index 00000000..ad454c9e --- /dev/null +++ b/theforeman.org/pipelines/lib/rbenv.groovy @@ -0,0 +1,32 @@ +def bundleInstall(version, gemfile=null) { + command = "bundle install" + + if (gemfile) { + command = "${command} --gemfile=${gemfile}" + } + + withRuby(version, "bundle config set path ~/.rubygems") + withRuby(version, command) +} + +def bundleExec(version, command, gemfile=null) { + command = "bundle exec ${command}" + + if (gemfile) { + command = "BUNDLE_GEMFILE=${gemfile} bundle exec ${command}" + } + + withRuby(version, command) +} + +def withRuby(version, command) { + echo command.toString() + + sh """ + set -x + + eval "\$(rbenv init - bash)" + rbenv shell ${version} + ${command} + """ +} diff --git a/theforeman.org/pipelines/test/foreman-installer.groovy b/theforeman.org/pipelines/test/foreman-installer.groovy index a1908266..0c775430 100644 --- a/theforeman.org/pipelines/test/foreman-installer.groovy +++ b/theforeman.org/pipelines/test/foreman-installer.groovy @@ -12,7 +12,7 @@ pipeline { axes { axis { name 'ruby' - values '2.7' + values '2.7.6' } axis { name 'PUPPET_VERSION' @@ -23,7 +23,7 @@ pipeline { exclude { axis { name 'ruby' - notValues '2.7' + notValues '2.7.6' } axis { name 'PUPPET_VERSION' @@ -38,41 +38,35 @@ pipeline { sh "cp Gemfile Gemfile.${ruby}-${PUPPET_VERSION}" } } - stage("Setup RVM") { + stage("bundle-install") { steps { - configureRVM(ruby, "${ruby}-${PUPPET_VERSION}") - } - } - stage('Install dependencies') { - steps { - withRVM(["bundle install --gemfile=Gemfile.${ruby}-${PUPPET_VERSION}"], ruby, "${ruby}-${PUPPET_VERSION}") + bundleInstall(ruby, "Gemfile.${ruby}-${PUPPET_VERSION}") } } stage('Run Rubocop') { steps { - withRVM(["BUNDLE_GEMFILE=Gemfile.${ruby}-${PUPPET_VERSION} bundle exec rake rubocop TESTOPTS='-v' --trace"], ruby, "${ruby}-${PUPPET_VERSION}") + bundleExec(ruby, "rake rubocop TESTOPTS='-v' --trace", "Gemfile.${ruby}-${PUPPET_VERSION}") } } stage('Run Tests') { steps { - withRVM(["BUNDLE_GEMFILE=Gemfile.${ruby}-${PUPPET_VERSION} bundle exec rake spec TESTOPTS='-v' --trace"], ruby, "${ruby}-${PUPPET_VERSION}") + bundleExec(ruby, "rake spec TESTOPTS='-v' --trace", "Gemfile.${ruby}-${PUPPET_VERSION}") } } stage('Test installer configuration') { steps { - withRVM(["BUNDLE_GEMFILE=Gemfile.${ruby}-${PUPPET_VERSION} bundle exec rake install PREFIX=${ruby}-${PUPPET_VERSION} --trace"], ruby, "${ruby}-${PUPPET_VERSION}") - withRVM(["BUNDLE_GEMFILE=Gemfile.${ruby}-${PUPPET_VERSION} bundle exec ${ruby}-${PUPPET_VERSION}/sbin/foreman-installer --help --scenario foreman --trace"], ruby, "${ruby}-${PUPPET_VERSION}") - withRVM(["BUNDLE_GEMFILE=Gemfile.${ruby}-${PUPPET_VERSION} bundle exec ${ruby}-${PUPPET_VERSION}/sbin/foreman-installer --help --scenario foreman-proxy-content --trace"], ruby, "${ruby}-${PUPPET_VERSION}") - withRVM(["BUNDLE_GEMFILE=Gemfile.${ruby}-${PUPPET_VERSION} bundle exec ${ruby}-${PUPPET_VERSION}/sbin/foreman-installer --help --scenario katello --trace"], ruby, "${ruby}-${PUPPET_VERSION}") - withRVM(["BUNDLE_GEMFILE=Gemfile.${ruby}-${PUPPET_VERSION} bundle exec ${ruby}-${PUPPET_VERSION}/sbin/foreman-proxy-certs-generate --help --trace"], ruby, "${ruby}-${PUPPET_VERSION}") - withRVM(["BUNDLE_GEMFILE=Gemfile.${ruby}-${PUPPET_VERSION} bundle exec ${ruby}-${PUPPET_VERSION}/sbin/foreman-proxy-certs-generate --help|grep -q certs-update-server"], ruby, "${ruby}-${PUPPET_VERSION}") + bundleExec(ruby, "rake install PREFIX=${ruby}-${PUPPET_VERSION} --trace", "Gemfile.${ruby}-${PUPPET_VERSION}") + bundleExec(ruby, "${ruby}-${PUPPET_VERSION}/sbin/foreman-installer --help --scenario foreman --trace", "Gemfile.${ruby}-${PUPPET_VERSION}") + bundleExec(ruby, "${ruby}-${PUPPET_VERSION}/sbin/foreman-installer --help --scenario katello --trace", "Gemfile.${ruby}-${PUPPET_VERSION}") + bundleExec(ruby, "${ruby}-${PUPPET_VERSION}/sbin/foreman-installer --help --scenario foreman-proxy-content --trace", "Gemfile.${ruby}-${PUPPET_VERSION}") + bundleExec(ruby, "${ruby}-${PUPPET_VERSION}/sbin/foreman-proxy-certs-generate --help --trace", "Gemfile.${ruby}-${PUPPET_VERSION}") + bundleExec(ruby, "${ruby}-${PUPPET_VERSION}/sbin/foreman-proxy-certs-generate --help|grep -q certs-update-server", "Gemfile.${ruby}-${PUPPET_VERSION}") } } } post { always { archiveArtifacts artifacts: "Gemfile*lock" - cleanupRVM(ruby, "${ruby}-${PUPPET_VERSION}") deleteDir() } } diff --git a/theforeman.org/yaml/jobs/tests/foreman-installer-pr-test.yaml b/theforeman.org/yaml/jobs/tests/foreman-installer-pr-test.yaml index 5ff66da6..8b256846 100644 --- a/theforeman.org/yaml/jobs/tests/foreman-installer-pr-test.yaml +++ b/theforeman.org/yaml/jobs/tests/foreman-installer-pr-test.yaml @@ -13,4 +13,5 @@ !include-raw: - pipelines/lib/git.groovy - pipelines/lib/rvm.groovy + - pipelines/lib/rbenv.groovy - pipelines/test/foreman-installer.groovy