部署后运行节点脚本?

bAr*_*don 15 deployment continuous-integration vercel

在 Vercel 上部署后是否有部署后挂钩或任何其他方式来运行 Node 脚本?

Eli*_*jas 0

Vercel 部署完成后,您可以将 Vercel 的 Webhook 与 Git 提供程序结合使用来运行 Node 脚本。此示例将使用 GitHub Actions,但您可以使用任何其他受支持的 Git 提供程序

配置 GitHub 操作

  1. 将您的 Git 存储库连接到您的项目。对于新项目,您可以遵循这些文档。对于现有项目,请访问项目仪表板的“设置”选项卡中的 Git 配置。

  2. 使用以下内容在 .github/workflows 中创建 GitHub 工作流:

# Using Playwright but you may use your E2E framework of choice
name: Playwright Tests

on:
  deployment_status:
    
  run-e2es:
    if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Install dependencies
      run: npm ci && npx playwright install --with-deps
    - name: Run tests
        run: npx playwright test
          env:
              BASE_URL: ${{ github.event.deployment_status.environment_url }}
Run Code Online (Sandbox Code Playgroud)

学分:官方文档