Run pre-merge pipeline and merge a MR when it succeeds
Description
There are many ways in which an organization can reduce the cost of running their pipelines. Typical solutions are:
- Select tests to run, and only run these selected on every push / commit.
- Run all tests only when a merge request gets approved / changes its draft status to ready.
- Run all tests on "merged code pipeline" when there is a maintainer's approval on the MR.
- Extract tests from merge requests to nightly pipelines, and run them on schedule.
All of these solution offer some benefits, but each of them is associated with their own challenges:
- Running selected tests only can result in a test gap when code hits master branch.
- Running tests when MR is approved can be insufficiently efficient when someones approves a MR early with an ongoing implementation.
- When we extract tests to nightly pipeline, we can - and most likely will - broken master each night.
Additional way to run tests may be: run a full test suite only when the MR is in the process of actually getting merged.
Proposal
Implement a new way of running tests in gitlab-org/gitlab
project. Fortunately we do not need to add more features, it seems that the feature set that we have is sufficient.
We could reuse merge trains feature to achieve this, by running all possible tests whenever we see that CI_MERGE_REQUEST_EVENT_TYPE
is set to merge_train
.