36
loading...
This website collects cookies to deliver better user experience
Create new Nextjs app.
Create a new Next.js app using npx and change into the new directory:
npx create-next-app nextjs-vercel-ci-cd
cd nextjs-vercel-ci-cd
git remote add origin [email protected]:git-<username>/<project-name>.git
touch .github/workflows/deploy.yml
npm i -g vercel
Before you proceed, you need to know your project ID and org ID from Vercel. The simplest way to get this is to link your project to Vercel. You can do this by using npx vercel link
..vercel
folder in your project with a project.json
file. In that file, you will find the projectId and orgId, which you can use later in your GitHub Actions workflow.vercel.json
file in the root of your project (if it does not yet exist), and add the following contents to it:{
"version": 2,
"github": {
"enabled": false
}
}
name: deploy nexturl to vercel
on: [push, pull_request]
jobs:
vercel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
#add env file to .env.local
- name: Set Env Vars on Vercel Project
uses: dkershner6/vercel-set-env-action@v1
with:
token: ${{ secrets.VERCEL_TOKEN }}
teamId: ${{ secrets.VERCEL_TEAM_ID }} # optional, without will use personal
projectName: nexturl # project name in Vercel
envVariableKeys: MONGODB_URL,MONGODB_DB
env:
MONGODB_URL: ${{ secrets.MONGODB_URL }}
TARGET_MONGODB_URL: preview,development,production
# comma delimited, one of [production, preview, development]
TYPE_MONGODB_URL: encrypted # one of [plain, encrypted]
MONGODB_DB: ${{ secrets.MONGODB_DB }}
TARGET_MONGODB_DB: preview,development,production
TYPE_MONGODB_DB: encrypted
# deploy app to vercel
- name: deploy site to vercel
uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
github-token: ${{ secrets.GITHUB_TOKEN }} #Optional
vercel-args: '--prod' #Optional
vercel-org-id: ${{ secrets.ORG_ID}} #Required
vercel-project-id: ${{ secrets.PROJECT_ID}} #Required