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

Rewrite Foreman's testing to a matrix #523

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Jan 6, 2025

This makes it easier to change the Ruby versions and also test on multiple at the same time.

@ekohl ekohl force-pushed the rewrite-foreman-to-matrix branch from 8e514a0 to b6c2740 Compare January 6, 2025 17:35
@ekohl ekohl marked this pull request as draft January 6, 2025 17:35
@ekohl ekohl force-pushed the rewrite-foreman-to-matrix branch 3 times, most recently from c4b125a to d147dd6 Compare January 6, 2025 18:09
@ekohl ekohl marked this pull request as ready for review January 6, 2025 18:11
axes {
axis {
name 'RUBY_VER'
values '2.7.6'
Copy link
Member Author

Choose a reason for hiding this comment

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

I still struggle with this and variables, but I really didn't want to also implement https://www.jenkins.io/blog/2019/12/02/matrix-building-with-scripted-pipeline/. On the other hand, how we typically write our pipelines is actually more scripted anyway.

Copy link
Member

Choose a reason for hiding this comment

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

What's the struggle here? That you can't define it in pipelines/vars/foreman/nightly.groovy and then say values my_variable?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's indeed my struggle. AFAIK you can't use a variable here and need to hardcode it. Then you could use filtering to bring it down, but that feels so complicated.

Copy link
Member

Choose a reason for hiding this comment

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

We have a couple of parallel <weird_Map_that_defines_the_branches> in our repo, and I hate it… 👍 for not doing that here, TBH

Copy link
Member Author

Choose a reason for hiding this comment

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

We can also do what katello did and simply remove Ruby from the testing matrix and only test on a single version. Then we can declare it a simple env var and use a variable again.

Copy link
Member

Choose a reason for hiding this comment

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

I think for source creation that's an OK strategy. While it's more correct to test the matrix of Ruby versions, as you noted, the matrix method in Jenkins pipelines is annoying due to hard-coding.

@ekohl
Copy link
Member Author

ekohl commented Jan 6, 2025

@ehelms @evgeni my goal is to also replace the old test_X_Y_stable jobs with this pipeline so I made it a bit more generic. On the other hand, I still struggle with the testing matrix that should be unique for every version.

When I look at theforeman.org/pipelines/release/source/katello.groovy I see we set a single variable and pick a single version. Should we do that too for Foreman to keep it simple?

def databaseUrlForTask(task) {
return task == 'assets:precompile' ? 'production' : 'test'
}

def databaseFile(id) {
Copy link
Member

Choose a reason for hiding this comment

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

is this still used somewhere then?

Copy link
Member Author

Choose a reason for hiding this comment

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

databaseFile("${env.JOB_NAME}-${env.BUILD_ID}")

Do you want me to also replace that?

Copy link
Member

Choose a reason for hiding this comment

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

theforeman.org/pipelines/release/source/katello.groovy does use this, but I guess it'd get the same treatment once this PR is done and we see it working fine

Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated, but I had a closer look at the other functions and noticed addSettings was also unused: #524

@ekohl ekohl force-pushed the rewrite-foreman-to-matrix branch from d147dd6 to 9de0441 Compare January 7, 2025 11:42
environment {
BUNDLE_WITHOUT = 'development'
RAILS_ENV = railsEnvForTask(TASK)
DATABASE_URL = databaseUrlForTask(TASK, env)
Copy link
Member Author

Choose a reason for hiding this comment

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

I suspect you're not allowed to pass in env here:

java.lang.IllegalArgumentException: One or more variables have some issues with their values: DATABASE_URL

Thoughts on just using some UUID for the DB name?

@ekohl ekohl force-pushed the rewrite-foreman-to-matrix branch from 6dfbd0d to 750d7f1 Compare January 7, 2025 15:57
@ekohl
Copy link
Member Author

ekohl commented Jan 7, 2025

@evgeni
Copy link
Member

evgeni commented Jan 8, 2025

Mhh, https://ci.theforeman.org/job/foreman-develop-source-release/ is failing, and the number of tests is different for the passed jobs? 🤔

Comment on lines +5 to +6
database = UUID.randomUUID().toString()
return "postgresql://foreman:foreman@localhost/foreman-${database}"
Copy link
Member

Choose a reason for hiding this comment

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

somehow all tests end up using the same DB. and that breaks things

Comment on lines 14 to 15
RAILS_ENV = railsEnvForTask(RAKE_TASK)
DATABASE_URL = databaseUrlForTask(RAKE_TASK)
Copy link
Member

Choose a reason for hiding this comment

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

I think this gets evaluated too early?

Copy link
Member Author

@ekohl ekohl Jan 8, 2025

Choose a reason for hiding this comment

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

https://www.jenkins.io/doc/book/pipeline/syntax/#matrix-cell-directives says you can also use it in the matrix itself, which is probably way cleaner. It could even be unused outside of it.

This makes it easier to change the Ruby versions and also test on
multiple at the same time.
@ekohl ekohl force-pushed the rewrite-foreman-to-matrix branch from 8211590 to c99d80a Compare January 8, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants