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.ymlname: CIon:push:branches: [main]pull_request:jobs:build:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v2- uses: actions/setup-node@v2with:node-version: 14cache: npm- run: npm ci- run: npm test- run: npm run build
Here's what each part does:
onsets when the workflow runs. Here it's pushes tomainand any pull request.runs-onpicks the machine the job runs on.actions/checkoutpulls your repo's code onto that machine.actions/setup-nodeinstalls Node, andcache: npmcaches your npm downloads between runs so installs are faster.npm ciinstalls the exact versions frompackage-lock.json. It's faster thannpm installand fails if the lock file is out of date, which is what you want in CI.npm testandnpm run buildfail 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
maindeploys 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.
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? .