Test only the affected gems in merge request pipelines
What does this MR do?
Each in-repo gem pipeline only runs when that gem's own directory changes. A change to gems/gitlab-utils does not test gitlab-http, gitlab-mfe, gitlab-bitbucket-server or gitlab-database-load_balancing, which depend on it. A gem that is changed should be tested with every gem that depends on it, directly or transitively.
I replace the 40 static gems <name> trigger jobs with the pattern the predictive rspec pipeline already uses. A job generates a child pipeline from the changed files, and a trigger job runs it. The generated pipeline triggers the pipeline of each changed gem and of every gem that depends on it. Monolith-only changes trigger none. The dependency graph comes from the step 1 MR linked below.
I generate the pipeline instead of adding the dependency paths to each job's rules:changes. Static rules would copy the graph into YAML that we must keep in sync by hand. They also cannot grow into the domains and bounded contexts graph later. Changed files come from the existing detect-tests job, which already runs for every path that triggers gem pipelines.
Examples from this repo:
- A change in
gems/gitlab-utilstestsgitlab-utils,gitlab-http,gitlab-mfe,gitlab-bitbucket-serverandgitlab-database-load_balancing. - A change in
gems/gitlab-mfetests onlygitlab-mfe. - A change in
app/models/user.rbtests no gem.
Behaviour changes:
- New gems no longer need to be added to a list. Every gem with a
.gitlab-ci.ymlis picked up. - The pipeline UI has one more level. Gem pipelines now appear under the
gems:triggerchild pipeline. - Changes to shared gem CI config,
Gemfile.lockor the RuboCop config test all gems, as today. This usesGLCI_GEMS_TEST_ALL. If the changed files list is missing or empty, all gems are tested.
Known limits:
- Nesting is now root, generated child, gem pipeline. This is the maximum depth GitLab allows (2 levels of child pipelines). A gem pipeline can no longer trigger its own child pipeline. None does today.
- The changed files come from the MR changes API, which truncates very large MRs (about 1000+ files). In that case a gem changed beyond the cut-off could be skipped. I accept this for now.
Validated: CI lint of the branch config is valid. The generated child pipelines (with gems, and the no-op case) are valid through the CI lint API. A real MR pipeline has not run yet, because I pushed with ci.skip.
Related issues
- #630714 (closed)
- Depends on !259287 (merged)
Checklist
Pre-merge
- Consider the effect on different pipeline types (merge trains, merged results, detached MR pipelines, maintenance schedule, default branch). The event conditions are the same as before: merged results and detached MR pipelines, and the maintenance schedule only. Merge train, branch and default branch pipelines had no gem pipelines before and have none now.
- Consider the effect on non-canonical projects (gitlab-foss, security, dev, personal forks). The rules are unchanged. I added no project-specific conditions.
- Consider the effect on pipeline performance. This adds one short job (
gems:pipeline-generate, slim Ruby image, plain Ruby, no bundle install) inprepare, and one trigger job. Fewer gem pipelines run when only one gem changes. More run when a widely used gem changes, which is correct. - If new jobs are added, set change-related rules and frequency. Rules:
{gems,vendor/gems}/**/*, plus shared gem CI config,Gemfile.lockand RuboCop config (these test all gems, as before). Frequency: MRs and the maintenance schedule. - Add a duration chart to https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations if there are new jobs added to merge request pipelines
Post-merge
- Consider communicating these changes to the broader team following the communication guideline for pipeline changes