Add opt-in jobs that test gems from the dependency graph

What does this MR do?

A gem pipeline runs only when the gem's own directory or shared config changes. Every gem must also be listed by hand in .gitlab/ci/gitlab-gems.gitlab-ci.yml or .gitlab/ci/vendored-gems.gitlab-ci.yml. A change to gems/gitlab-utils does not test gitlab-http, gitlab-bitbucket-server or gitlab-database-load_balancing, which depend on it.

I fix this with the dependency graph from !259287 (merged) (rake gems:dependency_graph, built from lockfiles).

The new jobs run side by side with the existing ones and are opt-in. gems:dependency_graph decides which gems to test and writes a child pipeline YAML. gems:test runs that YAML as a dynamic child pipeline. Gems are found automatically: every directory in gems/ and vendor/gems/ with a .gitlab-ci.yml. Each gem keeps its own .gitlab-ci.yml (including gems/gem.gitlab-ci.yml), so a gem can still add its own jobs. The rules move from each gem job to gems:dependency_graph.

Changes from today, with GLCI_GEMS_DEPENDENCY_GRAPH="true":

Change in the MR Today With this MR
A gem's own directory That gem That gem
An in-repo gem that another gem depends on, directly or transitively Only the changed gem The changed gem and every gem that depends on it. For example, gems/gitlab-utils also tests gitlab-http, gitlab-bitbucket-server, gitlab-database-load_balancing and gitlab-mfe
Monolith code only No gem No gem
Monolith Gemfile.lock All gems No gem. Each gem tests with its own lockfile, and the graph covers changes to in-repo gems
.rubocop.yml or .rubocop_todo/** All gems No gem. Gems do not load the monolith RuboCop config or TODOs
rubocop/** (monolith cops) All gems All gems. Gems load these cops
gems/config/rubocop.yml (inherited by every gem in gems/) No gem All gems
Shared gem CI config or scripts/validate-monorepo-gem All gems All gems. The new generator files are added to this list
Maintenance schedule All gems All gems
A new gem Runs only after it is added to a static list Found automatically when it has a .gitlab-ci.yml
Turn off one gem (feature currently not used) enabled: false input in the static list Not available - can add later if needed
Test all gems on demand Not available GLCI_GEMS_TEST_ALL="true"
Pipeline layout Gem pipelines are children of the root pipeline Gem pipelines are children of the gems:test child pipeline, after one extra prepare job. In the next iteration we can bring all jobs up 1 level into a single gems:test child pipeline.

Changed files come from the existing detect-tests job. If they are missing or empty, all gems are tested.

Switches:

  • GLCI_GEMS_DEPENDENCY_GRAPH="true" turns on the new jobs and turns off the existing gem jobs, so a gem never runs twice.
  • GLCI_GEMS_TEST_ALL="true" forces the new jobs to run and test all gems, even without changes. Use it to try the jobs or to rerun everything.
  • With no variable set, nothing changes.

To retire the old path later: delete the template, both static lists and the switch.

Trade-offs:

  • The transitive walk can select more than needed, but never less. A change to gitlab-rspec also runs gems that reach it only through a test-only dependency of a dependency.
  • Nesting is root, gems:test, gem pipeline. This is the maximum depth GitLab allows. A gem pipeline cannot trigger its own child pipeline. None does today.
  • The MR changes API that detect-tests uses truncates very large MRs (about 1000+ files). A gem changed beyond the cut-off could be skipped.

Validated: specs for the generator and the graph pass. CI lint of the branch config and of a generated child pipeline is valid. Not verified: a real pipeline with the switch on. I pushed with ci.skip.

See it working

Rollout

  1. Set GLCI_GEMS_DEPENDENCY_GRAPH="true" in Project settings.
  2. Leave it running for a few days.
  3. Change YAML to remove the use of the variable.
  4. Unset the variable in Project settings.
Edited by Fabio Pitino

Merge request reports

Loading
Loading