What is CI/CD?

What continuous integration and deployment mean for your app.

When working on a team you will often hear people talk about "CI/CD" or ask if "the pipeline is green". It sounds bigger than it is. CI/CD is just automating the steps between pushing code and getting it in front of users, so nobody has to remember to run the tests or deploy by hand.

CI (Continuous Integration) automatically builds and tests every change. CD (Continuous Delivery) keeps every passing change ready to release, and Continuous Deployment goes one step further and releases it automatically.

What is Continuous Integration?

Continuous Integration means everyone merges their work into the main branch often, and every push or pull request kicks off an automated check. Usually that means installing dependencies, running the tests, running the linter and making sure the app builds.

If something fails you find out in minutes, on the pull request, instead of days later when someone else pulls your changes.

Continuous Delivery vs Continuous Deployment

Both use "CD", which is where the confusion comes from.

  • Continuous Delivery: every change that passes CI is ready to deploy, but a person still clicks the button to release it.
  • Continuous Deployment: every change that passes CI on the main branch is deployed to production automatically.

Most front-end teams I've worked with use Continuous Delivery. Every change is ready to go, but someone still decides when it goes out, like after QA signs off or once a feature is ready to announce.

Why does CI/CD matter?

  • Bugs get caught before they're merged, not after.
  • Code reviews can focus on the code, because the tests already ran.
  • Deploys become boring and small, which is exactly what you want.

Setting up CI with GitHub Actions

GitHub Actions is built into GitHub and free for public repos, so it's an easy place to start. Workflows are YAML files in the .github/workflows folder. Here is a workflow for a Node app that runs on every push to main and every pull request:

# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
cache: npm
- run: npm ci
- run: npm test
- run: npm run build

Here's what each part does:

  • on sets when the workflow runs. Here it's pushes to main and any pull request.
  • runs-on picks the machine the job runs on.
  • actions/checkout pulls your repo's code onto that machine.
  • actions/setup-node installs Node, and cache: npm caches your npm downloads between runs so installs are faster.
  • npm ci installs the exact versions from package-lock.json. It's faster than npm install and fails if the lock file is out of date, which is what you want in CI.
  • npm test and npm run build fail the job if a test fails or the build breaks.

Push this file and you'll see a check on your next pull request. In your repo settings you can add a branch protection rule for main that requires this check to pass before anything can be merged.

Setting up CD with Vercel

For the deployment side, Vercel makes this especially simple. Connect your GitHub repo in the Vercel dashboard and it handles the rest:

  • Every push to a branch or pull request gets its own preview deployment with a unique URL. Vercel comments the link on the pull request so reviewers can click through the actual change.
  • Every merge to main deploys to production.

That's Continuous Deployment without writing any config. Combined with the GitHub Actions workflow, every pull request gets tested and previewed, and merging it ships it.

CI/CD pipeline. Continuous Integration: a pull request or a push to main starts the GitHub Actions workflow, which runs actions/checkout, actions/setup-node, npm ci, npm test and npm run build. Continuous Deployment: a passing pull request gets a preview deployment with a unique URL, and every merge to main is deployed to production. With a manual release step it would be Continuous Delivery.CONTINUOUS INTEGRATIONCONTINUOUS DEPLOYMENTWith a manual release step it's Continuous Deliverypull requeston: pull_requestpush to mainbranches: [main]GitHub Actionsactions/checkoutactions/setup-nodenpm cinpm testnpm run buildpreview deployunique URL on the PRproduction deployevery merge to main

You don't need a big setup to get the benefits. Start with a workflow that runs your tests and builds the app, and add more steps as your project grows.

Have some feedback on this post? .