Implementing a Two-Step CI with Mergify
Run essential tests on every PR and comprehensive tests before merging, optimizing CI time and resources.
Split your CI into fast preliminary checks on every PR and full tests that run only before merging.
The Two Phases
Section titled The Two PhasesStep 1: Preliminary tests run on every PR push: linters, formatters, unit tests, basic compile checks. Fast feedback, cheap to run.
Step 2: Pre-merge tests run only when a PR enters the merge queue: integration tests, end-to-end tests, performance benchmarks. Thorough but expensive.
How It Works
Section titled How It WorksBatch Processing
Section titled Batch ProcessingEnable batching to run pre-merge tests once for a group of PRs instead of per PR. For 5 PRs with a 30-minute pre-merge suite, that’s 30 minutes instead of 2.5 hours.
Configuration
Section titled ConfigurationCI System
Section titled CI SystemRun pre-merge tests only on merge queue branches. Mergify creates branches
prefixed with mergify/merge-queue/ (customizable via queue_branch_prefix
in queue_rules).
GitHub Actions
Section titled GitHub Actionsname: CI
on: pull_request: branches: - main
jobs: # STEP 1: Preliminary tests (runs on every PR) preliminary-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run linters run: make lint - name: Run unit tests run: make test-unit
# STEP 2: Pre-merge tests (runs only on merge queue branches) pre-merge-tests: if: startsWith(github.head_ref, 'mergify/merge-queue/') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run integration tests run: make test-integration - name: Run E2E tests run: make test-e2e - name: Run performance benchmarks run: make benchmarkOther CI Systems
Section titled Other CI Systems- CircleCI: Branch filter regex
/^mergify\/merge-queue\/.*/ - Jenkins: Conditional execution on
BRANCH_NAME - GitLab CI:
only: /^mergify\/merge-queue\/.*/
Mergify
Section titled Mergifyqueue_rules: - name: default # PRs can enter the queue after preliminary tests pass queue_conditions: - check-success=preliminary-tests
# PRs can merge only after pre-merge tests pass merge_conditions: - check-success=pre-merge-testsqueue_conditions gates entry into the queue; merge_conditions gates the
final merge to main.
Was this page helpful?
Thanks for your feedback!