> ## 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 和 Android 测试，iOS 使用 Mac mini，Android 使用 Linux 实例。

export const setupPrompt = `添加 Codemagic 工作流，在 iOS 和 Android 上运行此项目的 e2e 测试。文档：\`https://e2e.com/docs/ci/codemagic.md\` 和 \`https://e2e.com/docs/ci.md\`

1. 阅读这两个页面。
2. 将工作流添加到 \`codemagic.yaml\`。根据此项目调整项目路径、scheme 和 Node 版本。
3. 让我将模型密钥添加到 \`e2e\` 环境变量组，并标记为机密值。
4. 在我启动构建后，读取构建日志并修复错误，直到两个工作流都通过。`;

此配置遵循[移动端作业](https://e2e.com/docs/zh/ci#mobile-jobs)中的规则，在 Mac mini 实例上运行 iOS，在 Linux 实例上运行 Android，各使用一个工作流。

<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` 环境变量组，并标记为机密值。每个读取该组的构建都可以读取密钥，包括不受信任的拉取请求（PR）代码。仅为你信任的贡献者触发使用该组的拉取请求（PR）构建。参阅[模型凭据](https://e2e.com/docs/zh/ci#model-credentials)。

## 下一步

<CardGroup cols={2}>
  <Card title="持续集成" icon="rotate" href="/ci">
    CI 默认值、分片、重新运行和退出码。
  </Card>
  <Card title="托管设备" icon="cloud" href="/mobile#hosted-devices">
    从服务租用设备，让运行器无需启动设备。
  </Card>
</CardGroup>
