Search code examples
githubnext.jsdevopsvercelsemantic-versioning

How to use GitHub Releases with Vercel?


I am working on an ecommerce site with Next.js and want to deploy it to Vercel. I have seen that Vercel uses the Deploy-Preview-Ship model (DPS) and while I am not sure if this is something that goes against that I was wondering if there is a way to link GitHub actions/tags to my Vercel deployments so I can deploy each GitHub release, rather than each merge into the main branch. This way I can keep better semantic versioning and I can batch PRs and changes into releases. Any ideas or am I better off just deploying to production on each merge into main?


Solution

  • As mentioned in the comment above by bigpopakap, you can follow the guide provided by Vercel and use a GitHub workflow similar to the following

    name: Production Tag Deployment
    env:
      VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
      VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
    on:
      push:
        # Pattern matched against refs/tags
        tags:        
          - '*' # Push events to every tag not containing /
    jobs:
      Deploy-Production:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
          - name: Install Vercel CLI
            run: npm install --global vercel@latest
          - name: Pull Vercel Environment Information
            run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
          - name: Build Project Artifacts
            run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
          - name: Deploy Project Artifacts to Vercel
            run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
    

    In addition, if you no longer want the Vercel production branch to deploy to the main branch, go to GitHub Repo > Settings > Environments and delete the Production environment. Alternatively, create a branch named ignore and set it as the production branch and ensure no one pushes to it using GitHub rulesets