Skip to content

Commit 3faab35

Browse files
committed
Add method to inject Test Analytics env value in xctestrun in Fastlane
1 parent c843473 commit 3faab35

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ Metrics/BlockLength:
22
Exclude:
33
- fastlane/Fastfile
44

5+
Metrics/MethodLength:
6+
Max: 20
7+
58
Style/AsciiComments:
69
Exclude:
710
- fastlane/Fastfile

fastlane/Fastfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,3 +1105,37 @@ def trigger_buildkite_release_build(branch:, beta:)
11051105
pipeline_file: 'release-builds.yml'
11061106
)
11071107
end
1108+
1109+
def inject_buildkite_analytics_environment(xctestrun_path:)
1110+
require 'plist'
1111+
1112+
xctestrun = Plist.parse_xml(xctestrun_path)
1113+
xctestrun['TestConfigurations'].each do |configuration|
1114+
configuration['TestTargets'].each do |target|
1115+
TEST_ANALYTICS_ENVIRONMENT.each do |key|
1116+
value = ENV.fetch(key)
1117+
next if value.nil?
1118+
1119+
target['EnvironmentVariables'][key] = value
1120+
end
1121+
end
1122+
end
1123+
1124+
File.write(xctestrun_path, Plist::Emit.dump(xctestrun))
1125+
end
1126+
1127+
def buildkite_ci?
1128+
ENV.fetch('BUILDKITE', false)
1129+
end
1130+
1131+
# https://buildkite.com/docs/test-analytics/ci-environments
1132+
TEST_ANALYTICS_ENVIRONMENT = %w[
1133+
BUILDKITE_ANALYTICS_TOKEN
1134+
BUILDKITE_BUILD_ID
1135+
BUILDKITE_BUILD_NUMBER
1136+
BUILDKITE_JOB_ID
1137+
BUILDKITE_BRANCH
1138+
BUILDKITE_COMMIT
1139+
BUILDKITE_MESSAGE
1140+
BUILDKITE_BUILD_URL
1141+
].freeze

0 commit comments

Comments
 (0)