跳过主要内容
教程

将每个Pull Request转换为可安装的预览

不必等待TestFlight处理。Capgo PR预览让QA、PM和利益相关者在一分钟内在真实设备上测试功能。

马丁·多纳迪厄

马丁·多纳迪厄

内容营销人员

将每个Pull Request转换为可安装的预览

每个移动开发团队都曾经感受到的痛苦:一个特性已经准备好进行审查,但将其推送到利益相关者的手中意味着要在 TestFlight 或 Google Play 测试版审查迷宫中漫游。什么应该花费几分钟却变成了等待、安装和管理测试版构建的几个小时。

如果您的生产应用程序可以直接从任何拉取请求中拉取最新的更改,并将其推送到设备上,而无需重新安装或应用商店延迟?

这就是 PR 预览 enable. When a developer opens a pull request, a GitHub Action creates a dedicated update channel and publishes the changes. Anyone with the app installed can switch to that channel, test the feature, and switch back - all without leaving the app they already have.

当开发人员打开拉取请求时,__CAPGO_KEEP_0__ 动作会创建一个专用更新通道并发布更改。任何安装了该应用程序的人都可以切换到该通道,测试该特性,并切换回原来的应用程序 - 且不需要离开他们已经拥有的应用程序。

TestFlight 问题

  1. 传统的测试移动功能的工作流程大致如下: - Code is ready for review
  2. - __CAPGO_KEEP_0__ 已经准备好审查 等待 TestFlight
  3. - 15-30 分钟的处理时间 - 测试人员寻找正确的构建
  4. 测试和重复 - 每次改变意味着另一次等待

这会造成瓶颈。 QA 等待构建被阻塞。产品经理无法快速验证功能。开发人员在等待反馈时会失去上下文。行业估计这会导致每个 PR 的生产力损失约为 340 美元。

PR 预览

PR 预览使用 Capgo 的通道系统来创建每个 PR 的更新流。以下是流程:

  1. PR 打开或更新 - GitHub 动作触发
  2. 打包上传 - 您的 JS/CSS 更改将发送到 PR 特有的通道
  3. 评论发布 - 测试人员在 PR 中获得指示
  4. 立即测试 -切换频道、测试、切换回原频道

无新应用安装。无TestFlight延迟。同一生产应用可以从不同更新频道拉取。

设置PR预览

在您可以实现PR预览之前,项目需要先配置Capgo Live Updates。请遵循 Capgo快速入门指南 如果您还没有。

GitHub Actions Workflow

创建 .github/workflows/pr-preview.yml:

name: PR Preview
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Setup Bun
        uses: oven-sh/setup-bun@v2

      - name: Install Dependencies
        run: bun install

      - name: Build
        run: bun run build

      # Create a channel named after your PR (may already exist on synchronize)
      - name: Create PR Channel
        id: create_channel
        continue-on-error: true
        run: bunx @capgo/cli@latest channel add pr-${{ github.event.pull_request.number }} --self-assign
        env:
          CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}

      # Upload the build to that channel
      - name: Upload to Capgo
        run: bunx @capgo/cli@latest bundle upload --channel pr-${{ github.event.pull_request.number }}
        env:
          CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}

      # Post a comment with testing instructions (only on PR open)
      - name: Comment on PR
        if: github.event.action == 'opened'
        uses: actions/github-script@v7
        with:
          script: |
            github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: ${{ github.event.pull_request.number }},
              body: '📱 **Test this PR on device:**\n\nOpen your app and switch to channel: `pr-${{ github.event.pull_request.number }}`\n\nUse the shake menu or call `setChannel()` from your app.'
            })

关键是 --self-assign 标志在创建频道时使用。这样测试者就可以在应用内部使用__CAPGO_KEEP_0__切换到频道。 setChannel() API

设置 Capgo token

  1. 前往您的 Capgo 控制台
  2. 导航至设置 > API 密钥
  3. 生成一个新的密钥,具有 all 权限
  4. 将其添加为 CAPGO_TOKEN 您的 GitHub 仓库机密

测试人员如何切换频道

测试人员有两种方式切换到 PR 频道:

选项 1:摇动菜单(最简单)

在您的 Capacitor 配置中启用摇动菜单和频道选择器:

// capacitor.config.ts
const config: CapacitorConfig = {
  // ... your other config
  plugins: {
    CapacitorUpdater: {
      shakeMenu: true,
      allowShakeChannelSelector: true
    }
  }
};

测试人员摇晃他们的设备以打开调试菜单,菜单中显示可用的通道列表,带有搜索栏。他们找到他们的PR通道(例如,__CAPGO_KEEP_0__),点击选择它,应用程序自动下载并应用更新。当测试完成后,他们再次摇晃,切换回生产环境。 pr-123shake菜单自动处理整个流程:

通过__CAPGO_KEEP_0__获取所有可自行分配的通道

  1. 显示通道列表,带有搜索栏,以便找到特定的PR listChannels()
  2. 在选择后下载更新
  3. 提示重新加载,提示“立即重新加载”/“稍后”选项
  4. 选项2:自定义通道选择器UI

在应用程序中构建一个通道switcher,列出可用的PR通道,让测试人员选择一个。这使用了两个关键API:

- 获取所有启用自行分配的通道

  • listChannels() - 将设备切换到所选的通道
  • setChannel() 使用这些基本组件,您可以创建一个简单的UI:
import { CapacitorUpdater } from '@capgo/capacitor-updater';

// Get all available channels (including PR channels)
async function getAvailableChannels() {
  const { channels } = await CapacitorUpdater.listChannels();

  // Filter to show only PR channels
  const prChannels = channels.filter(c => c.name.startsWith('pr-'));

  return prChannels;
}

// Switch to a specific PR channel
async function switchToChannel(channelName: string) {
  await CapacitorUpdater.setChannel({
    channel: channelName,
    triggerAutoUpdate: true  // Immediately check for updates
  });
}

// Return to production
async function switchBackToProduction() {
  await CapacitorUpdater.unsetChannel({});
}

// Get current channel
async function getCurrentChannel() {
  const { channel } = await CapacitorUpdater.getChannel();
  return channel;
}

- 选项1:shake菜单

// Example: List PR channels and let user select
const channels = await getAvailableChannels();
const current = await getCurrentChannel();

// Display channels in your UI
channels.forEach(channel => {
  console.log(`${channel.name} ${channel.name === current ? '(current)' : ''}`);
});

// When user selects a channel
await switchToChannel('pr-123');

For a complete React component example, see 我们的频道浏览文章.

清理 PR 通道

当 PR 被合并或关闭时,您将希望清理通道。添加另一个工作流程:

name: Cleanup PR Preview
on:
  pull_request:
    types: [closed]

jobs:
  cleanup:
    runs-on: ubuntu-latest
    steps:
      - name: Delete PR Channel
        run: bunx @capgo/cli@latest channel delete pr-${{ github.event.pull_request.number }}
        env:
          CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}

这会在 PR 关闭时删除通道,保持您的通道列表清洁。

版本兼容性

PR 预览仅在 JavaScript 包装器与安装的本机版本兼容时才会工作。如果您的 PR 包含本机 code 变更(新 Capacitor 插件,iOS/Android 修改),测试人员将需要一个新的本机构建。

Capgo 会自动检查版本兼容性。如果 PR 的包装器目标的是不同的本机版本,而不是安装的版本,则更新将不会被应用。这会防止由于不兼容的 code 导致的崩溃。

对于需要本机变更的 PR,您将需要分发一个新的 TestFlight/Play Store 构建。PR 预览对于 JavaScript、CSS 和资产变更最有效,这些变更不涉及本机 code。

谁从 PR 预览中受益

QA 工程师

  • 测试特性立即在 PR 打开时
  • 不再需要重新安装
  • 验证修复和回归在真实设备上
  • 不再等待TestFlight处理

产品经理

  • 在合并之前查看特性
  • 直接在PR上给出反馈
  • 验证实现与要求相符
  • 减少审查周期时间

开发者

  • 对变化的反馈更快
  • 演示特性给利益相关者
  • 调试与特定用户相关的问题
  • 节省更多时间管理测试版

比较:传统版 vs PR预览

方面TestFlight/测试版Capgo PR预览
构建时间15-30 分钟小于 1 分钟
切换 PR5+ 分钟重新安装10 秒
设置复杂度App Store凭据一个工作流文件
清理手动自动
本机code更改必需可选 (仅 JS)

最佳实践

  1. 明确命名通道: 使用 pr-{number} 命名约定以便识别
  2. 自动清理: PR 关闭时始终删除频道
  3. 限制访问: 只在 debug/staging 构建中启用 shake 菜单
  4. 记录流程: 将测试指南添加到您的 PR 模板
  5. 优雅处理失败: 在发布评论之前检查频道创建是否成功

什么时候不应该使用 PR 预览

PR 预览适用于 JavaScript/CSS 变更。如果您的 PR 包含:

  • 新 Capacitor 插件
  • iOS 原生 code 变更
  • Android 原生 code 变更
  • 影响原生构建的依赖项更新

您需要传统的 TestFlight/Play Store 分发来实现这些变更。

与 Channel Surfing 结合使用

PR 预览在与 channel surfing结合使用时,最佳效果。

  • production 您的应用程序可以具有:
  • beta - 对所有用户的稳定版本
  • pr-123 - 对特定 PR 的功能预览

- 对特定 PR 的早期访问

测试者可以在同一应用程序中切换到任何 PR 通道,测试功能,然后切回 - 所有这些都在同一应用程序中。

结论

PR 预览将如何改变您的团队审查和测试移动功能。

The setup is minimal - one GitHub Actions workflow file - and the benefits compound across your team. QA stays unblocked, product managers review faster, and developers get quicker feedback.

设置很简单 - 只需一个 __CAPGO_KEEP_0__ Actions 工作流文件 - 并且好处会在您的团队中累积。

QA 不会被阻塞,产品经理可以更快地审查,开发人员可以更快地获得反馈。

从一个仓库开始添加工作流程,看到它如何改变您的审查流程。 继续从 Turn Every Pull Request Into an Installable Preview 中学习。如果您正在使用... 为计划频道路由和分阶段发布,连接它 频道 频道 频道 频道 Beta 测试解决方案 为 Beta 测试解决方案中的产品工作流程 版本目标解决方案 为版本目标解决方案中的产品工作流程 __CAPGO_KEEP_0__

Capacitor 应用的实时更新

当 web 层 bug 活跃时,通过 Capgo 将修复推送到用户,而不是等待几天的 app store 审批。用户在后台接收更新,而原生变化仍然在正常的审批路径中。

立即开始

博客最新文章

Capgo 为您提供了创建真正专业的移动应用所需的最佳见解。