Skip to content

在流水线内使用

推荐在自动化的流水线内,配置上本工具。

简单的 github workflow 示例

详情
yaml
name: 自写的vercel部署工具
env:
  # 必须密文提供token
  VERCEL_TOKEN: ${{ secrets.vercel_token }}
  # 可以明文提供组织id和项目id
  # VERCEL_ORG_ID: ${{ secrets.vercel_orgId }}
  # VERCEL_PROJECT_ID: ${{ secrets.vercel_projectId }}

on:
  push:
    branches:
      # 可以自选分支 为了避免过快耗尽vercel额度,建议只在main分支内触发部署
      - main

jobs:
  Deploy-Production:
    runs-on: ubuntu-latest
    steps:
      - name: 检出分支
        uses: actions/checkout@v4

      - name: 安装pnpm
        uses: pnpm/action-setup@v4
        with:
          # 若项目提供了packageManager配置 这里可以不提供该配置
          # version: 9
          # 必须安装 vercel @dotenvx/dotenvx tsx 这三个全局包
          run_install: |
            - recursive: true
            - args: [--global, "vercel", "@dotenvx/dotenvx", "tsx"]

      - name: 安装node
        uses: actions/setup-node@v4
        with:
          node-version: 20.15.1
          cache: pnpm

      - name: 检查版本
        run: |
          node -v
          pnpm -v
          vc -v

      - name: pnpm全局检查依赖包
        run: pnpm ls -g

      - name: 运行自写的vercel部署工具
        # 读取环境变量
        # https://dotenvx.com/docs/cis/github-actions#install-dotenvx
        # pnpm run your-command
        run: |
          curl -sfS https://dotenvx.sh/install.sh | sh
          pnpm dotenvx run -- pnpm run deploy-vercel

带有远程 turbo 缓存的 github workflow

详情
yaml
# 参考资料
# https://vercel.com/guides/how-can-i-use-github-actions-with-vercel
# https://vercel.com/guides/how-to-alias-a-preview-deployment-using-the-cli

name: 自写的vercel部署工具
env:
  VERCEL_TOKEN: ${{ secrets.vercel_token }}
  # 根据 vercel-deploy-tool 部署配置来决定是否需要以下环境变量
  # VERCEL_ORG_ID: ${{ secrets.vercel_orgId }}
  # VERCEL_PROJECT_ID: ${{ secrets.vercel_projectId }}
  # https://turborepo.com/docs/crafting-your-repository/constructing-ci#enabling-remote-caching
  # https://vercel.com/docs/monorepos/remote-caching#use-remote-caching-from-external-ci/cd
  TURBO_TOKEN: ${{ secrets.vercel_token }}
  TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

on:
  push:
    branches:
      - main

jobs:
  Deploy-Production:
    runs-on: ubuntu-latest
    steps:
      - name: 检出分支
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: 安装pnpm
        uses: pnpm/action-setup@v4
        with:
          run_install: |
            - recursive: true
            - args: [--global, "vercel", "@dotenvx/dotenvx", "tsx", "turbo"]

      - name: 安装node
        uses: actions/setup-node@v4
        with:
          node-version: 20.15.1
          cache: pnpm

      - name: 检查版本
        run: |
          node -v
          pnpm -v
          vc -v

      - name: pnpm全局检查依赖包
        run: pnpm ls -g

      - name: turbo login 远程登录
        run: turbo login --token=${{env.TURBO_TOKEN}} --team=${{env.TURBO_TEAM}}

      - name: turbo link 链接远程项目
        run: turbo link --token=${{env.TURBO_TOKEN}} --scope=${{env.TURBO_TEAM}} --yes

      - name: 运行自写的vercel部署工具
        # https://dotenvx.com/docs/cis/github-actions#install-dotenvx
        run: |
          curl -sfS https://dotenvx.sh/install.sh | sh
          pnpm dotenvx run -- pnpm run deploy

贡献者

The avatar of contributor named as ruan-cat ruan-cat

页面历史