From e20b69133c094a34942266d82d1bb352db3dd98c Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 25 Feb 2025 17:02:02 -0500 Subject: [PATCH] ci: run iOS tests in GitHub Actions (#791) * ci: run iOS tests in GitHub Actions * fix firebase configuration this changed after the first draft of this code * also upload failed results the way Fastlane provides them --- .github/actions/setup/action.yml | 23 +++++++++++++-- .github/workflows/ci.yaml | 48 ++++++++++++++++++++++++++++++++ .gitignore | 1 + fastlane/Fastfile | 15 ++++++++++ fastlane/README.md | 13 +++++++++ shared/build.gradle.kts | 8 ++++-- 6 files changed, 104 insertions(+), 4 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index fa0631434..e8e9676fd 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -27,6 +27,9 @@ runs: android-test) tools="java kotlin-cache rsvg" ;; + ios-test) + tools="java kotlin-cache ruby xcode" + ;; android-build) tools="java kotlin-cache rsvg ruby aws-secrets-android" ;; @@ -67,8 +70,8 @@ runs: if: steps.settings.outputs.kotlin-cache == 'true' with: path: ~/.konan - key: konan-${{ runner.os }}-${{ hashFiles('build.gradle.kts') }} - restore-keys: konan-${{ runner.os }} + key: konan-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('build.gradle.kts') }} + restore-keys: konan-${{ runner.os }}-${{ runner.arch }} - run: sudo apt-get install librsvg2-bin if: steps.settings.outputs.rsvg == 'true' shell: bash @@ -106,3 +109,19 @@ runs: if: steps.settings.outputs.ruby == 'true' run: bin/patch-fastlane.sh shell: bash + - name: Configure Xcode version + if: steps.settings.outputs.xcode == 'true' + shell: bash + run: | + sudo xcode-select --switch /Applications/Xcode_15.4.app/Contents/Developer + - name: Cache CocoaPods dependencies + if: steps.settings.outputs.xcode == 'true' + uses: actions/cache@v4 + with: + path: iosApp/Pods + key: cocoapods-${{ hashFiles('iosApp/Podfile.lock') }} + restore-keys: cocoapods- + - name: Install SwiftLint and xcbeautify + if: steps.settings.outputs.xcode == 'true' + shell: bash + run: brew install swiftlint xcbeautify diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 96f4e1e6e..b0788fad2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -51,6 +51,54 @@ jobs: with: name: android-android-reports path: androidApp/build/reports + test-ios: + name: Test for iOS + runs-on: macos-14-xlarge + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup + with: + for: ios-test + - name: Install CocoaPods dependencies + run: | + ./gradlew :shared:generateDummyFramework + pushd iosApp + bundle exec pod install + popd + bundle exec ./gradlew :shared:podInstallSyntheticIos + - name: shared checks & unit tests + run: ./gradlew shared:iosSimulatorArm64Test shared:iosX64Test + env: + GH_TOKEN: ${{ github.token }} + - uses: actions/upload-artifact@v4 + if: failure() + with: + name: ios-shared-reports + path: shared/build/reports + - name: Add build environment variables + run: | + { + echo "export SENTRY_DSN=${SENTRY_DSN}" + echo "export SENTRY_ENVIRONMENT=${SENTRY_ENVIRONMENT}" + echo "export FIREBASE_KEY=${FIREBASE_KEY}" + echo "export GOOGLE_APP_ID_IOS=${GOOGLE_APP_ID_IOS}" + } >> .envrc + env: + SENTRY_DSN: ${{ secrets.SENTRY_DSN }} + SENTRY_ENVIRONMENT: staging + FIREBASE_KEY: ${{ secrets.FIREBASE_KEY }} + GOOGLE_APP_ID_IOS: ${{ secrets.GOOGLE_APP_ID_IOS_STAGING }} + - name: Run emulator tests + run: | + bundle exec fastlane ios test \ + xcodebuild_formatter:"xcbeautify --renderer github-actions" + - uses: actions/upload-artifact@v4 + if: failure() + with: + name: ios-ios-results + path: fastlane/test_output/* emulator-test-android: name: Run Android instrumented tests in emulator runs-on: mobile_app_runner diff --git a/.gitignore b/.gitignore index c5dae7fe6..b173780f3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ xcuserdata .kotlin fastlane/report.xml +fastlane/test_output /iosApp/secrets/* /iosApp/Pods/* diff --git a/fastlane/Fastfile b/fastlane/Fastfile index f812a2ddd..2aebde4c2 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -79,3 +79,18 @@ platform :android do ) end end + +platform :ios do + desc "Run tests" + lane :test do |options| + run_tests( + workspace: "iosApp/iosApp.xcworkspace", + scheme: "Staging", + device: "iPhone 15 (17.5)", + testplan: "iosAppRetries", + output_directory: options[:output_directory], + xcodebuild_formatter: options[:xcodebuild_formatter], + number_of_retries: 3 + ) + end +end diff --git a/fastlane/README.md b/fastlane/README.md index b8c0a61a6..2486c38d6 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -33,6 +33,19 @@ Deploy a new version to Google Play for internal testing ---- + +## iOS + +### ios test + +```sh +[bundle exec] fastlane ios test +``` + +Run tests + +---- + This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run. More information about _fastlane_ can be found on [fastlane.tools](https://fastlane.tools). diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 1308e7981..8de4e86b0 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -140,13 +140,17 @@ if (DefaultNativePlatform.getCurrentOperatingSystem().isMacOsX) { tasks.getByName("compileKotlinIosSimulatorArm64").dependsOn("bomCodegenIos") } -if (System.getenv("CI_XCODE_CLOUD") != "TRUE") { +// don't run Android BOM codegen for iOS-only CI +if ( + !(System.getenv("CI")?.lowercase() == "true" && + DefaultNativePlatform.getCurrentOperatingSystem().isMacOsX) +) { tasks.getByName("preBuild").dependsOn("bomCodegenAndroid") } task("bomCodegenAndroid") { dependsOn("bomAndroid") - mustRunAfter("spotlessKotlin") + mustRunAfter("spotlessKotlin", "cyclonedxBom") inputPath = layout.buildDirectory.file("boms/bom-android.json") outputPath = layout.projectDirectory.file(