A GitHub Actions CI/CD Pipeline for a Vite and Node.js App
By Muhammad Osama Khan, Software Engineer. DevOps, Sep 8, 2026, 3 min read.
One workflow that checks every push and pull request, and a second job that deploys to production only when those checks are green.
Continuous integration (CI) means every change is automatically installed, linted, tested and built on a clean machine. Continuous delivery (CD) means a change that passes is deployed without manual steps. GitHub Actions does both from a YAML file in your repository.
The CI job
This workflow runs on pull requests and on pushes to your main branches. It uses npm ci (a clean, reproducible install from the lockfile), caches the npm download, and cancels an older run when a newer commit arrives.
.github/workflows/ci.yml
name: CI
on:
pull_request:
branches: [staging, Production]
push:
branches: [dev, staging, Production]
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
verify:
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend # remove if the app is at the repo root
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: frontend/package-lock.json
- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: dist
path: frontend/distworking-directorymatters when the app lives in a subfolder. A workflow that runsnpm ciat the repository root of a monorepo fails because there is nopackage.jsonthere.- Pin the Node version to match what you develop with, so "works on my machine" differences disappear.
permissions: contents: readgives the job the least access it needs.
The CD job: deploy after the checks pass
Add a second job that waits for verify and runs only for pushes to the production branch. This version builds and deploys with the Vercel CLI.
.github/workflows/ci.yml (continued)
deploy:
needs: verify
if: github.event_name == 'push' && github.ref == 'refs/heads/Production'
runs-on: ubuntu-latest
environment: production
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm install --global vercel@latest
- run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Smoke test
run: curl --fail --silent --show-error --output /dev/null https://your-domain.example/Setting it up
- Create a Vercel access token, and copy the organisation and project IDs from the project settings.
- In the GitHub repository, add them as secrets:
VERCEL_TOKEN,VERCEL_ORG_ID,VERCEL_PROJECT_ID. Never commit them. - Turn off Vercel's own Git auto-deploys for that project, otherwise every push is deployed twice and the first one skips your checks.
- Create a GitHub Environment named
production. You can require a manual approval there for a safety gate before each release. - In the branch protection rules for
Production, require theverifycheck to pass before merging.
A good branching flow
Work on dev, merge into staging to see the change on a staging URL, then merge into Production. Pull requests run the checks, pushes to staging deploy the preview environment, and only a green Production push reaches the live site.
Frequently asked questions
What is the difference between CI and CD?
Continuous integration runs checks (install, lint, test, build) automatically on every change. Continuous delivery or deployment takes a change that passed those checks and releases it without manual steps.
Why use npm ci instead of npm install in a pipeline?
npm ci installs exactly what the lockfile says, starting from a clean node_modules, and fails if the lockfile and package.json disagree. That makes builds reproducible.
How do I keep secrets safe in GitHub Actions?
Store them as repository or environment secrets, reference them with secrets.NAME, never print them in logs, and give the workflow the least permissions it needs (for example contents: read).
How do I stop Vercel from deploying twice when I deploy from Actions?
Turn off Vercel's own Git auto-deploys for that project. Otherwise each push is deployed by Vercel directly, without waiting for your checks, as well as by the workflow.