跳过内容

自动选择 Live Update 或原生构建

大多数 Capacitor 发布都是 JavaScript-only 的,应该以 live update。有些变更触及本机 code,需要从 code 构建 Capgo 构建. This guide shows how to make GitHub Actions, GitLab CI, or any other CI/CD platform pick the correct path on every push — without a human deciding.

Page/area: Capgo solutions marketing page. Role: Short UI label or navigation item. Seen in: page solutions/white-label.astro. Preserve Capgo product/brand and developer terms exactly. Message key `solutions_white_label_visual_cell3_value` (Solutions White Label Visual Cell3 Value).

。本指南展示如何让 __CAPGO_KEEP_0__ Actions、GitLab CI 或任何其他 CI/CD 平台在每次推送时选择正确的路径 —— 无需人类决定。

Capgo已经知道哪个路径是安全的。完成您的网页构建(并在上传或请求本机构建之前),运行:

决定
npx @capgo/cli@latest bundle releaseType com.example.app --channel production
# → OTA ship with bundle upload
# → native ship with Capgo Build

OTA 表示本地包与已在渠道上发布的包匹配。 native 表示插件、Capacitor版本或其他本地依赖发生了变化——仅通过OTA包无法安全地更新设备。

releaseType 比较 本地包元数据 (Capacitor/Cordova插件和版本)。它不会 查看 、或 ios/, android/, or capacitor.config.*进行依赖兼容性检查——以下示例会同时进行两者。 releaseType 参见

本地兼容性 means the native packages match what is already live on the channel. 了解完整的规则和手册。 bundle compatibility 表格。

  • Capgo应用程序已注册并且有一个Capgo __CAPGO_KEEP_1__密钥 Capgo API 密钥 Live Updates上传正在工作( CAPGO_TOKEN
  • Live Updates 上传成功bundle upload) — 见 CI/CD 集成
  • Capgo 在 CI 中配置建置凭据,如果您期望原生作业 — 见 GitHub 动作 或 原生作业
  • 或 production)
  • 凭据 metadata 一个已存在且与生产匹配的频道(例如 --auto-min-update-version 频道在
策略,因此每次上传都可以携带
npx @capgo/cli@latest channel set production com.example.app --disable-auto-update metadata

CI/CD管道应该如何工作

How the Pipeline Should Work
  1. 按照正常的方式构建 Web 资产。
  2. 如果提交涉及 ios/, android/或 capacitor.config.*强制使用原生路径。
  3. 否则请Capgo releaseType 判断提交是否安全。
  4. 如果 OTA,上传到 --fail-on-incompatible 和 --auto-min-update-version.
  5. 如果 native,执行Capgo Build,然后上传匹配的捆绑包 --auto-min-update-version 以便频道的本地元数据得到更新 不 不要 --fail-on-incompatible 用于该基线上传 — 新的本地包应该有所不同。请参见 Native + OTA 频道工作流 频道级FAQ

GitHub 操作

GitHub Actions

一项工作流程,用于控制本地路径,然后根据 releaseType:

github/workflows/capgo-release.yml
name: Capgo Release
on:
push:
branches: [main]
jobs:
decide:
runs-on: ubuntu-latest
outputs:
release_type: ${{ steps.verdict.outputs.type }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'npm'
- run: npm ci
- run: npm run build
- name: Decide OTA vs native
id: verdict
env:
CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}
run: |
BEFORE="${{ github.event.before }}"
if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
BEFORE="$(git rev-parse HEAD~1 2>/dev/null || echo '')"
fi
if [ -z "$BEFORE" ] || git diff --name-only "$BEFORE" "${{ github.sha }}" \
| grep -qE '^(ios/|android/|capacitor\.config\.)'; then
TYPE=native
echo "Native path/config changed (or no prior commit) — forcing native"
else
TYPE=$(npx @capgo/cli@latest bundle releaseType com.example.app --channel production | tr -d '[:space:]')
fi
echo "type=$TYPE" >> "$GITHUB_OUTPUT"
echo "Capgo release type: $TYPE"
live_update:
needs: decide
if: needs.decide.outputs.release_type == 'OTA'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'npm'
- run: npm ci
- run: npm run build
- name: Upload live update
env:
CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}
run: |
npx @capgo/cli@latest bundle upload com.example.app \
--channel production \
--fail-on-incompatible \
--auto-min-update-version
native_build:
needs: decide
if: needs.decide.outputs.release_type == 'native'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform: [ios, android]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npx cap sync ${{ matrix.platform }}
- name: Capgo Build ${{ matrix.platform }}
env:
CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
CAPGO_IOS_PROVISIONING_MAP: ${{ secrets.CAPGO_IOS_PROVISIONING_MAP }}
APPLE_KEY_ID: ${{ secrets.APPLE_KEY_ID }}
APPLE_ISSUER_ID: ${{ secrets.APPLE_ISSUER_ID }}
APPLE_KEY_CONTENT: ${{ secrets.APPLE_KEY_CONTENT }}
APP_STORE_CONNECT_TEAM_ID: ${{ secrets.APP_STORE_CONNECT_TEAM_ID }}
ANDROID_KEYSTORE_FILE: ${{ secrets.ANDROID_KEYSTORE_FILE }}
KEYSTORE_KEY_ALIAS: ${{ secrets.KEYSTORE_KEY_ALIAS }}
KEYSTORE_KEY_PASSWORD: ${{ secrets.KEYSTORE_KEY_PASSWORD }}
KEYSTORE_STORE_PASSWORD: ${{ secrets.KEYSTORE_STORE_PASSWORD }}
PLAY_CONFIG_JSON: ${{ secrets.PLAY_CONFIG_JSON }}
run: |
npx @capgo/cli@latest build request com.example.app \
--platform ${{ matrix.platform }} \
--build-mode release
native_bundle:
needs: [decide, native_build]
if: needs.decide.outputs.release_type == 'native'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'npm'
- run: npm ci
- run: npm run build
- name: Upload bundle for new native baseline
env:
CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}
run: |
# Channel must already be on metadata (see Prerequisites above)
npx @capgo/cli@latest bundle upload com.example.app \
--channel production \
--auto-min-update-version

替换 com.example.app 并将签名密钥按照 GitHub GitHub 的动作 Capgo 构建.

以便后续的检查可以看到新原生包。

GitLab CI

GitLab评估 rules 当管道创建时,GitLab评估分支中的shell if 内部一个部署作业(或生成一个动态子管道) 如果您需要单独的本机矩阵作业): .gitlab-ci.yml

复制到剪贴板
image: node:24
stages:
- build
- deploy
variables:
APP_ID: com.example.app
CHANNEL: production
build_web:
stage: build
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
- node_modules/
expire_in: 1 hour
only:
- main
deploy:
stage: deploy
needs: [build_web]
script:
- |
BEFORE="${CI_COMMIT_BEFORE_SHA:-}"
if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
BEFORE="$(git rev-parse HEAD~1 2>/dev/null || echo '')"
fi
if [ -z "$BEFORE" ] || git diff --name-only "$BEFORE" "$CI_COMMIT_SHA" \
| grep -qE '^(ios/|android/|capacitor\.config\.)'; then
TYPE=native
else
TYPE=$(npx @capgo/cli@latest bundle releaseType "$APP_ID" --channel "$CHANNEL" | tr -d '[:space:]')
fi
echo "Capgo release type: $TYPE"
if [ "$TYPE" = "OTA" ]; then
npx @capgo/cli@latest bundle upload "$APP_ID" \
--channel "$CHANNEL" \
--fail-on-incompatible \
--auto-min-update-version
elif [ "$TYPE" = "native" ]; then
npx cap sync
npx @capgo/cli@latest build request "$APP_ID" --platform ios --build-mode release
npx @capgo/cli@latest build request "$APP_ID" --platform android --build-mode release
npx @capgo/cli@latest bundle upload "$APP_ID" \
--channel "$CHANNEL" \
--auto-min-update-version
else
echo "Unexpected release type: $TYPE" >&2
exit 1
fi
only:
- main

Store CAPGO_TOKEN 并且 Capgo 将构建签名变量作为掩码/保护的CI/CD变量。

Section titled “Other CI Platforms”

其他CI平台

无论在哪里,相同的三个步骤都有效:

步骤命令
判决npx @capgo/cli@latest bundle releaseType APP_ID --channel production
OTA路径npx @capgo/cli@latest bundle upload APP_ID --channel production --fail-on-incompatible --auto-min-update-version
原生路径npx @capgo/cli@latest build request APP_ID --platform ios (或 android) --build-mode release

将 shell 退出/标准输出映射到您的平台的条件语句(或保留一个 shell ifGitLab(如上所示)

  • Azure Pipelines —从脚本步骤设置一个输出变量,然后使用 condition: eq(variables['releaseType'], 'OTA')
  • Bitbucket Pipelines — 写 RELEASE_TYPE=… 到 $BITBUCKET_PIPELINES_VARIABLES_PATH在产品页面中,Live Updates output-variables,在 condition: state: RELEASE_TYPE == "OTA" ,并在后续步骤中分支 condition)
  • (仅文件存档无法驱动 — when CircleCI if 在配置编译时间评估,因此使用一个运行时shell when
  • Jenkins Jenkins when { environment name: 'RELEASE_TYPE', value: 'OTA' }

— 将 stdout 捕获到一个环境变量中并使用

路径过滤(可选加速)

路径过滤器是一种成本优化,而不是Capgo检查的替代品。更倾向于排除仅用于文档的路径,而不是维护一个脆弱的白名单——web构建通常还依赖于 vite.config.*, tsconfig*.json,以及框架配置文件:

on:
push:
branches: [main]
paths-ignore:
- '**.md'
- 'docs/**'
- '.github/**'

如果您使用白名单代替,包括web和native构建读取的所有输入,而不仅仅是 src/ 和 package.json.

native判决后

native判决后

当CI选择native时:

  1. Capgo构建生成签名的二进制文件并可以提交到TestFlight/Play(请参见 配置).
  2. 上传匹配的JS包裹 --auto-min-update-version (元数据策略)以便通道记录新的native包裹——否则下一个仅JS提交仍然返回 native.
  3. 用户安装新二进制文件后,后续仅包含 JavaScript 的提交将恢复到 OTA 再次。