cd ..

Deploy to Vercel By GitHub Actions

Feb 23, 20221 min #技术笔记

Prerequisites

Need an account of Vercel and Github, and three secrity keys:

VERCEL_TOKEN can generate from Vercel tokens setting page: https://vercel.com/account/tokens.

Run this command on your website project directory to generate the other values:

npx vercel link

It will create a .vercel directory with a config file named project.json, and those values will be stored in this file.

Config GitHub Actions

Add job steps like this:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:

    # Other steps, just like build, test or etc.

    - name: Deploy to vercel
      id: deploy-vercel-staging
      uses: amondnet/vercel-action@v20
      with:
        vercel-token: ${{ secrets.VERCEL_TOKEN }}
        vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
        vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
        vercel-args: '--prod' # if not set will deploy to Staging
        working-directory: ./dist # website directory
        scope: ${{ secrets.VERCEL_ORG_ID }}

A full example to see here.