ビットライズCIによるコードプッシュアップデート
CodePush のアップデートは、次の方法でリリースできます。 ビットライズ CI ワークフロー これにより、iOS と Android の両方用のアップデートパッケージが作成され、Bitrise CodePush サーバーの両方がアップデートされます。
CodePush のアップデートは、次の方法でリリースできます。 ビットライズ CI ワークフロー。このプロセスには以下が必要です。
-
CodePush 認証情報のセットアップ:作成 シークレット そして 環境変数 Bitrise CodePush からのデプロイメントIDとデプロイキーが格納されています。
-
iOSとAndroidの両方のアップデートパッケージを作成し、両方をBitrise CodePushサーバーにアップデートするワークフローを作成します。
ビットライズでのコードプッシュ認証情報の設定
-
認証情報を取得: リリース管理アプリ ID と CodePush デプロイ ID とデプロイキーが必要です。
-
環境変数の作成 デプロイ ID と接続アプリケーション ID の場合:
-
IOS_PROD_DEPLOYMENT_ID: iOS アプリケーションのデプロイ ID。 -
ANDROID_PROD_DEPLOYMENT_ID: Android アプリのデプロイ ID。 -
IOS_CONNECTED_APP_ID: iOS アプリのアプリ ID。 -
ANDROID_CONNECTED_APP_ID: iOS アプリのアプリ ID。
-
-
シークレットを作成 デプロイキーと API トークンの場合:
-
IOS_PROD_DEPLOYMENT_KEY: Bitrise CodePush からの iOS デプロイメントのデプロイメントキー。 -
ANDROID_PROD_DEPLOYMENT_KEY: Bitrise CodePush からの Android デプロイメントのデプロイメントキー。 -
BITRISE_API_TOKEN: 個人アクセストークンまたはワークスペース API トークン。
-
CodePush 更新用のワークフローの作成
このセクションでは、CI を作成する方法を説明します。 ワークフロー これにより、次のようになります。
-
iOS 用のアップデートパッケージを作成します。
-
iOS アップデートパッケージを Bitrise CodePush サーバーにアップロードしてください。
-
Android 用のアップデートパッケージを作成します。
-
Bitrise CodePush サーバーにアンドロイド用アップデートパッケージをアップロードしてください。
リアクトネイティブアプリ
エキスポアプリ
-
ワークフローを作成し、その後
git-cloneステップ 1、追加npmステップウィズinstallコマンド:--- format_version: '13' default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: ios workflows: codepush_update_to_server: description: The workflow will generate and push your update to CodePush Server. steps: - git-clone@8: {} - npm@1: inputs: - command: install -
を追加
scriptJSON パーサーを使用してアプリバージョンを抽出し、を使用して環境変数にバージョンを設定するステップenvman:- script@1: title: Extract App Version inputs: - content: |- #!/bin/bash set -e # Extract version from app.json using jq (JSON parser) VERSION=$(jq -r '.version' package.json) # Verify version extraction if [ -z "$VERSION" ]; then echo "Error: Could not extract version from package.json" exit 1 fi echo "Extracted version from package.json: $VERSION" # Set the environment variable using envman envman add --key APP_VERSION --value "$VERSION" echo "Successfully set APP_VERSION=$VERSION" -
もう一つ追加
scriptのクローンを作成するステップrelease-management-recipesGitHub のリポジトリ。これには、後で使用するアップロードスクリプトが含まれています- script@1: title: Get Release Management Recipes inputs: - content: >- #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x # write your script here git clone https://github.com/bitrise-io/release-management-recipes -
iOS アップデートバンドルを生成し、そこから zip アーカイブを作成します。
- script@1: title: Generate iOS Update Bundle inputs: - content: >- #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x npx react-native bundle \ --platform ios \ --dev false \ --entry-file index.js \ --bundle-output ./build/main.jsbundle \ --assets-dest ./build # Create zip archive zip -r update.zip ./build -
次のコマンドを使用して、iOS アップデートバンドルをCodePush サーバーにアップロードします。
upload_code_push_package.sh:- script@1: title: Upload iOS Update Bundle to Codepush Server inputs: - content: > #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x cd release-management-recipes UPLOAD_RESPONSE=$(PACKAGE_PATH=../update.zip \ AUTHORIZATION_TOKEN=$BITRISE_API_TOKEN \ CONNECTED_APP_ID=$IOS_CONNECTED_APP_ID \ DEPLOYMENT_ID=$IOS_PROD_DEPLOYMENT_ID \ APP_VERSION=$APP_VERSION /bin/bash ./api/upload_code_push_package.sh 2>&1) EXIT_CODE=$? if [ $EXIT_CODE -ne 0 ]; then \ echo \"❌ upload_code_push_package.sh failed with exit code $EXIT_CODE\" \ echo \"$UPLOAD_RESPONSE\" \ exit $EXIT_CODE fi # Take only the last line of the response (final/latest status JSON object) FINAL_RESPONSE=$(echo "$UPLOAD_RESPONSE" | tail -n1) # Check explicitly for ERR_INTERNAL or other internal error indicators if echo \"$UPLOAD_RESPONSE\" | grep -q \"ERR_INTERNAL\"; then \ ERROR_MESSAGE=$(echo \"$FINAL_RESPONSE\" | jq -r '.message' || echo \"Unknown error\") \ echo \"❌ Server returned internal error: $ERROR_MESSAGE\" \ exit 1 fi # Now safely parse 'status' and 'status_reason' from the final response line PACKAGE_STATUS=$(echo "$FINAL_RESPONSE" | jq -r '.status' || echo "null") STATUS_REASON=$(echo "$FINAL_RESPONSE" | jq -r '.status_reason' || echo "") if [ "$PACKAGE_STATUS" = "processed_valid" ]; then echo "✅ Package uploaded and processed successfully." rm -rf ../build.zip rm -rf ../build else echo "⚠️ Package upload unexpected status: $PACKAGE_STATUS - Reason: $STATUS_REASON" exit 1 fi cd .. -
Android アップデートバンドルを生成します。
- script@1: title: Generate Android Update Bundle inputs: - content: | #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x npx react-native bundle \ --platform android \ --dev false \ --entry-file index.js \ --bundle-output ./build/index.android.bundle \ --assets-dest ./build # Create zip archive zip -r update.zip ./build -
Android アップデートバンドルを CodePush サーバーにアップロードします。
- script@1: title: Upload Android Update Bundle to Codepush Server inputs: - content: | #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x cd release-management-recipes UPLOAD_RESPONSE=$(PACKAGE_PATH=../update.zip \ AUTHORIZATION_TOKEN=$BITRISE_API_TOKEN \ CONNECTED_APP_ID=$ANDROID_CONNECTED_APP_ID \ DEPLOYMENT_ID=$ANDROID_PROD_DEPLOYMENT_ID \ APP_VERSION=$APP_VERSION /bin/bash ./api/upload_code_push_package.sh 2>&1) EXIT_CODE=$? if [ $EXIT_CODE -ne 0 ]; then echo "❌ upload_code_push_package.sh failed with exit code $EXIT_CODE" echo "$UPLOAD_RESPONSE" exit $EXIT_CODE fi # Take only the last line of the response (final/latest status JSON object) FINAL_RESPONSE=$(echo "$UPLOAD_RESPONSE" | tail -n1) # Check explicitly for ERR_INTERNAL or other internal error indicators if echo "$UPLOAD_RESPONSE" | grep -q "ERR_INTERNAL"; then ERROR_MESSAGE=$(echo "$FINAL_RESPONSE" | jq -r '.message' || echo "Unknown error") echo "❌ Server returned internal error: $ERROR_MESSAGE" exit 1 fi # Now safely parse 'status' and 'status_reason' from the final response line PACKAGE_STATUS=$(echo "$FINAL_RESPONSE" | jq -r '.status' || echo "null") STATUS_REASON=$(echo "$FINAL_RESPONSE" | jq -r '.status_reason' || echo "") if [ "$PACKAGE_STATUS" = "processed_valid" ]; then echo "✅ Package uploaded and processed successfully." else echo "⚠️ Package upload unexpected status: $PACKAGE_STATUS - Reason: $STATUS_REASON" exit 1 fi cd ..
-
ワークフローを作成し、その後
git-cloneステップ 1、追加npmステップウィズinstallコマンド:--- format_version: '13' default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: ios workflows: codepush_update_deploy: description: | Uploads Update Bundle to Bitrise CodePush Server status_report_name: Executing <target_id> for <project_title> steps: - git-clone@8: {} - restore-npm-cache@2: {} - npm@1: inputs: - command: install -
を追加
scriptを使用してアプリバージョンを抽出するステップawkそしてそれを環境変数として設定します:- script@1: title: Extract App Version inputs: - content: |- #!/bin/bash set -e # Simpler version using awk APP_VERSION=$(awk -F'"' '/version:/ {print $2}' app.config.js) # Check if the version was successfully extracted if [ -z "$APP_VERSION" ]; then echo "Error: Failed to extract version from app.config.js" exit 1 fi echo "Extracted version: $APP_VERSION" # Set the environment variable using envman envman add --key APP_VERSION --value "$APP_VERSION" echo "Successfully set APP_VERSION=$APP_VERSION" -
もう一つ追加
scriptのクローンを作成するステップrelease-management-recipesGitHub のリポジトリ。これには、後で使用するアップロードスクリプトが含まれています- script@1: title: Get Release Management Recipes inputs: - content: >- #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x # write your script here git clone https://github.com/bitrise-io/release-management-recipes -
iOS アップデートバンドルを生成し、そこから zip アーカイブを作成します。
- script@1: title: Generate iOS Update Bundle inputs: - content: |- #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x # write your script here npx expo export:embed \ --entry-file index.js \ --platform ios \ --dev false \ --reset-cache \ --bundle-output ./build/main.jsbundle \ --assets-dest ./build \ --minify false # Create zip archive zip -r update.zip ./build -
次のコマンドを使用して、iOS アップデートバンドルをCodePush サーバーにアップロードします。
upload_code_push_package.sh:- script@1: title: Upload iOS Update Bundle to Codepush Server inputs: - content: > #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x cd release-management-recipes UPLOAD_RESPONSE=$(PACKAGE_PATH=../update.zip \ AUTHORIZATION_TOKEN=$BITRISE_API_TOKEN \ CONNECTED_APP_ID=$IOS_CONNECTED_APP_ID \ DEPLOYMENT_ID=$IOS_PROD_DEPLOYMENT_ID \ APP_VERSION=$APP_VERSION /bin/bash ./api/upload_code_push_package.sh 2>&1) EXIT_CODE=$? if [ $EXIT_CODE -ne 0 ]; then \ echo \"❌ upload_code_push_package.sh failed with exit code $EXIT_CODE\" \ echo \"$UPLOAD_RESPONSE\" \ exit $EXIT_CODE fi # Take only the last line of the response (final/latest status JSON object) FINAL_RESPONSE=$(echo "$UPLOAD_RESPONSE" | tail -n1) # Check explicitly for ERR_INTERNAL or other internal error indicators if echo \"$UPLOAD_RESPONSE\" | grep -q \"ERR_INTERNAL\"; then \ ERROR_MESSAGE=$(echo \"$FINAL_RESPONSE\" | jq -r '.message' || echo \"Unknown error\") \ echo \"❌ Server returned internal error: $ERROR_MESSAGE\" \ exit 1 fi # Now safely parse 'status' and 'status_reason' from the final response line PACKAGE_STATUS=$(echo "$FINAL_RESPONSE" | jq -r '.status' || echo "null") STATUS_REASON=$(echo "$FINAL_RESPONSE" | jq -r '.status_reason' || echo "") if [ "$PACKAGE_STATUS" = "processed_valid" ]; then echo "✅ Package uploaded and processed successfully." rm -rf ../build.zip rm -rf ../build else echo "⚠️ Package upload unexpected status: $PACKAGE_STATUS - Reason: $STATUS_REASON" exit 1 fi cd .. -
Android アップデートバンドルを生成します。
- script@1: title: Generate Android Update Bundle inputs: - content: | #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x # write your script here npx expo export:embed \ --entry-file index.js \ --platform android \ --dev false \ --reset-cache \ --bundle-output ./build/index.android.bundle \ --assets-dest ./build \ --minify false # Create zip archive zip -r update.zip ./build -
Android アップデートバンドルを CodePush サーバーにアップロードします。
- script@1: title: Upload Android Update Bundle to Codepush Server inputs: - content: | #!/usr/bin/env bash # fail if any commands fails set -e # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully set -o pipefail # debug log set -x cd release-management-recipes UPLOAD_RESPONSE=$(PACKAGE_PATH=../update.zip \ AUTHORIZATION_TOKEN=$BITRISE_API_TOKEN \ CONNECTED_APP_ID=$ANDROID_CONNECTED_APP_ID \ DEPLOYMENT_ID=$ANDROID_PROD_DEPLOYMENT_ID \ APP_VERSION=$APP_VERSION /bin/bash ./api/upload_code_push_package.sh 2>&1) EXIT_CODE=$? if [ $EXIT_CODE -ne 0 ]; then echo "❌ upload_code_push_package.sh failed with exit code $EXIT_CODE" echo "$UPLOAD_RESPONSE" exit $EXIT_CODE fi # Take only the last line of the response (final/latest status JSON object) FINAL_RESPONSE=$(echo "$UPLOAD_RESPONSE" | tail -n1) # Check explicitly for ERR_INTERNAL or other internal error indicators if echo "$UPLOAD_RESPONSE" | grep -q "ERR_INTERNAL"; then ERROR_MESSAGE=$(echo "$FINAL_RESPONSE" | jq -r '.message' || echo "Unknown error") echo "❌ Server returned internal error: $ERROR_MESSAGE" exit 1 fi # Now safely parse 'status' and 'status_reason' from the final response line PACKAGE_STATUS=$(echo "$FINAL_RESPONSE" | jq -r '.status' || echo "null") STATUS_REASON=$(echo "$FINAL_RESPONSE" | jq -r '.status_reason' || echo "") if [ "$PACKAGE_STATUS" = "processed_valid" ]; then echo "✅ Package uploaded and processed successfully." else echo "⚠️ Package upload unexpected status: $PACKAGE_STATUS - Reason: $STATUS_REASON" exit 1 fi cd ..
CodePush アップデートリリースの自動化
CodePush 更新を生成してアップロードするワークフローを作成したら、次の 2 つの方法で実行できます。
-
ビルドの自動起動 定義した条件が満たされたとき。使用可能な条件については、を参照してください サポートされているトリガー条件。
プロセスを自動化するために、いくつかの異なるタイプのトリガーを設定できます。この設定例では、ラベルの付いたプルリクエストトリガーを使用しています。
この例では、次のようなトリガーを設定しています。
-
Bitriseは、で開かれたプルリクエストを検索します
updatesターゲットブランチとして。 -
ザ・
codepush_update_deployワークフローは、ブランチへのプルリクエストが以下を受け取ったときにトリガーされますrelease-updatePR へのラベル。
-
トリガーの作成: 2 つの条件でプルリクエストトリガーを設定します。
target_branchそしてlabel:-
セット
target_branchへupdates。 -
セット
labelにrelease-update。
GUI コンフィグ
これらはワークフローエディターの GUI でも設定できます。ここでは YAML 設定を示しています
format_version: "13" default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: react-native workflows: codepush_update_deploy: status_report_name: 'Executing <target_id> for <project_title>' description: | Uploads Update Bundle to Bitrise CodePush Server steps: [...] triggers: pull_request: - target_branch: updates label: release-update -
-
CodePush のアップデートをリリースしたい場合は、へのプルリクエストを開いてください
updatesブランチ。 -
PR がレビューされ承認されたら、以下を追加します
release-updateそれにラベルを付けます。
すべてがうまくいけば、PRにラベルを追加すると、 codepush_update_deploy ワークフロー。