Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test using rbenv for foreman-installer tests #442

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} ${command}"
}

withRuby(version, command)
}

def withRuby(version, command) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative approach would be to include a check for if a particular environment variable is set (e.g. RUBY_VERSION) then use it unless version is explicitly specified. That would allow not having to pass the ruby version as the first argument everytime if we find that annoying.

echo command.toString()

sh """
export PATH="\$HOME/.rbenv/shims:\$PATH"
export RBENV_VERSION=${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