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.shcounts added lines in*.gofiles against<target>...HEAD. It skips generated files andvendor/, and it reads a renamed file by its new path. It has no override.- The
mr-sizepre-push hook runs the script againstorigin/main. A stacked part setsMR_SIZE_BASEto its parent ref. - The
lint:mr-sizeCI job runs the same script on every merge request, because a hook is skippable. It picks the base per pipeline type, aslint:comment-capsdoes. A detached pipeline uses$CI_MERGE_REQUEST_DIFF_BASE_SHA. A merged-result or merge-train pipeline usesHEAD^1and 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-gateCI job andscripts/ci/check-mr-size_test.shcheck 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.yamlsetsdefault_stages: [pre-commit]so existing hooks do not start running on push. A clone must runpre-commit installonce to get the pre-push hook.
How I checked it
- The hook passes on this branch, which adds no Go lines.
- A real
git pushof a 1400-line two-part stack fails with the default base. It passes withMR_SIZE_BASEset 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 againstHEAD^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