CI/CD 集成
复制一个包含安装步骤和完整 Markdown 指南的配置提示。
将 Capgo integrates 到您的 CI/CD pipeline 中,可让您完全自动化应用程序构建和部署更新的过程。通过利用 Capgo CLI 和 semantic-release,您可以确保一致、可靠的部署,并启用快速迭代。
CI/CD 集成的好处
CI/CD 集成的好处部分-
自动化:不再需要手动步骤或人为错误。您可以从头到尾自动化整个构建、测试和部署过程。
-
一致性: Every deployment follows the same set of steps, ensuring a predictable and repeatable process. This is especially valuable when you have multiple team members contributing code.
-
更快的迭代:通过自动化部署,您可以更频繁地发布更新并且有信心。无需等待手动QA或发布审批。
Capgo CLI
Capgo CLI部分Capgo CLI 是将 Capgo 集成到 CI/CD 工作流中的关键。它提供推送新捆绑版本、管理通道等命令。
CI/CD 集成的关键命令 bundle upload:
npx @capgo/cli@latest bundle upload --channel Production --apikey YOUR_API_KEY如果您使用加密,请从以下方式之一提供:
使用私钥文件路径:
npx @capgo/cli@latest bundle upload --channel Production --apikey YOUR_API_KEY --key-v2 PRIVATE_KEY_PATH直接使用私钥内容(CI/CD推荐):
npx @capgo/cli@latest bundle upload --channel Production --apikey YOUR_API_KEY --key-data-v2 PRIVATE_KEY_CONTENT使用环境变量(CI/CD最佳实践):
npx @capgo/cli@latest bundle upload --channel Production --apikey YOUR_API_KEY --key-data-v2 "$CAPGO_PRIVATE_KEY"设置环境变量进行加密
设置环境变量进行加密对于CI/CD环境,建议将私钥存储为环境变量而不是文件。以下是如何设置它:
-
获取私钥内容:
终端窗口 cat .capgo_key_v2 | pbcopy将密钥内容复制到剪贴板。
-
将其添加到CI/CD环境:
- GitHub操作:添加
CAPGO_PRIVATE_KEY到您的仓库密钥 - GitLab CI: 在项目设置中添加它作为一个被掩码的变量
- CircleCI: 在项目设置中添加它作为一个环境变量
- Jenkins: 在项目设置中添加它作为一个密文文本凭证
- GitHub操作:添加
-
在管道中使用它:
- run: npx @capgo/cli@latest bundle upload --channel=production --apikey=${{ secrets.CAPGO_API_KEY }} --key-data-v2 "${{ secrets.CAPGO_PRIVATE_KEY }}"
注意: 这个 --key-data-v2 标志允许您将私钥内容直接作为一个字符串传递,适合用于CI/CD管道中的环境变量,避免创建临时文件。
这个命令会将当前的web构建上传到指定的频道。您通常会在CI/CD管道的最后一步运行这个命令,之后web构建完成成功后。
在CI/CD管道中设置Capgo
Section titled “在 CI/CD Pipeline 中设置 Capgo”虽然具体步骤会根据您选择的 CI/CD 工具而有所不同,但将 Capgo 集成到 CI/CD Pipeline 中的通用过程如下:
-
生成一个 API 密钥: 登录到 Capgo 控制台并创建一个新的 API 密钥。这个密钥将用于在 CI/CD 环境中验证 CLI。请保密并不要将其提交到您的仓库!
-
配置
bundle upload命令: 将步骤添加到您的 CI/CD 配置中,运行bundle upload命令复制到剪贴板,并使用适当的参数: - run: npx @capgo/cli@latest bundle upload --channel=production --apikey=${{ secrets.CAPGO_API_KEY }}Production\n 替换为您要部署到的频道${{ secrets.CAPGO_API_KEY }}使用环境变量来持有你的API密钥,并添加--key-data-v2 "${{ secrets.CAPGO_PRIVATE_KEY }}"如果使用加密。 -
添加
upload步骤在你的web构建之后:确保步骤在你的web构建完成后才会执行。这确保了你总是部署最新的__CAPGO_KEEP_0__。uploadstep comes after your web build has completed successfully. This ensures you’re always deploying your latest code.\n Here’s an example configuration for GitHub Actions:\nupload.yml name: Deploy to Capgoon:push:branches: [main]jobs:deploy:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v6- uses: actions/setup-node@v6with:node-version: '24'- run: npm ci- run: npm run build- run: npm install -g @capgo/cli- run: npx @capgo/cli@latest bundle upload --channel=production --apikey=${{ secrets.CAPGO_API_KEY }} --key-data-v2 "${{ secrets.CAPGO_PRIVATE_KEY }}"
语义发布管理版本
关于语义发布管理版本的部分使用Capgo来管理版本的推荐方法是,在你的 capacitor.config.ts 文件中设置版本,通过从中导入它 package.json:
import pkg from './package.json'
const config: CapacitorConfig = { // ... other config plugins: { CapacitorUpdater: { version: pkg.version, } }}这种方法允许您:
- 使用semantic-release(或任何其他工具)来更新
package.json__CAPGO_KEEP_0__ - 使用更新的版本自动构建您的应用
- 上传包含正确版本的捆绑包
您的CI/CD工作流程将如下所示:
- run: npm ci- run: npx semantic-release # Updates package.json version- run: npm run build # Builds with new version from capacitor.config- run: npx @capgo/cli@latest bundle upload --channel=production --apikey=${{ secrets.CAPGO_API_KEY }}以下是semantic-release的示例 .releaserc __CAPGO_KEEP_0__
{ "branches": [ "main", { "name": "beta", "prerelease": true } ], "plugins": [ "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", "@semantic-release/changelog", [ "@semantic-release/git", { "assets": ["CHANGELOG.md", "package.json"], "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" } ] ]}复制到剪贴板
- 分析提交信息以确定下一个版本号,遵循 Conventional Commits spec.
- 根据自上次发布以来提交的更改生成发布说明。
- 文件
CHANGELOG.md更新 - 文件
package.jsonversion, which will be picked up by your capacitor.config. - 版本号,会被您的__CAPGO_KEEP_0__.config拾取。
CHANGELOG.md,package.json将更新的
, package.json is included in your build through the capacitor.config.
确保在构建应用之前运行 semantic-release,才能将从__CAPGO_KEEP_0__.config获取的更新版本包含在构建中。
故障排除If you encounter issues with your Capgo CI/CD integration, here are a few things to check:
-
API key: Ensure your API key is valid and has the necessary permissions. If using an environment variable, double check that it’s set correctly.
-
CLI version: Make sure you’re using the latest version of the Capgo CLI. Older versions may have compatibility issues or lack certain features.
-
Build artifacts: Confirm that your web build is generating the expected output files. The Capgo CLI needs a valid web build to create a bundle.
-
Network connectivity: Check that your CI/CD environment has network access to the Capgo servers. Firewall or proxy issues can sometimes interfere with the
uploadcommand.
If you’re still having trouble, reach out to Capgo support for assistance. They can help troubleshoot any issues with your specific setup.
Conclusion
结论将Capgo正确地整合到CI/CD管道中并进行版本管理,可以显著地简化您的开发流程。通过自动化您的部署和版本管理,通过capacitor.config方法,您可以更快地发布更新并且更有信心。
建议的方法是将版本设置在您的 capacitor.config.ts 文件中,并使用semantic-release更新 package.json 提供了一个强大的和可靠的部署流程,使您可以专注于构建伟大的功能,而不必担心手动发布步骤。
有关Capgo CLI命令和选项的更多详细信息,请参阅 CLI参考。有关semantic-release配置的更深入的了解,请参阅 semantic-release文档.
祝您顺利部署!
继续CI/CD集成
继续从CI/CD集成如果您正在使用 CI/CD 集成 来规划 CI/CD 自动化,连接它与 Capgo CI/CD 为产品工作流程在 Capgo CI/CD 中 Capgo 原生构建 为产品工作流程在 Capgo 原生构建中 Capgo 集成 为产品工作流程在 Capgo 集成中 GitHub 动作集成 为实现细节在 GitHub 动作集成中 GitLab CI/CD 集成 GitLab CI/CD 集成的实现细节。