How to Automate Your Vercel Deployments Using GitHub Actions: Deploy Like a Pro!!

Posted by Abhishek Tiwari · 06 Feb, 2024 · 6 min read
How to Automate Your Vercel Deployments Using GitHub Actions: Deploy Like a Pro!!

In the world of web development, deploying applications efficiently and managing workflow automation ensures a seamless digital experience. Vercel and GitHub Actions are the two tools that have revolutionized these aspects.

The automated deployments to Vercel with GitHub Actions significantly simplify the process of deploying web applications and static sites. This is while ensuring that every new commit to the repository or changes pushed to the develop branch, as well as actions like opening, synchronizing, or reopening pull requests, will automatically trigger a deployment.

Today's blog is a guide that will walk you through the CI/CD pipeline setup using GitHub Actions while detailing how to configure a workflow for seamless and error-free deployments to Vercel. Adoption of this approach saves time and also guarantees consistency across deployments, making the entire process efficient and straightforward.

Introduction to Vercel

A cloud-based system specifically engineered to accommodate static websites and serverless functions, while also facilitating an efficient deployment procedure for front-end frameworks, Vercel is distinguished by its scalability, performance optimization, and simplicity.

Key Features:

Instant Global Deployments:

Content Delivery Network (CDN) by Vercel guarantees the site is accessible with minimal delay globally.

Serverless Functions:

Support for serverless functions allows running the backend code without managing a server, scaling automatically with demand.

Automatic HTTPS:

All deployed sites are automatically secured with HTTPS, enhancing security and trust.

Preview Deployments:

Each Git push generates a live preview deployment; allowing a review of changes in a live environment before it is merged into production.

Optimized for Front-End Frameworks:

Tailored for modern web frameworks, Vercel offers features like incremental static regeneration (ISR) with Next.js.

Introduction to GitHub Actions

GitHub Actions is a CI/CD (Continuous Integration and Continuous Deployment) service integrated into GitHub. it enables developers to automate the build, test, and deployment workflows directly within their GitHub repositories.

Key Features of GitHub Actions:

Workflow Automation: GitHub Actions allows automation of software workflows with workflows defined in YAML format, executing a series of commands after a specified event has occurred, such as a push to a repository.

Diverse Marketplace:

Access to a marketplace of actions developed by the GitHub community, which can be used to automate nearly every aspect of the workflow.

Custom Workflows:

Ability to create custom workflows that match development, testing, and deployment needs.

Language and Framework Agnostic:

GitHub Actions supports any language or framework, from Node.js to Rust, Python, PHP, Java, and more.

Integration with GitHub:

Seamless integration with GitHub repositories enables the triggering of workflows based on GitHub events like push, pull requests, and releases.

Automating Deployments to Vercel with GitHub Actions

Deploying applications to Vercel can be a breeze with the help of GitHub Actions. Let’s walk through the process of setting up a GitHub Actions workflow for deploying a project to Vercel automatically whenever changes are pushed to the develop branch or a pull request is opened, synchronized, or reopened.


Before we dive into the setup, ensure you have the following:

  • A GitHub repository containing your web application code.
  • A Vercel account and a Vercel project were created.

Also, Read: DevOps for Small Businesses: 3 Ways to Save Time and Money​

GitHub Actions Workflow
deploy-to-vercel-action uses GitHub Actions to deploy your project/site to Vercel. It offers more customization than Vercel's GitHub integration in terms of when to deploy your site. Let's break down the GitHub Actions workflow defined in the provided code.

name: Deploy CI
    branches: [develop]
    types: [opened, synchronize, reopened]
    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, '[skip ci]')"
      - name: Checkout
        uses: actions/checkout@v2
      - name: Use Node.js 18.x
        uses: actions/setup-node@v1
          node-version: 18.x
      - name: Deploy to Vercel Action
        uses: BetaHuhn/deploy-to-vercel-action@v1
          GITHUB_TOKEN: ${{ secrets.GH_PAT }}
          VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
          VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
          VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
PRODUCTION: false # Don't deploy to production environment
          BUILD_ENV: |
            ENVIORNEMENT2=${{ secrets.ENVIORNEMENT2 }}

Workflow Explanation

  • name: The name of the workflow, in this case, "Deploy CI."
  • on: Specifies the events that trigger the workflow. In this example, it triggers on pushes to the "develop" branch and certain pull request actions.
  • jobs: Defines a job named "deploy" that runs on the latest Ubuntu environment.
  • if: Checks if the commit message contains "[skip ci]". If present, the workflow will be skipped.
  • steps: Describes the sequence of steps to be executed in the job.
  • Checkout: Check out your repository's code.
  • Use Node.js 18.x: Sets up the Node.js environment with version 18.x.
  • Deploy to Vercel Action: Uses the "deploy-to-vercel-action" to deploy the application to Vercel. Configuration includes GitHub and Vercel tokens, organization, and project IDs
  • The line PRODUCTION: true/false in the GitHub Actions workflow file is used to control whether the deployment should target the production environment or the preview environment.
  • The BUILD_ENV section in the GitHub Actions workflow file is used to define environment variables that will be available during the build and deployment process

Setting up Secrets

To use this workflow, you need to add secrets to your

GitHub repository. These include:

  • GH_PAT: create a Fine-grained personal access token with permissions
  • Repository permission:
  • Read access to code and metadata
  • Read and write access to deployments, issues, and pull requests
  • VERCEL_TOKEN: Vercel API token.
    VERCEL_ORG_ID: Vercel organization ID.
  • VERCEL_PROJECT_ID: Vercel project ID.

All Action Inputs - GitHub Marketplace Action Inputs

Why Automating Deployments Is Beneficial?

Adoption of automated deployments in software development has benefits that enhance the efficiency and quality of the software delivery process. Here are a few key advantages:

Better Speed and Efficiency:

Automation cuts down on the amount of time needed to go from code completion to deployment. It can also deploy several environments/servers together. This enhanced speed is important when implementing CI/CD pipelines.

Consistency and Reliability:

Automation eliminates the errors manual operations are prone to by ensuring that every step is carried out precisely the same way each time. This means that it can be duplicated with the same degree of consistency in development, staging, and production environments.

Improved Quality and Testing

Automation makes it possible to smoothly incorporate testing into the deployment procedure. Regular testing of codes provides quick feedback and enables developers to iterate and improve their codes, which means that errors are found and corrected quickly.

Team Collaboration and Productivity

Automation helps developers focus on writing code rather than worrying about deployment. Its ability to manage and monitor provides transparency and better collaboration.

Scalability and Flexibility

Automated deployments can be readily scaled to meet the project requirements with very little additional input. This means it is easier to implement different deployment strategies, such as canary releases, blue-green deployments, etc.

Risk Management

Automated deployment also rolls back a deployment rapidly to its previous state and lowers the possibility of extended downtime. Its security protocols can strengthen the application's overall security.

Continuous Innovation and Improvement

Faster and more frequent updates and deployments of apps, which helps in quicker development. It also enables teams to concentrate on creating newer and better features instead of concentrating on repetitive tasks.

Wrapping Up

Automating deployments with GitHub Actions and Vercel allows for streamlining the development process, ensuring that applications are deployed consistently and efficiently. With this workflow, an application will be automatically deployed to Vercel whenever changes are pushed to the "develop" branch or when relevant pull requests are opened, synchronized, or reopened.

Frequently Asked Questions

Subscribe to The Friday Brunch
Our twice a month newsletter featuring insights and tips on how to build better experiences for your customers

Have a product idea?

Talk to our experts to see how you can turn it
into an engaging, sustainable digital product.