Migrating from Vercel's native GitHub integration to GitHub Actions for deployments involves several steps to ensure a smooth transition without disrupting your deployment history. Here's how you can proceed:
-
Disable Vercel's GitHub Integration:
-
In your Vercel project, navigate to the Settings tab.
-
Under the Git section, set the
github.enabled
property tofalse
in yourvercel.json
file:{ "github": { "enabled": false } }
This configuration prevents Vercel from automatically deploying your project upon GitHub events.
-
-
Set Up Vercel CLI and Link Your Project:
-
Install the Vercel CLI globally if you haven't already:
npm install -g vercel
-
In your project directory, link your project to Vercel:
vercel link
Follow the prompts to select the appropriate scope and project. This command creates a
.vercel
directory containingproject.json
, which includes yourorgId
andprojectId
.
-
-
Configure GitHub Secrets:
- In your GitHub repository, navigate to Settings > Secrets and variables > Actions.
- Add the following secrets:
VERCEL_TOKEN
: Your Vercel token, obtainable from your Vercel account settings.VERCEL_ORG_ID
: TheorgId
from your.vercel/project.json
.VERCEL_PROJECT_ID
: TheprojectId
from your.vercel/project.json
.
-
Create a GitHub Actions Workflow:
-
That does the following:
- The workflow triggers on pushes and pull requests to the
main
branch. - It checks out the code, sets up Node.js, installs dependencies, builds the project, and deploys it to Vercel using the Vercel CLI.
- The workflow triggers on pushes and pull requests to the
-
In your repository, create a
.github/workflows/deploy.yml
file with the following content:name: Deploy to Vercel on: push: branches: - main pull_request: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '14' - name: Install dependencies run: npm install - name: Build project run: npm run build - name: Deploy to Vercel env: VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} run: npx vercel --prod --token $VERCEL_TOKEN --org-id $VERCEL_ORG_ID --project-id $VERCEL_PROJECT_ID
-
-
Test the New Deployment Pipeline:
- Push a commit or open a pull request to the
main
branch to trigger the GitHub Actions workflow. - Monitor the Actions tab in your GitHub repository to ensure the workflow runs successfully and deploys your project to Vercel.
- Push a commit or open a pull request to the
-
Monitor Deployment History:
- Your previous deployment history remains intact in the Vercel dashboard.
- New deployments triggered via GitHub Actions will appear alongside your existing deployment history, maintaining continuity.