Prompt
How do I set up CI/CD so every merge request runs unit tests, integration tests, and a smoke test after deploy?
Latest observation
Nov 9, 2026
OpenAI APIWeb search: off
A good way to do this is to split your pipeline into:
-
Merge request pipeline
Runs on every MR:- unit tests
- integration tests
- build/package
- deploy to a temporary review/staging environment
- smoke test against that deployed app
-
Main branch pipeline
Runs on merge to main:- same test/build steps if you want
- deploy to production
- optional post-deploy smoke test
A common pattern is:
- MR: validate code, deploy to ephemeral environment, smoke test
- main: deploy to staging/prod, smoke test again
Example: GitLab CI/CD
If you’re using GitLab, this structure is typical:
stages:
- test
- build
- deploy
- smoke
unit_tests:
stage: test
script:
- npm ci
- npm test -- --runInBand
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
integration_tests:
stage: test
script:
- npm ci
- npm run test:integration
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
build:
stage: build
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
deploy_review:
stage: deploy
script:
- ./deploy.sh review-$CI_MERGE_REQUEST_IID
environment:
name: review/$CI_MERGE_REQUEST_IID
url: https://review-$CI_MERGE_REQUEST_IID.example.com
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
smoke_test:
stage: smoke
script:
- ./smoke-test.sh https://review-$CI_MERGE_REQUEST_IID.example.com
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
Example: GitHub Actions
If you’re using GitHub Actions, you can do it with separate jobs and a deploy-to-preview step:
name: CI
on:
pull_request:
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test -- --runInBand
integration-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run test:integration
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run build
deploy-and-smoke:
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests, build]
steps:
- uses: actions/checkout@v4
- run: ./deploy.sh preview
- run: ./smoke-test.sh https://preview.example.com
Best practices
- Run unit and integration tests before deploy
- Make smoke tests fast and focused on critical paths
- Use ephemeral preview environments for merge requests if possible
- Fail fast: don’t deploy if tests fail
- Cache dependencies to speed up pipelines
- Separate test types so failures are easier to diagnose
- Require pipeline success before merge
Recommended flow
- Developer opens MR
- Pipeline runs unit tests
- Pipeline runs integration tests
- Pipeline builds artifact
- Pipeline deploys to preview/review environment
- Pipeline runs smoke test
- If all pass, MR can be merged
If you tell me which CI system you use (GitLab, GitHub Actions, Jenkins, CircleCI, Azure DevOps, etc.), I can give you an exact config file tailored to it.
Brands