GitHub Actions から Autify for Mobile (iOS) テストを実行する方法を解説します。
前提
- Autify for Mobile(iOS) で Simulator テストを実行する
fastlane 設定
Autify へアップロードするために、*.app を生成します。
以下の fastlane を設定します。
Autify は x86_64 Simulator で実行されるため、arm64 ではなく x86_64 の *.app を生成するようにしています。
fastlane/Fastfile
lane :build_simulator do
gym(
scheme: "MyApp",
skip_package_ipa: true, # *.app を生成するため、*.ipa は不要
skip_codesigning: true # Simulator 実行のため署名不要
destination: "generic/platform=iOS Simulator",
xcargs: "ARCHS=x86_64" # Autify の x86_64 Simulator 向け
)
end
GitHub Actions Workflow
Workflow を以下のように設定します。
...
jobs:
autify:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
...
- name: Build
run: fastlane build_simulator
- name: Autify Upload & Run Test
env:
AUTIFY_UPLOAD_TOKEN: ${{ secrets.AUTIFY_UPLOAD_TOKEN }}
AUTIFY_TEST_PLAN_ID: {test plan id を設定}
AUTIFY_PROJECT_ID: {project id を設定}
run: |
export AUTIFY_APP_DIR_PATH=$(echo ~/Library/Developer/Xcode/Archives/*/*.xcarchive/Products/Applications/*.app)
# MyApp.app をアップロード
envman(){ :; } # autify_mobile_cli の envman エラーを無視
export -f envman
response=$(bash -c "$(curl -fsSL https://raw.githubusercontent.com/autifyhq/autify-for-mobile-cli/main/autify_mobile_cli.sh)")
result=$(echo $response | tail -n 1 | sed -E 's/^[^{]*({.*}).*$/\1/g') # workaround: API レスポンスだけを取得
build_id=$(echo $result | jq -r .id)
# テストの実行
response=$(curl -X POST \
-H "Authorization: Bearer $AUTIFY_UPLOAD_TOKEN" \
-H "Content-Type: application/json" \
--data "{\"build_id\":\"$build_id\"}" \
"https://mobile-app.autify.com/api/v1/test_plans/$AUTIFY_TEST_PLAN_ID/test_plan_results")
test_plan_result_id=$(echo "${response}" | jq -r .id)
echo "https://mobile-app.autify.com/projects/$AUTIFY_PROJECT_ID/results/$test_plan_result_id"
解説
Autify for Mobile のテスト実行には *.app
のアップロードが必要です。
Autify for Mobile CLI を使用します。
Autify for Mobile CLI への入力は以下の環境変数で設定します。
環境変数 | 値 |
---|---|
AUTIFY_UPLOAD_TOKEN | Autify Personal Access Token |
AUTIFY_PROJECT_ID | Autify Project ID |
AUTIFY_APP_DIR_PATH |
*.app ファイルのパス |
fastlane からビルドすると ~/Library/Developer/Xcode/Archives/2022-02-25/MyApp 2022-02-25 23.00.00.xcarchive/Products/Applications/MyApp.app
が生成されるため、これを AUTIFY_APP_DIR_PATH へ設定します。
Autify for Mobile CLI は Bitrise の envman
に依存してしまっているため、Github Actions Support の PR を提出しておきました。https://github.com/autifyhq/autify-for-mobile-cli/pull/5
テストの実行は Autify for Mobile API を使用します。
/api/v1/test_plans/{test_plan_id}/test_plan_results
API にアップロード結果の build_id を渡すとテストが実行されます。
Autify のテスト結果は https://mobile-app.autify.com/projects/$AUTIFY_PROJECT_ID/results/$test_plan_result_id
から参照できます。
余談
以下の GitHub リポジトリに Autify 公式の GitHub Actions 設定サンプルがあるようなのですが、現時点ではサンプルが未完成のようです...