Skip to content

Commit

Permalink
Rewrite Foreman's testing to a matrix
Browse files Browse the repository at this point in the history
This makes it easier to change the Ruby versions and also test on
multiple at the same time.
  • Loading branch information
ekohl committed Jan 6, 2025
1 parent e4c5579 commit eb7ef22
Showing 1 changed file with 45 additions and 79 deletions.
124 changes: 45 additions & 79 deletions theforeman.org/pipelines/release/source/foreman.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,64 @@ pipeline {
buildDiscarder(logRotator(daysToKeepStr: '7'))
}

environment {
BUNDLE_WITHOUT = 'development'
RAILS_ENV = TASK == 'assets:precompile' ? 'production' : 'test'
// TODO: replace invalid chars
// TODO: strip *: from TASK
// TODO: limit DB name length to < 63 chars
DATABASE_URL = TASK == 'assets:precompile' ? 'nulldb://nohost' : "postgresql://foreman:foreman@localhost/test-${env.JOB_NAME}-${env.BUILD_ID}-${RUBY_VER}-${TASK}"
TESTOPTS = '-v'
}

stages {
stage('Test Matrix') {
parallel {
stage('ruby-2.7-postgres') {
agent { label 'fast' }
environment {
RUBY_VER = '2.7.6'
matrix {
agent { label 'fast' }
axes {
axis {
name 'RUBY_VER'
values '2.7.6'
}
stages {
stage("setup-2.7-postgres") {
steps {
git url: git_url, branch: git_ref
script {
archive_git_hash()
}
databaseFile("${env.JOB_NAME}-${env.BUILD_ID}")
configureDatabase(env.RUBY_VER)
}
}
stage("unit-tests-2.7-postgres") {
steps {
bundleExec(env.RUBY_VER, 'rake jenkins:unit TESTOPTS="-v" --trace')
}
}
}
post {
always {
junit(testResults: 'jenkins/reports/unit/*.xml')
}
cleanup {
cleanup(env.RUBY_VER)
deleteDir()
}
axis {
name 'TASK'
values 'jenkins:unit', 'jenkins:integration', 'assets:precompile'
}
}
stage('ruby-2.7-postgres-integrations') {
agent { label 'fast' }
environment {
RUBY_VER = '2.7.6'
}
stages {
stage("setup-2.7-postgres-ui") {
steps {
git url: git_url, branch: git_ref
databaseFile("${env.JOB_NAME}-${env.BUILD_ID}-ui")
configureDatabase(env.RUBY_VER)
withRuby(env.RUBY_VER, 'npm install --no-audit --legacy-peer-deps')
archiveArtifacts(artifacts: 'package-lock.json')
stages {
stage('setup') {
steps {
git url: git_url, branch: git_ref
script {
archive_git_hash()
}
}
stage("integration-tests-2.7-postgres-ui") {
steps {
bundleExec(env.RUBY_VER, 'rake jenkins:integration TESTOPTS="-v" --trace')
bundleInstall(RUBY_VER)
archiveArtifacts(artifacts: 'Gemfile.lock')
script {
if (TASK == 'assets:precompile') {
sh "cp db/schema.rb.nulldb db/schema.rb"
filter_package_json(RUBY_VER)
}
if (TASK == 'jenkins:integration' || TASK == 'assets:precompile' ){
withRuby(RUBY_VER, 'npm install --no-audit --legacy-peer-deps')
archiveArtifacts(artifacts: 'package-lock.json')
}
}
}
}
post {
always {
junit(testResults: 'jenkins/reports/unit/*.xml')
}
cleanup {
cleanup(env.RUBY_VER)
deleteDir()
stage(TASK) {
steps {
bundleExec(RUBY_VER, "rake ${TASK} --trace")
}
}
}
stage('ruby-2.7-nulldb-assets') {
agent { label 'fast' }
environment {
RUBY_VER = '2.7.6'
}
stages {
stage("setup-2.7-nulldb") {
steps {
git url: git_url, branch: git_ref
bundleInstall(env.RUBY_VER, '--without=development')
sh "cp db/schema.rb.nulldb db/schema.rb"
filter_package_json(env.RUBY_VER)
withRuby(env.RUBY_VER, 'npm install --no-audit --legacy-peer-deps')
}
}
stage("assets-precompile-2.7-nulldb") {
steps {
bundleExec(env.RUBY_VER, 'rake assets:precompile RAILS_ENV=production DATABASE_URL=nulldb://nohost')
}
}
post {
always {
junit(testResults: 'jenkins/reports/*/*.xml', allowEmptyResults: TASK == 'assets:precompile')
}
post {
cleanup {
cleanup(env.RUBY_VER)
deleteDir()
}
cleanup {
bundleExec(RUBY_VER, 'rake db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=true')
deleteDir()
}
}
}
Expand Down

0 comments on commit eb7ef22

Please sign in to comment.