diff --git a/theforeman.org/pipelines/lib/foreman.groovy b/theforeman.org/pipelines/lib/foreman.groovy index 97242bdc..14e86100 100644 --- a/theforeman.org/pipelines/lib/foreman.groovy +++ b/theforeman.org/pipelines/lib/foreman.groovy @@ -1,3 +1,22 @@ +def railsEnvForTask(task, env) { + if (task == 'assets:precompile') { + return 'nulldb://nohost' + } else { + // TODO: limit DB name length to < 63 chars + ruby = env.RUBY_VER.split('.')[0..1] + task_id = task.split(':')[1] + database = (['test', env.JOB_NAME, env.BUILD_ID] + ruby + [task_id]).join('-') + if (database.size() > 63) { + error "${id} cannot be used to generate a PostgreSQL DB name, the resulting name would be longer than 63 chars." + } + return "postgresql://foreman:foreman@localhost/${database}" + } +} + +def databaseUrlForTask(task) { + return task == 'assets:precompile' ? 'production' : 'test' +} + def databaseFile(id) { text = postgresqlTemplate(id) writeFile(file: 'config/database.yml', text: text) diff --git a/theforeman.org/pipelines/release/source/foreman.groovy b/theforeman.org/pipelines/release/source/foreman.groovy index 9943a0bc..2ad9bb53 100644 --- a/theforeman.org/pipelines/release/source/foreman.groovy +++ b/theforeman.org/pipelines/release/source/foreman.groovy @@ -8,98 +8,61 @@ pipeline { buildDiscarder(logRotator(daysToKeepStr: '7')) } + environment { + BUNDLE_WITHOUT = 'development' + RAILS_ENV = railsEnvForTask(TASK) + DATABASE_URL = databaseUrlForTask(TASK, env) + 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() } } }