diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 62c25ac35..9f12aa522 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -192,17 +192,140 @@ jobs: exit "$((codes[0] != 0 ? codes[0] : codes[1]))" } + # Summarize RunnerTests. + - name: Summarize RunnerTests + if: ${{ !cancelled() && (steps.simulator.outcome == 'success' || steps.simulator.outcome == 'failure') }} + shell: bash + env: + SIMULATOR_OUTCOME: ${{ steps.simulator.outcome }} + TEST_OUTCOME: ${{ steps.runner_tests.outcome }} + run: | + diagnostics="$RUNNER_TEMP/ios-test-diagnostics" + bundle="$diagnostics/RunnerTests.xcresult" + + { + printf '### RunnerTests\n\n' + printf -- '- Simulator setup: %s\n' "$SIMULATOR_OUTCOME" + printf -- '- Test result: %s' "$TEST_OUTCOME" + + if [[ -d "$bundle" ]] && summary="$(xcrun xcresulttool get test-results summary --path "$bundle" | jq -er ' + select(.totalTestCount > 0) + | " — \(.passedTests) passed, \(.failedTests) failed, \(.skippedTests) skipped" + ')"; then + printf '%s' "$summary" + fi + + printf '\n' + } | tee "$diagnostics/summary.md" >> "$GITHUB_STEP_SUMMARY" + + # Upload diagnostics if RunnerTests failed. + - name: Upload RunnerTests diagnostics + if: ${{ !cancelled() && (steps.simulator.outcome == 'failure' || steps.runner_tests.outcome == 'failure') }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: DPIP-iOS-RunnerTests-diagnostics + path: ${{ runner.temp }}/ios-test-diagnostics/ + retention-days: 7 + + - name: Build iOS App and create IPA + run: | + bash tool/dev/build.sh ios --debug + mkdir -p Payload + cp -R build/ios/iphoneos/Runner.app Payload/Runner.app + zip -qr DPIP.ipa Payload + + - name: Upload Artifacts + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: DPIP-iOS + path: | + build/ios/iphoneos/Runner.app + DPIP.ipa + retention-days: 7 + compression-level: 6 + + ios_widget_ui_tests: + needs: changes + if: ${{ needs.changes.outputs.ios == 'true' && needs.changes.outputs.release != 'true' }} + runs-on: macos-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Install toolchain (mise) + uses: jdx/mise-action@9b200bcecbfd6303e69a4a261b2e09e3757440a7 # v5.2.0 + + - name: Cache Swift Packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: | + ~/Library/Caches/org.swift.swiftpm + build/ios/SourcePackages + ~/Library/Developer/Xcode/DerivedData/**/SourcePackages + key: ${{ runner.os }}-spm-${{ hashFiles('ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved') }} + restore-keys: | + ${{ runner.os }}-spm- + + - name: Install dependencies and run build_runner + run: | + bash tool/dev/deps.sh + bash tool/dev/codegen.sh + + - name: Select and boot iPhone simulator + id: simulator + timeout-minutes: 5 + shell: bash + run: | + diagnostics="$RUNNER_TEMP/ios-test-diagnostics" + mkdir -p "$diagnostics" + + { + xcodebuild -version + sdk="$(xcrun --sdk iphonesimulator --show-sdk-version)" + xcrun simctl list devices available + + selected="$(xcrun simctl list --json | jq -er --arg sdk "$sdk" ' + . as $inventory + | [ .runtimes[] + | select(.isAvailable and (.platform == "iOS")) + | . as $runtime + | $inventory.devices[$runtime.identifier][]? + | select(.isAvailable and ((.deviceTypeIdentifier // "") | startswith("com.apple.CoreSimulator.SimDeviceType.iPhone-"))) + | { version: $runtime.version, name, udid, state } + ] + | sort_by([(.version == $sdk), (.version | split(".") | map(tonumber)), + (.name == "iPhone 17 Pro"), (.state == "Booted"), .name, .udid]) + | if length == 0 then error("No available iPhone simulator") else last end + | [.udid, .name, .version] | @tsv + ')" + + IFS=$'\t' read -r udid name version <<< "$selected" + printf 'Selected %s / iOS %s / %s (iOS SDK %s)\n' "$name" "$version" "$udid" "$sdk" + + boot_log="$RUNNER_TEMP/ios-simulator-bootstatus.log" + xcrun simctl bootstatus "$udid" -b 2>&1 | tee "$boot_log" + + if grep -Fq 'Data Migration Failed' "$boot_log"; then + echo '::error::Simulator data migration failed during startup.' + exit 1 + fi + + printf 'udid=%s\n' "$udid" >> "$GITHUB_OUTPUT" + } 2>&1 | tee "$diagnostics/simulator-startup.log" + - name: Test (ios/WidgetFixtureUITests) id: widget_ui_tests - # Run after RunnerTests even if it failed. The failed step remains a - # job failure; only the prerequisite setup and cancellation gate this step. - if: ${{ !cancelled() && steps.simulator.outcome == 'success' }} timeout-minutes: 30 shell: bash env: DPIP_IOS_SIMULATOR: ${{ steps.simulator.outputs.udid }} run: | diagnostics="$RUNNER_TEMP/ios-test-diagnostics" + bash tool/dev/test_widget_ui.sh \ -parallel-testing-enabled NO \ -derivedDataPath "$RUNNER_TEMP/WidgetFixtureUITests-DerivedData" \ @@ -213,71 +336,43 @@ jobs: exit "$((codes[0] != 0 ? codes[0] : codes[1]))" } - - name: Summarize iOS tests + - name: Summarize WidgetFixtureUITests if: ${{ !cancelled() && (steps.simulator.outcome == 'success' || steps.simulator.outcome == 'failure') }} shell: bash env: SIMULATOR_OUTCOME: ${{ steps.simulator.outcome }} - RUNNER_TESTS_OUTCOME: ${{ steps.runner_tests.outcome }} - WIDGET_UI_TESTS_OUTCOME: ${{ steps.widget_ui_tests.outcome }} + TEST_OUTCOME: ${{ steps.widget_ui_tests.outcome }} run: | diagnostics="$RUNNER_TEMP/ios-test-diagnostics" + bundle="$diagnostics/WidgetFixtureUITests.xcresult" + { - printf '### iOS test results\n\n- Simulator setup: %s\n' "$SIMULATOR_OUTCOME" - for suite in RunnerTests WidgetFixtureUITests; do - case "$suite" in - RunnerTests) outcome="$RUNNER_TESTS_OUTCOME" ;; - WidgetFixtureUITests) outcome="$WIDGET_UI_TESTS_OUTCOME" ;; - esac - printf -- '- %s: %s' "$suite" "$outcome" - bundle="$diagnostics/$suite.xcresult" - if [[ -d "$bundle" ]] && summary="$(xcrun xcresulttool get test-results summary --path "$bundle" | jq -er ' - select(.totalTestCount > 0) - | " — \(.passedTests) passed, \(.failedTests) failed, \(.skippedTests) skipped" - ')"; then - printf '%s' "$summary" - elif [[ "$outcome" == failure ]]; then - if [[ -d "$bundle" ]] && xcrun xcresulttool get build-results --path "$bundle" | - jq -e '(.errorCount // (.errors | length)) > 0' >/dev/null; then - printf ' — build errors recorded in xcresult' - else - printf ' — no test counts; check the log for build or test launch errors' - fi - fi - printf '\n' - done + printf '### WidgetFixtureUITests\n\n' + printf -- '- Simulator setup: %s\n' "$SIMULATOR_OUTCOME" + printf -- '- Test result: %s' "$TEST_OUTCOME" + + if [[ -d "$bundle" ]] && summary="$(xcrun xcresulttool get test-results summary --path "$bundle" | jq -er ' + select(.totalTestCount > 0) + | " — \(.passedTests) passed, \(.failedTests) failed, \(.skippedTests) skipped" + ')"; then + printf '%s' "$summary" + fi + + printf '\n' } | tee "$diagnostics/summary.md" >> "$GITHUB_STEP_SUMMARY" - # The full bundle retains XCTest diagnostics and attachments. Export - # any UI failure screenshots as well so they can be opened directly. - ui_bundle="$diagnostics/WidgetFixtureUITests.xcresult" - if [[ "$WIDGET_UI_TESTS_OUTCOME" == failure && -d "$ui_bundle" ]]; then + # Export screenshots from failed UI tests. + if [[ "$TEST_OUTCOME" == failure && -d "$bundle" ]]; then xcrun xcresulttool export attachments --only-failures --filter '*.png' \ - --path "$ui_bundle" --output-path "$diagnostics/WidgetFixtureUITests-attachments" || + --path "$bundle" \ + --output-path "$diagnostics/WidgetFixtureUITests-attachments" || echo '::warning::Could not export UI test screenshots; see the xcresult bundle.' fi - - name: Upload iOS test failure diagnostics - if: ${{ !cancelled() && (steps.simulator.outcome == 'failure' || steps.runner_tests.outcome == 'failure' || steps.widget_ui_tests.outcome == 'failure') }} + - name: Upload WidgetFixtureUITests diagnostics + if: ${{ !cancelled() && (steps.simulator.outcome == 'failure' || steps.widget_ui_tests.outcome == 'failure') }} uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - name: DPIP-iOS-test-diagnostics + name: DPIP-iOS-WidgetFixtureUITests-diagnostics path: ${{ runner.temp }}/ios-test-diagnostics/ retention-days: 7 - - - name: Build iOS App and create IPA - run: | - bash tool/dev/build.sh ios --debug - mkdir -p Payload - cp -R build/ios/iphoneos/Runner.app Payload/Runner.app - zip -qr DPIP.ipa Payload - - - name: Upload Artifacts - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: DPIP-iOS - path: | - build/ios/iphoneos/Runner.app - DPIP.ipa - retention-days: 7 - compression-level: 6 diff --git a/pr.md b/pr.md index 6c6769c17..43ec360c0 100644 --- a/pr.md +++ b/pr.md @@ -107,6 +107,7 @@ PR 不需要它,例如只改文件的 PR 不會 build App。 | `Android` | `android.yml` | 動到 `android/`、`assets/`、`lib/`、`pubspec.yaml` | 原生 Widget 單元測試、Android lint、Android 能 build | | `Instrumented` | `android.yml` | 只動到 `android/`、`android.yml` 或 `tool/dev/test_android_device.sh`,不受 release 決策影響 | 在 Android 35 模擬器驗證 Widget metadata、RemoteViews 與 SQLite | | `iOS` | `ios.yml` | 動到 `ios/`、`assets/`、`lib/`、`pubspec.yaml` | iOS 能 build | +| `ios_widget_ui_tests` | `ios.yml` | 與 `iOS` 相同 | 在 iPhone 模擬器驗證 Widget UI | | `code-review` | `review.yml` | 開 PR、推新 commit | 自動 code review 跑完;它留的意見要逐條回應 | | `codecov/project` | Codecov | `build` 上傳覆蓋率之後 | 總覆蓋率比 base 掉超過 1% 就失敗 | | `codecov/patch` | Codecov | 同上 | 新增與修改行的覆蓋率;只回報,不會失敗 |