メインコンテンツにジャンプ

CI/CD統合

CI/CDパイプラインにCapgoを統合することで、完全に自動化されたアプリのビルドとデプロイのプロセスを実現できます。CapgoとCLI、およびsemantic-releaseを活用することで、安定したデプロイを保証し、迅速な開発を可能にします。

CI/CD統合の利点

CI/CD統合の利点
  • 自動化: 人間の間違いや手作業が必要なステップがなくなります。ビルド、テスト、デプロイ全プロセスが自動化され、エンドツーエンドで管理されます。

  • 一貫性: すべてのデプロイメントは、同じセットのステップに従っており、予測可能で繰り返し可能なプロセスを保証しています。これは、複数のチームメンバーが code に貢献する場合に特に価値があります。

  • より速い反復: 自動化されたデプロイメントを使用すると、更新を頻繁に、そして信頼性の高いもので配信できます。手動のQAまたはリリース承認を待つ必要はありません。

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で使用するためにプライベートキーのコンテンツを直接使用する (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環境では、ファイルとしてではなく環境変数としてプライベートキーコンテンツを保存することをお勧めします。以下の手順に従って設定してください。

  1. プライベートキーコンテンツを取得する:

    ターミナル画面
    cat .capgo_key_v2 | pbcopy

    キー コンテンツをクリップボードにコピーします。

  2. CI/CD 環境に追加する:

    • GitHub Actions: 追加 CAPGO_PRIVATE_KEY リポジトリのシークレットに追加する
    • GitLab CI: プロジェクト設定のマスクされた変数として追加する
    • CircleCI: プロジェクト設定の環境変数として追加する
    • Jenkins: プロジェクト設定のシークレットテキスト認証情報として追加する
  3. Use it in your pipeline:

    - run: npx @capgo/cli@latest bundle upload --channel=production --apikey=${{ secrets.CAPGO_API_KEY }} --key-data-v2 "${{ secrets.CAPGO_PRIVATE_KEY }}"

Note: The --key-data-v2 flag allows you to pass the private key content directly as a string, making it perfect for environment variables in CI/CD pipelines where you don’t want to create temporary files.

This command uploads the current web build to the specified channel. You’ll typically run this as the last step in your CI/CD pipeline, after your web build has completed successfully.

While the exact steps will vary depending on your CI/CD tool of choice, the general process for integrating Capgo looks like this:

  1. Generate an API key: Log in to the Capgo dashboard and create a new API key. This key will be used to authenticate the CLI in your CI/CD environment. Keep it secret and never commit it to your repository!

  2. Configure the bundle upload コマンド: CI/CD構成に実行するステップを追加して、 bundle upload コマンドと適切な引数を実行します:

    upload.yml
    - run: npx @capgo/cli@latest bundle upload --channel=production --apikey=${{ secrets.CAPGO_API_KEY }}
    置き換え Production デプロイ先のチャンネルに置き換え ${{ secrets.CAPGO_API_KEY }} 環境変数にAPIキーを保持する --key-data-v2 "${{ secrets.CAPGO_PRIVATE_KEY }}" 暗号化を使用する場合に追加します。

  3. Webビルド後にステップを追加してください upload : CI/CD構成に実行するステップを追加して、コマンドと適切な引数を実行します: upload step comes after your web build has completed successfully. This ensures you’re always deploying your latest code. Here’s an example configuration for GitHub Actions:

    upload.yml
    name: Deploy to Capgo
    on:
    push:
    branches: [main]
    jobs:
    deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
    - uses: actions/setup-node@v6
    with:
    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 }}"

バージョン管理のSemantic-release

バージョン管理のSemantic-release

The recommended way to handle versioning with Capgo is to set the version in your capacitor.config.ts ファイルからインポートすることです。 package.json:

import pkg from './package.json'
const config: CapacitorConfig = {
// ... other config
plugins: {
CapacitorUpdater: {
version: pkg.version,
}
}
}

このアプローチにより、次のことが可能になります。

  1. semantic-release (または他のツール)を使用してバージョンを更新する package.json バージョンを自動的に含むアプリをビルドする
  2. バージョンを自動的に含むアプリをビルドする
  3. __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 }}

Conventional Commits規格に従って、次のバージョン番号を決定するためにコミットメッセージを分析します。 .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}"
}
]
]
}

__CAPGO_KEEP_0__

  1. __CAPGO_KEEP_0__
  2. __CAPGO_KEEP_0__
  3. __CAPGO_KEEP_0__ CHANGELOG.md __CAPGO_KEEP_0__
  4. __CAPGO_KEEP_0__ package.json バージョン、capacitorのconfigによって取得されます。
  5. 更新された CHANGELOG.md, package.json、およびその他の変更されたファイルをリポジトリに戻します。

アプリをビルドする前に、semantic-releaseを実行してください。 したがって、__CAPGO_KEEP_0__のconfigによって更新されたバージョンがビルドに含まれます。 package.json is included in your build through the capacitor.config.

Capgoキー

  • APIキーが有効であり、必要な権限を持っていることを確認してください。環境変数を使用している場合は、正しく設定されていることを確認してください。APIバージョン

  • CLI __CAPGO_KEEP_1__の最新バージョンを使用していることを確認してください。古いバージョンでは、互換性の問題や特定の機能の欠如が発生する可能性があります。: Make sure you’re using the latest version of the Capgo CLI. Older versions may have compatibility issues or lack certain features.

  • ビルドアーティファクトCapgoのWebビルドが期待どおりの出力ファイルを生成していることを確認する。CapgoとCLIには、有効なWebビルドが必要です。

  • ネットワーク接続性CI/CD環境がCapgoサーバーにネットワーク接続できることを確認する。ファイアウォールまたはプロキシの問題が、まれにCapgoサーバーへの接続に影響を与えることがある。 upload コマンド

問題が解決しない場合は、Capgoサポートに連絡してください。特定の設定に関して、問題をトラブルシューティングするのに役立ちます。

Integrating Capgo into your CI/CD pipeline with proper version management can greatly streamline your development workflow. By automating your deployments and versioning through the capacitor.config approach, you can ship updates faster and with more confidence.

ファイルとsemantic-releaseを使用することで、信頼性の高いデプロイプロセスが実現し、開発者は機能の開発に集中できるようになります。手動のリリースステップに心配する必要がなくなります。 capacitor.config.ts __CAPGO_KEEP_0__ package.json __CAPGO_KEEP_1__

詳細については、Capgo CLI コマンドとオプションについては、 CLI リファレンスを参照してください。 また、シームアントリリースの設定については、 シームアントリリース ドキュメント.

を参照してください。

ハッピーデプロイ!

CI/CD統合から続けて

セクションのタイトル “CI/CD統合から続けて” CI/CD統合を使用してCI/CDの自動化を計画している場合、 Cloudflare CI/CD をCapgo CI/CD for the product workflow in Capgo CI/CD, Capgo Native Builds 製品ワークフロー用に Capgo Native Builds を使用します。 Capgo Integrations 製品ワークフロー用に Capgo Integrations を使用します。 GitHub Actions Integration 実装詳細用に GitHub Actions Integration を使用します。 GitLab CI/CD Integration 実装詳細用に GitLab CI/CD Integration を使用します。