跳过内容

自动选择实时更新或原生构建

大多数 Capacitor 发布都是 JavaScript-only,应该以 实时更新的形式发布。有些变更会影响本机 code,需要从 code Build Capgo Build本指南展示了如何让 GitHub Actions、GitLab CI 或任何其他 CI/CD 平台在每次推送时都能选择正确的路径 —— 而不需要人类介入。

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

终端窗口
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/、或 capacitor.config.*路径。先在git中gate这些路径,然后使用 releaseType for dependency compatibility — the examples below do both.

查看 原生兼容性 查看完整规则和手册 bundle compatibility 提示

终端窗口
npx @capgo/cli@latest channel set production com.example.app --disable-auto-update metadata
  1. 按照正常方式构建Web资源
  2. 如果提交涉及 ios/, android/,或 capacitor.config.*强制使用原生路径
  3. 否则,请Capgo判断提交是否安全 releaseType 如果
  4. else OTA,上传 --fail-on-incompatible 并且 --auto-min-update-version.
  5. If native, run Capgo Build, then upload the matching bundle with --auto-min-update-version不要 用于该基线上传 — 新的本机包应该有所不同。请参阅 --fail-on-incompatible Native + OTA Channel Workflow 关于频道级FAQ __CAPGO_KEEP_0__ Actions

GitHub Actions

GitHub Build

一个工作流程,用于控制原生路径,然后根据 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 Actions for Capgo Build.

GitLab 会评估 rules 当管道创建时,分支将使用 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

GitLab CI 部分 CAPGO_TOKEN 并且 Capgo 将签名变量作为掩码/保护的CI/CD变量。

在任何地方都可以使用相同的三个步骤:

步骤命令
判决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 if,如GitLab上面的那样

  • Azure Pipelines — 脚本步骤中设置一个输出变量,然后使用 condition: eq(variables['releaseType'], 'OTA')
  • Bitbucket Pipelines — 写 RELEASE_TYPE=…$BITBUCKET_PIPELINES_VARIABLES_PATHoutput-variables,并在后续步骤中使用 condition: state: RELEASE_TYPE == "OTA" (仅文件存档无法驱动 condition)
  • CircleCIwhen 在配置编译时间评估,因此使用一个运行时shell if (或动态配置/继续),而不是工作区值在 when
  • Jenkins ——将 stdout 捕获到环境变量中并使用 when { environment name: 'RELEASE_TYPE', value: 'OTA' }

路径过滤器(可选加速)

标题:路径过滤器(可选加速)

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

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

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

当CI选择native时:

  1. Capgo Build生成签名二进制文件并可以提交到TestFlight / Play(请参见 配置).
  2. 上传匹配的 JS 包 --auto-min-update-version (元数据策略) 以便渠道记录新的本机包 — 否则下一个仅 JS 提交仍会返回 native.
  3. 一旦用户安装了新的二进制文件,后续的 JavaScript-only 提交将返回 OTA 相关指南
本机兼容性