@@ -28,6 +28,8 @@ SCREENSHOT_DEVICES = [
2828MAIN_BUNDLE_IDENTIFIERS = %w[ com.automattic.woocommerce ] . freeze # Registered in our main account, for development and AppStore
2929ALPHA_BUNDLE_IDENTIFIERS = %w[ com.automattic.alpha.woocommerce ] . freeze # Registered in our Enterprise account, for App Center / Installable Builds
3030
31+ TEST_SCHEME = 'WooCommerce'
32+
3133# List of `.strings` files manually maintained by developers (as opposed to being automatically extracted from the code)
3234# which we will merge into the main `Localizable.strings` file imported by GlotPress, then extract back once we download the translations.
3335#
@@ -556,7 +558,7 @@ platform :ios do
556558 lane :build_for_testing do |options |
557559 run_tests (
558560 workspace : 'WooCommerce.xcworkspace' ,
559- scheme : 'WooCommerce' ,
561+ scheme : TEST_SCHEME ,
560562 derived_data_path : 'DerivedData' ,
561563 build_for_testing : true ,
562564 device : options [ :device ] ,
@@ -1042,11 +1044,15 @@ lane :test_without_building do |options|
10421044 e . include? ( options [ :name ] )
10431045 end . first
10441046
1045- UI . user_error! ( 'Unable to find .xctestrun file' ) unless !xctestrun_path . nil? && File . exist? ( ( xctestrun_path ) )
1047+ unless !xctestrun_path . nil? && File . exist? ( ( xctestrun_path ) )
1048+ UI . user_error! ( "Unable to find .xctestrun file at #{ xctestrun_path } " )
1049+ end
1050+
1051+ inject_buildkite_analytics_environment ( xctestrun_path : xctestrun_path ) if buildkite_ci?
10461052
10471053 run_tests (
10481054 workspace : 'WooCommerce.xcworkspace' ,
1049- scheme : 'WooCommerce' ,
1055+ scheme : TEST_SCHEME ,
10501056 device : options [ :device ] ,
10511057 deployment_target_version : options [ :ios_version ] ,
10521058 test_without_building : true ,
@@ -1101,3 +1107,37 @@ def trigger_buildkite_release_build(branch:, beta:)
11011107 pipeline_file : 'release-builds.yml'
11021108 )
11031109end
1110+
1111+ def inject_buildkite_analytics_environment ( xctestrun_path :)
1112+ require 'plist'
1113+
1114+ xctestrun = Plist . parse_xml ( xctestrun_path )
1115+ xctestrun [ 'TestConfigurations' ] . each do |configuration |
1116+ configuration [ 'TestTargets' ] . each do |target |
1117+ TEST_ANALYTICS_ENVIRONMENT . each do |key |
1118+ value = ENV . fetch ( key )
1119+ next if value . nil?
1120+
1121+ target [ 'EnvironmentVariables' ] [ key ] = value
1122+ end
1123+ end
1124+ end
1125+
1126+ File . write ( xctestrun_path , Plist ::Emit . dump ( xctestrun ) )
1127+ end
1128+
1129+ def buildkite_ci?
1130+ ENV . fetch ( 'BUILDKITE' , false )
1131+ end
1132+
1133+ # https://buildkite.com/docs/test-analytics/ci-environments
1134+ TEST_ANALYTICS_ENVIRONMENT = %w[
1135+ BUILDKITE_ANALYTICS_TOKEN
1136+ BUILDKITE_BUILD_ID
1137+ BUILDKITE_BUILD_NUMBER
1138+ BUILDKITE_JOB_ID
1139+ BUILDKITE_BRANCH
1140+ BUILDKITE_COMMIT
1141+ BUILDKITE_MESSAGE
1142+ BUILDKITE_BUILD_URL
1143+ ] . freeze
0 commit comments