From 2c160b8115f0e2bf8b6fe5d3952e8c02f05d9782 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 | 30 +++++++++++++++ .../pipelines/test/foreman-installer.groovy | 30 ++++++--------- .../pipelines/test/simple-ruby.groovy | 38 +++++++++++++++++++ theforeman.org/yaml/jobs/simple.yaml | 8 ++++ .../jobs/tests/foreman-installer-pr-test.yaml | 1 + 5 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 theforeman.org/pipelines/lib/rbenv.groovy create mode 100644 theforeman.org/pipelines/test/simple-ruby.groovy create mode 100644 theforeman.org/yaml/jobs/simple.yaml diff --git a/theforeman.org/pipelines/lib/rbenv.groovy b/theforeman.org/pipelines/lib/rbenv.groovy new file mode 100644 index 00000000..b6ffc7f4 --- /dev/null +++ b/theforeman.org/pipelines/lib/rbenv.groovy @@ -0,0 +1,30 @@ +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} ${command}" + } + + withRuby(version, command) +} + +def withRuby(version, command) { + echo command.toString() + + sh """ + export PATH="\$HOME/.rbenv/shims:\$PATH" + export RBENV_VERSION=${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/pipelines/test/simple-ruby.groovy b/theforeman.org/pipelines/test/simple-ruby.groovy new file mode 100644 index 00000000..037581ad --- /dev/null +++ b/theforeman.org/pipelines/test/simple-ruby.groovy @@ -0,0 +1,38 @@ +def ruby = '2.7.6' + +pipeline { + agent { label 'el8' } + options { + timeout(time: 1, unit: 'HOURS') + ansiColor('xterm') + } + + stages { + stage('Setup Git Repos') { + steps { + git url: 'https://github.com/theforeman/foreman-installer', branch: 'develop' + sh "cp Gemfile Gemfile.${ruby}" + } + } + stage("bundle-install") { + steps { + bundleInstall(ruby, "Gemfile.${ruby}") + } + } + stage('Run Rubocop') { + steps { + bundleExec(ruby, "rake rubocop TESTOPTS='-v' --trace", "Gemfile.${ruby}") + } + } + stage('Run Tests') { + steps { + bundleExec(ruby, "rake spec TESTOPTS='-v' --trace", "Gemfile.${ruby}") + } + } + } + post { + always { + deleteDir() + } + } +} diff --git a/theforeman.org/yaml/jobs/simple.yaml b/theforeman.org/yaml/jobs/simple.yaml new file mode 100644 index 00000000..0ef417b8 --- /dev/null +++ b/theforeman.org/yaml/jobs/simple.yaml @@ -0,0 +1,8 @@ +- job: + name: simple-ruby-test + project-type: pipeline + sandbox: true + dsl: + !include-raw: + - pipelines/lib/rbenv.groovy + - pipelines/test/simple-ruby.groovy 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