Skip to content

Commit

Permalink
Test using rbenv for foreman-installer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Apr 12, 2024
1 parent 00fc3c2 commit ad775dd
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 18 deletions.
30 changes: 30 additions & 0 deletions theforeman.org/pipelines/lib/rbenv.groovy
Original file line number Diff line number Diff line change
@@ -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} bundle exec ${command}"
}

withRuby(version, command)
}

def withRuby(version, command) {
echo command.toString()

sh """
eval "\$(rbenv init -)"
rbenv shell ${version}
${command}
"""
}
30 changes: 12 additions & 18 deletions theforeman.org/pipelines/test/foreman-installer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pipeline {
axes {
axis {
name 'ruby'
values '2.7'
values '2.7.6'
}
axis {
name 'PUPPET_VERSION'
Expand All @@ -23,7 +23,7 @@ pipeline {
exclude {
axis {
name 'ruby'
notValues '2.7'
notValues '2.7.6'
}
axis {
name 'PUPPET_VERSION'
Expand All @@ -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()
}
}
Expand Down
38 changes: 38 additions & 0 deletions theforeman.org/pipelines/test/simple-ruby.groovy
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
8 changes: 8 additions & 0 deletions theforeman.org/yaml/jobs/simple.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
!include-raw:
- pipelines/lib/git.groovy
- pipelines/lib/rvm.groovy
- pipelines/lib/rbenv.groovy
- pipelines/test/foreman-installer.groovy

0 comments on commit ad775dd

Please sign in to comment.