What should a CI pipeline do on a pull request versus after merging to main?

IntermediateConceptCI/CD practices
Answer

In one line: On a pull request, run fast checks that tell the author "is this change safe to merge?"; after merging to main, build the official artifact and deliver it to environments.

On a pull request (feedback for the developer):

  1. Build / compile.
  2. Lint and formatting.
  3. Unit tests (and coverage on new code).
  4. Static analysis (SonarQube, Semgrep).
  5. Secret scanning and dependency scanning.
  6. IaC checks: terraform fmt, validate, plan posted as a PR comment, Checkov.
  7. Optionally: build the Docker image (without pushing), and spin up a temporary preview environment.
  8. Results posted back to the PR; branch protection blocks the merge if anything fails.

Goal: fast (ideally under 10 minutes) and no side effects on shared environments.

After merge to main (delivery):

  1. Build the official versioned artifact (image tagged with the commit SHA or version).
  2. Scan and sign the image, generate an SBOM.
  3. Push it to the registry.
  4. Deploy automatically to dev/staging.
  5. Run integration, end-to-end and smoke tests there.
  6. Promote to production (automatically, or after approval).
  7. Notify the team and update tickets.

Why separate them:

  • PR pipelines must be safe to run on untrusted code (for example forks) — they shouldn't get production secrets.
  • Only reviewed, merged code becomes a release artifact.
  • Shared environments don't get spammed by every PR.

Example (GitHub Actions): on: pull_request runs ci.yml (tests, scans, Terraform plan). on: push: branches: [main] runs release.yml (build, push, deploy to staging, then production with an environment approval).

Tip for interviews: mention that PR pipelines from forks should never have access to secrets — a classic security point.

All DevOps Fundamentals questions

More on CI/CD practices