#vercel deployments

1 messages · Page 1 of 1 (latest)

pulsar cobalt
#

how do I disable vercel deployments on pushes? i want to use only cli through github actions

frank pathBOT
#

Hi @pulsar cobalt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To disable Vercel deployments on pushes and use only the CLI through GitHub Actions, you can configure the "Ignore Build Step" option in your Vercel project settings. This will allow you to skip building and deploying for all branches except the ones you specify.

For example, you can tell Vercel to only build your main branch and ignore all other branches by using a command that returns "0" for the branches you want to skip and "1" or greater for the branches you want to build:

{
  "build": {
    "env": {
      "VERCEL_IGNORE_BUILD_STEP": "echo $(if [ \"$VERCEL_GIT_COMMIT_REF\" = \"main\" ]; then echo \"0\"; else echo \"1\"; fi)"
    }
  }
}

Add this configuration to your vercel.json file in your project's root directory. This will ensure that Vercel only builds and deploys the main branch, while all other branches are ignored.

For using GitHub Actions to build and deploy your Vercel application, you can use the vercel build command to build your project inside GitHub Actions without exposing your source code to Vercel. Then, use vercel deploy --prebuilt to skip the build step on Vercel and upload the previously generated .vercel/output folder to Vercel from the GitHub Action. You can learn more about configuring GitHub Actions and Vercel for custom CI/CD workflows here (https://vercel.com/guides/how-can-i-use-github-actions-with-vercel).

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

Vercel Documentation

To deploy on Vercel, you need to create a Project, which groups deployments and custom domains. Learn how to set up and configure projects with this guide.

Vercel Documentation

​Vercel for GitHub automatically deploys your GitHub projects with Vercel, providing Preview Deployment URLs, and automatic Custom Domain updates.

#

@pulsar cobalt kapa.ai is still learning and improving, please let us how it did by reacting below

pulsar cobalt
#

@frank path how do i make it so it builds once and not twicde

frank pathBOT
#

Let me check the knowledge base for you. One moment! :books:

#

To ensure your project builds only once, you can use GitHub Actions to build your project and then deploy the pre-built output to Vercel using the --prebuilt flag.

  1. Set up a GitHub Actions workflow in your repository by creating a .github/workflows directory and adding a YAML file, such as deploy.yml.

  2. Configure the GitHub Actions workflow to build your project and deploy it to Vercel using the vercel CLI. Here's an example workflow configuration:

name: Deploy to Vercel

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: 14

    - name: Install dependencies
      run: npm ci

    - name: Build project
      run: npm run build

    - name: Install Vercel CLI
      run: npm i -g vercel

    - name: Deploy to Vercel
      run: vercel deploy --prebuilt --token ${{ secrets.VERCEL_TOKEN }}

This example assumes you have a build script in your package.json file and a VERCEL_TOKEN secret set up in your GitHub repository.

By using this workflow, your project will be built by GitHub Actions, and the pre-built output will be deployed to Vercel using the vercel deploy --prebuilt command. This ensures that your project is built only once during the deployment process.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

Vercel Documentation

Learn how to use GitHub Actions as your CI/CD provider to deploy to Vercel, including support for GitHub Enterprise Server.

Vercel Documentation

​Vercel for GitHub automatically deploys your GitHub projects with Vercel, providing Preview Deployment URLs, and automatic Custom Domain updates.

#

@pulsar cobalt kapa.ai is still learning and improving, please let us how it did by reacting below

pulsar cobalt
#

@frank path how can i cache with this

frank pathBOT
#

Let me check the knowledge base for you. One moment! :books:

#

To cache the build output with GitHub Actions, you can use the actions/cache action. This will help speed up your build times by caching the dependencies and build output between runs. Here's an updated example of the workflow configuration with caching:

name: Deploy to Vercel

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: 14

    - name: Cache node_modules
      uses: actions/cache@v2
      with:
        path: ~/.npm
        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-node-

    - name: Install dependencies
      run: npm ci

    - name: Build project
      run: npm run build

    - name: Cache build output
      uses: actions/cache@v2
      with:
        path: .next/cache
        key: ${{ runner.os }}-nextjs-cache-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-nextjs-cache-

    - name: Install Vercel CLI
      run: npm i -g vercel

    - name: Deploy to Vercel
      run: vercel deploy --prebuilt --token ${{ secrets.VERCEL_TOKEN }}

This configuration adds two caching steps:

  1. Cache node_modules using the actions/cache action with the ~/.npm path.
  2. Cache the build output (.next/cache) using the actions/cache action.

These caching steps will help speed up your build times by reusing the cached data between runs.

#

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

GitHub

Cache dependencies and build outputs in GitHub Actions - GitHub - actions/cache: Cache dependencies and build outputs in GitHub Actions

#

@pulsar cobalt kapa.ai is still learning and improving, please let us how it did by reacting below

pulsar cobalt
#

@frank path how can i cache vercels stuff

frank pathBOT
#

Let me check the knowledge base for you. One moment! :books:

#

To cache Vercel's build output using Turborepo and Vercel Remote Cache, follow these steps:

  1. Install Turborepo in your project by following the Turborepo guide (https://vercel.com/docs/concepts/monorepos/turborepo).

  2. Set up Remote Caching for Turborepo on Vercel by following these steps:

  3. Update your GitHub Actions workflow to use turbo run build instead of npm run build:

    # ...
    - name: Build project
      run: npx turbo run build
    # ...

By following these steps, you'll be using Turborepo and Vercel Remote Cache to cache the build output, which will be shared across your entire Vercel team and CI/CD pipelines.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

Vercel Documentation

Monorepos allow you to manage and organize multiple projects in a single directory so they are easier to work with. Learn how to deploy a monorepo here.

Vercel Documentation

Vercel Remote Cache allows you to share build outputs and artifacts across distributed teams.

Vercel Documentation

Learn about Turborepo, a build system for monorepos that allows you to have faster incremental builds, content-aware hashing, and Remote Caching.