How to Deploy to Vercel via CLI With GitHub Actions
Run the Vercel CLI with a token: pull settings, build with vercel build, then ship with vercel deploy --prebuilt --prod.
When you want CI to own the deploy (rather than the Vercel Git integration), use the CLI: vercel pull to fetch project config, vercel build to produce .vercel/output, then vercel deploy --prebuilt.
Steps
- Create a Vercel token and store it plus
VERCEL_ORG_IDandVERCEL_PROJECT_IDas secrets. - Run
vercel pull --yes --environment=production. - Build with
vercel build --prod, then deploy withvercel deploy --prebuilt --prod.
Workflow
.github/workflows/deploy.yml
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- uses: actions/checkout@v4
- run: npm i -g 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 }}Common pitfalls
- Skipping
vercel pullmeans the build has no project settings andvercel builduses wrong framework defaults. - Omitting
--prebuiltre-uploads source and rebuilds on Vercel, double-spending build time. - If the Vercel Git integration is still enabled, both it and this workflow deploy; disable one to avoid duplicate deployments.
Related guides
How to Deploy to Netlify via CLI With GitHub ActionsDeploy a build to Netlify from GitHub Actions with the netlify CLI, using an auth token and site id to push t…
How to Deploy to Fly.io With GitHub ActionsDeploy an app to Fly.io from GitHub Actions with the flyctl CLI and a Fly API token, running fly deploy --rem…