> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Codemagic

> Codemagic で iOS テストを Mac mini、Android テストを Linux インスタンスで実行します。

export const setupPrompt = `このプロジェクトの e2e テストを iOS と Android で実行する Codemagic ワークフローを追加してください。ドキュメント: \`https://e2e.com/docs/ci/codemagic.md\` と \`https://e2e.com/docs/ci.md\`

1. 両方のページを読んでください。
2. \`codemagic.yaml\` にワークフローを追加し、プロジェクトのパス、スキーム、Node のバージョンをこのプロジェクトに合わせてください。
3. \`e2e\` 環境変数グループにモデルのキーをシークレットとして追加するよう、私に依頼してください。
4. 私がビルドを開始したらログを読み、両方のワークフローが成功するまでエラーを修正してください。`;

この構成では、iOS を Mac mini インスタンス、Android を Linux インスタンスで、
それぞれ専用のワークフローで実行します。[モバイルのジョブ](https://e2e.com/docs/ja/ci#mobile-jobs) のルールに従います。

<SetupPrompt>

<Prompt description={setupPrompt} children={setupPrompt} actions={["copy", "cursor"]} />

</SetupPrompt>

## ワークフロー

Ubuntu イメージには `emulator`（API 34）、`emulator-35`、`emulator-36` という AVD があります。
Linux インスタンスには課金の有効化が必要です。
`test_report` は `junit.xml` をビルドの Tests タブに送ります。

```yaml title="codemagic.yaml" expandable
workflows:
  e2e-ios:
    name: e2e iOS
    instance_type: mac_mini_m2
    max_build_duration: 60
    environment:
      groups:
        - e2e
      node: 24
      xcode: latest
    triggering:
      events:
        - push
        - pull_request
    scripts:
      - name: Install dependencies
        script: npm ci
      - name: Install pods
        script: cd ios && pod install
      - name: Build for the simulator
        script: |
          xcodebuild -workspace ios/MyApp.xcworkspace -scheme MyApp \
            -configuration Release -sdk iphonesimulator \
            -destination 'generic/platform=iOS Simulator' \
            -derivedDataPath ios/build
      - name: Boot a simulator and install the app
        script: |
          UDID=$(xcrun simctl create e2e "iPhone 17" com.apple.CoreSimulator.SimRuntime.iOS-26-5)
          xcrun simctl bootstatus "$UDID" -b
          xcrun simctl install "$UDID" ios/build/Build/Products/Release-iphonesimulator/MyApp.app
      - name: Run e2e
        script: npx e2e run --target ios --reporter list,junit
        test_report: .e2e/junit.xml
    artifacts:
      - .e2e/report.json
      - .e2e/junit.xml
      - .e2e/results/**

  e2e-android:
    name: e2e Android
    instance_type: linux_x2
    max_build_duration: 60
    environment:
      groups:
        - e2e
      node: 24
    triggering:
      events:
        - push
        - pull_request
    scripts:
      - name: Install dependencies
        script: npm ci
      - name: Build the APK
        script: cd android && ./gradlew :app:assembleRelease
      - name: Boot the emulator and install the app
        script: |
          emulator -avd emulator-35 -no-window -no-audio -no-boot-anim > /dev/null 2>&1 &
          adb wait-for-device
          until [ "$(adb shell getprop sys.boot_completed | tr -d '\r')" = "1" ]; do sleep 2; done
          adb install -r android/app/build/outputs/apk/release/app-release.apk
      - name: Run e2e
        script: npx e2e run --target android --reporter list,junit
        test_report: .e2e/junit.xml
    artifacts:
      - .e2e/report.json
      - .e2e/junit.xml
      - .e2e/results/**
```

## モデルのキー

`e2e` 環境変数グループに、モデルのキーをシークレットとして保存します。
このグループを読み取るビルドは、信頼できないプルリクエストのコードも含め、キーにアクセスできます。
このグループを使うプルリクエストのビルドは、信頼できるコントリビューターに限定してください。
[モデルの認証情報](https://e2e.com/docs/ja/ci#model-credentials) を参照してください。

## 次のステップ

<CardGroup cols={2}>
  <Card title="継続的インテグレーション" icon="rotate" href="/ci">
    CI のデフォルト、シャーディング、再実行、終了コードを確認します。
  </Card>
  <Card title="ホスト型デバイス" icon="cloud" href="/mobile#hosted-devices">
    サービスからデバイスを借りれば、ランナー側でのデバイス起動は不要です。
  </Card>
</CardGroup>
