ci: enforce a merge request size limit

What changed

A merge request that adds more than 1000 hand-written Go lines now fails.

  • scripts/ci/check-mr-size.sh counts added lines in *.go files against <target>...HEAD. It skips generated files and vendor/, and it reads a renamed file by its new path. It has no override.
  • The mr-size pre-push hook runs the script against origin/main. A stacked part sets MR_SIZE_BASE to its parent ref.
  • The lint:mr-size CI job runs the same script on every merge request, because a hook is skippable. It picks the base per pipeline type, as lint:comment-caps does. A detached pipeline uses $CI_MERGE_REQUEST_DIFF_BASE_SHA. A merged-result or merge-train pipeline uses HEAD^1 and fails when HEAD is not a merge commit. The target tip would count the train cars ahead of this MR as its lines.
  • The test:mr-size-gate CI job and scripts/ci/check-mr-size_test.sh check that the gate fails over the limit, passes at it, and rejects a dash-leading target ref. Both run on alpine and busybox.
  • .pre-commit-config.yaml sets default_stages: [pre-commit] so existing hooks do not start running on push. A clone must run pre-commit install once to get the pre-push hook.

How I checked it

  • The hook passes on this branch, which adds no Go lines.
  • A real git push of a 1400-line two-part stack fails with the default base. It passes with MR_SIZE_BASE set to the parent part.
  • Both CI job scripts pass in alpine:3.23.
  • A fixture train in alpine:3.23, with 800 Go lines from the car ahead and 300 from this MR, counts 300 against HEAD^1. The target tip as base counts 1100.

Size

Reviewable LOC is 643: tests 487, script 85, CI 55, hook 16. A split would not help, because the test file cannot land before the script it tests, and the CI and hook wiring has no purpose without either.

Follow-ups

docs/dev/development-model.md now contradicts the gate. Line 7 says "No stacked MR chains", and line 17 says a justification clears 500 LOC. This MR leaves both lines alone, because #1612 asks for the gate only. The scenario is posted on https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1625 for line 17 and https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1617 for line 7.

Related to https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1612

Edited by Radamanthus Batnag

Merge request reports

Loading
Loading