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.
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.
Content Delivery Network (CDN) by Vercel guarantees the site is accessible with minimal delay globally.
Support for serverless functions allows running the backend code without managing a server, scaling automatically with demand.
All deployed sites are automatically secured with HTTPS, enhancing security and trust.
Each Git push generates a live preview deployment; allowing a review of changes in a live environment before it is merged into production.
Tailored for modern web frameworks, Vercel offers features like incremental static regeneration (ISR) with Next.js.
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.
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.
Access to a marketplace of actions developed by the GitHub community, which can be used to automate nearly every aspect of the workflow.
Ability to create custom workflows that match development, testing, and deployment needs.
GitHub Actions supports any language or framework, from Node.js to Rust, Python, PHP, Java, and more.
Seamless integration with GitHub repositories enables the triggering of workflows based on GitHub events like push, pull requests, and releases.
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:
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
on:
push:
branches: [develop]
pull_request:
types: [opened, synchronize, reopened]
jobs:
deploy:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 18.x
uses: actions/setup-node@v1
with:
node-version: 18.x
- name: Deploy to Vercel Action
uses: BetaHuhn/deploy-to-vercel-action@v1
with:
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: |
ENV1=value
ENVIORNEMENT2=${{ secrets.ENVIORNEMENT2 }}
To use this workflow, you need to add secrets to your
All Action Inputs - GitHub Marketplace Action Inputs
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:
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.
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.
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.
Automation helps developers focus on writing code rather than worrying about deployment. Its ability to manage and monitor provides transparency and better collaboration.
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.
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.
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.
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.
Have a product idea?
Talk to our experts to see how you can turn it
into an engaging, sustainable digital product.