The smallest pipeline that works
A useful pipeline answers two questions: is this change safe to merge, and can we release it without anyone doing something by hand? Everything else is an addition you can make later.
Pull request
Every change goes through a branch and a review, however small it is.
The order matters. Verification runs before merging, so a broken change never reaches main and main stays releasable. Deployment runs only from main, so production always matches a commit you can point to, and when something goes wrong you can read the exact change that caused it.
A working example
Here is that pipeline as a GitHub Actions workflow for a Node.js project. The same structure translates directly to GitLab CI, Bitbucket Pipelines or similar tools. The deploy script is yours to supply, and should be the same one you would run by hand.
name: ci
on:
pull_request:
push:
branches: [main]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build
deploy:
needs: verify
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- run: ./scripts/deploy.sh
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
Two details are worth noticing. The deploy job depends on verify through the needs key, so a failed test stops the release. The environment setting links the job to a GitHub environment, where you can add protection rules such as a required approval and keep production secrets apart from everything else.
The habits that make it safe
- Keep the verify job fast. If it takes twenty minutes, people batch their changes and each release gets riskier.
- Make a rollback a rehearsed step. Keep the previous build available and know how to redeploy it.
- Make database migrations backward compatible, so the old code still runs while the new version rolls out.
- Keep secrets in the CI provider or a secrets manager, and limit each token to what the job needs.
- Use feature flags to separate releasing code from turning a feature on.
When to add more
Add a stage when a real problem justifies it, not because a template includes it.
- Bugs keep escaping that only appear in a browser: add a short Playwright smoke suite.
- Reviewers cannot judge visual changes: add preview environments for pull requests.
- Releases affect many users at once: add canary or blue-green deployments.
- Outdated dependencies pile up: add automated update pull requests and dependency scanning.
The aim is boring releases. When deploying is a routine, low-effort event, teams ship smaller changes more often, and small changes are easier to review, test and undo.