From b0a7d05a8cb3d8a7ddad9200c2f301849ecddca3 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 10 Feb 2023 16:52:15 +0200 Subject: [PATCH] BrowserStack support (#561) * BrowserStack support * Add fastlane step to automatically upload builds to BrowserStack * Add error log for when Application Groups are not available * Use better applicationSupportDirectory API --- .github/workflows/pr-build.yml | 2 ++ ElementX/Sources/Other/Extensions/URL.swift | 8 +++++++- Gemfile.lock | 3 +++ fastlane/Fastfile | 17 +++++++++++++++++ fastlane/Pluginfile | 1 + 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 42e073d82..89c2e4f3c 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -56,6 +56,8 @@ jobs: APPSTORECONNECT_KEY_CONTENT: ${{ secrets.APPSTORECONNECT_KEY_CONTENT }} DIAWI_API_TOKEN: ${{ secrets.DIAWI_API_TOKEN }} GITHUB_PR_NUMBER: ${{ github.event.number }} + BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} + BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} - name: Add release notes and Diawi info uses: NejcZdovc/comment-pr@v1 diff --git a/ElementX/Sources/Other/Extensions/URL.swift b/ElementX/Sources/Other/Extensions/URL.swift index 9c5583840..3c2908e9a 100644 --- a/ElementX/Sources/Other/Extensions/URL.swift +++ b/ElementX/Sources/Other/Extensions/URL.swift @@ -28,8 +28,14 @@ extension URL { /// The URL of the primary app group container. static var appGroupContainerDirectory: URL { guard let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: InfoPlistReader.main.appGroupIdentifier) else { - fatalError("Should always be able to retrieve the container directory") + MXLog.error("Application Group unavailable, falling back to the application folder") + // Browserstack doesn't properly handle AppGroup entitlements so this fails, presumably because of the resigning happening on their side + // Try using the normal app folder instead of the app group + // https://www.browserstack.com/docs/app-automate/appium/troubleshooting/entitlements-error + + return URL.applicationSupportDirectory.deletingLastPathComponent().deletingLastPathComponent() } + return url } diff --git a/Gemfile.lock b/Gemfile.lock index e417ca7ef..79077278d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,6 +113,8 @@ GEM xcpretty (~> 0.3.0) xcpretty-travis-formatter (>= 0.0.3) fastlane-plugin-brew (0.1.1) + fastlane-plugin-browserstack (0.3.2) + rest-client (~> 2.0, >= 2.0.2) fastlane-plugin-diawi (2.1.0) rest-client (>= 2.0.0) fastlane-plugin-sentry (1.15.0) @@ -254,6 +256,7 @@ PLATFORMS DEPENDENCIES fastlane + fastlane-plugin-browserstack fastlane-plugin-diawi fastlane-plugin-sentry fastlane-plugin-xcodegen diff --git a/fastlane/Fastfile b/fastlane/Fastfile index e90292b27..5f8e2c4f3 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -69,6 +69,8 @@ lane :alpha do ) upload_to_diawi() + + upload_to_browserstack() end lane :app_store_release do @@ -279,6 +281,21 @@ private_lane :upload_to_diawi do sh("echo DIAWI_QR_CODE_LINK=#{diawi_qr_code_link} >> $GITHUB_ENV") end +private_lane :upload_to_browserstack do + browserstack_username = ENV["BROWSERSTACK_USERNAME"] + UI.user_error!("Invalid BrowserStack username.") unless !browserstack_username.to_s.empty? + + browserstack_access_key = ENV["BROWSERSTACK_ACCESS_KEY"] + UI.user_error!("Invalid BrowserStack access key.") unless !browserstack_access_key.to_s.empty? + + upload_to_browserstack_app_automate( + browserstack_username: browserstack_username, + browserstack_access_key: browserstack_access_key, + file_path: lane_context[SharedValues::IPA_OUTPUT_PATH], + custom_id: "element-x-ios-pr" + ) +end + private_lane :bump_build_number do # Increment build number to current date build_number = Time.now.strftime("%Y%m%d%H%M") diff --git a/fastlane/Pluginfile b/fastlane/Pluginfile index 97b325ebf..b5c4d80b7 100644 --- a/fastlane/Pluginfile +++ b/fastlane/Pluginfile @@ -5,3 +5,4 @@ gem 'fastlane-plugin-diawi' gem 'fastlane-plugin-xcodegen' gem 'fastlane-plugin-sentry' +gem 'fastlane-plugin-browserstack'