Draft: Run gem pipelines when their in-repo dependencies change
What does this MR do?
A gem pipeline runs only when the gem's own directory or the shared gem config changes. A change to gems/gitlab-utils does not test gitlab-http, gitlab-mfe, gitlab-bitbucket-server or gitlab-database-load_balancing, although they have it in their bundle. A change to gems/gitlab-rspec does not test the 6 gems that use it in their test bundle.
I keep .gitlab/ci/templates/gem.gitlab-ci.yml and the static gem lists. I add one input, dependency_paths (array, default []). It holds globs of the in-repo gems that appear in the gem's own Gemfile.lock. The template adds one MR rule with changes: $[[ inputs.dependency_paths ]]. All other rules stay the same: the enabled switch, the maintenance schedule, the gem's own paths and the shared config. changes: [] never matches, so gems without in-repo dependencies behave as before.
I use the gem's own lockfile, not a transitive walk of the graph. The lockfile already lists every in-repo gem in that bundle, including indirect ones. This is exactly the code the gem's specs load. A transitive walk would also include development-only dependencies of dependencies.
This replaces !259288 (closed). That MR replaced the gem trigger jobs with a generated child pipeline. It changed too much: it lost the per-gem enabled switch, moved the rules into a Ruby script and added a nesting level. This MR depends on !259287 (merged), which adds Tooling::GemsDependencyGraph and rake gems:dependency_graph. It targets that branch.
Behaviour and trade-offs:
- The edges are copied into YAML. 8 gems have in-repo dependencies today.
dependency_pathsmust be updated when a gem's lockfile gains or loses an in-repo gem. spec/dot_gitlab_ci/gem_dependency_paths_spec.rbcompares each gem'sdependency_pathswith the graph. When they differ, it prints the expected list.tests.ymlmaps the gem lockfiles, the two gem CI list files and the graph class to this spec. It runs in the MR that changes an edge, so a missing edge is a failing test, not a silent gap.- This approach covers gems only. Selecting by domains or bounded contexts later needs a different mechanism.
- The monolith is unchanged. Changes in
gems/**already run the monolith rspec jobs through.backend-patterns. A change in the monolith still runs no gem pipeline.
Validation:
- CI lint of the branch config is valid with 40 gem jobs.
- The merged YAML shows the extra rule per gem. For example,
gitlab-bitbucket-servergetsgems/gitlab-http/**/*andgems/gitlab-utils/**/*. - The spec fails when I remove an entry.
- Not verified: a real MR pipeline has not run yet. I pushed with
ci.skip.
Related issues
- #630714 (closed)
- Depends on !259287 (merged)
- Replaces !259288 (closed)
Checklist
Pre-merge
- Different pipeline types: no change to event conditions. The MR only adds paths to the existing MR rule set.
- Non-canonical projects (gitlab-foss, security, dev, personal forks): no change.
- Pipeline performance: no new jobs. Gem pipelines now also run when an in-repo dependency changes, which is the intent.
- 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 (no new jobs)
Post-merge
- Consider communicating these changes to the broader team following the communication guideline for pipeline changes