[ios] Generate iOS code coverage for metrics (#14015)
This commit is contained in:
@@ -160,6 +160,7 @@
|
||||
"Effect": "Allow",
|
||||
"Resource": [
|
||||
"arn:aws:s3:::mapbox-loading-dock/raw/mobile.binarysize/*",
|
||||
"arn:aws:s3:::mapbox-loading-dock/raw/mobile.codecoverage/*"
|
||||
"arn:aws:s3:::mapbox-loading-dock/raw/mobile_staging.docs_coverage/*"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -929,6 +929,10 @@ jobs:
|
||||
- run:
|
||||
name: Build and run SDK unit tests with thread and undefined behavior sanitizers
|
||||
command: make ios-sanitize
|
||||
- run:
|
||||
name: Get iOS code coverage
|
||||
command: |
|
||||
platform/ios/scripts/ios-code-coverage.sh CI
|
||||
- save-dependencies
|
||||
- collect-xcode-build-logs
|
||||
- upload-xcode-build-logs
|
||||
|
||||
@@ -54,7 +54,18 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
codeCoverageEnabled = "YES"
|
||||
onlyGenerateCoverageForSpecifiedTargets = "YES"
|
||||
shouldUseLaunchSchemeArgsEnv = "NO">
|
||||
<CodeCoverageTargets>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "DA8847D11CBAF91600AB86E3"
|
||||
BuildableName = "Mapbox.framework"
|
||||
BlueprintName = "dynamic"
|
||||
ReferencedContainer = "container:ios.xcodeproj">
|
||||
</BuildableReference>
|
||||
</CodeCoverageTargets>
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
|
||||
31
platform/ios/scripts/ios-code-coverage.sh
Executable file
31
platform/ios/scripts/ios-code-coverage.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
#
|
||||
# Get code coverage report, then convert it to JSON.
|
||||
# The coverage reports end up in different locations based on whether coverage
|
||||
# is generated via CI or locally.
|
||||
#
|
||||
cov_result="";
|
||||
if [ -f build/ios/Logs/Test/*.xcresult/*_Test/*.xccovreport ]; then
|
||||
cov_result=build/ios/Logs/Test/*.xcresult/*_Test/*.xccovreport
|
||||
elif [ -f build/ios/ios/Logs/Test/*.xcresult/*_Test/*.xccovreport ]; then
|
||||
cov_result=build/ios/ios/Logs/Test/*.xcresult/*_Test/*.xccovreport
|
||||
else
|
||||
echo "Coverage file does not exist. Please run tests before executing"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
xcrun xccov view $cov_result --json > output.json
|
||||
|
||||
#
|
||||
# Convert the line coverage for the dynamic target to a percentage. Currently,
|
||||
# only CI tests are included when calculated code coverage.
|
||||
#
|
||||
percentage=`node -e "console.log(require('./output.json').lineCoverage)"`
|
||||
cov=$(printf "%.2f" $(echo "$percentage*100" | bc -l))
|
||||
|
||||
# Generate a formatted JSON file and upload it to S3.
|
||||
./././scripts/code-coverage.sh $cov "iOS" "$1"
|
||||
35
scripts/code-coverage.sh
Executable file
35
scripts/code-coverage.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
#
|
||||
# This script takes three values: $1 should be a decimal value reflecting the
|
||||
# percentage of lines covered, with a maximum value of 100.0, $2 is
|
||||
# the platform the percentage pertains to (iOS or Android), and $3 is the
|
||||
# test scheme being run (on iOS, this is currently CI).
|
||||
#
|
||||
|
||||
# Check that platform input values are valid.
|
||||
|
||||
if [[ ! $2 = "iOS" && ! $2 = "Android" ]]; then
|
||||
echo "$2 does not match either 'iOS' or 'Android'. Platform must be specified for coverage report."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a formatted JSON file that contains the current coverage.
|
||||
|
||||
current_date=$(TZ=UTC date +"%Y-%m-%d")
|
||||
file_name=$2_coverage.json
|
||||
cat <<EOF > $file_name
|
||||
{"code_coverage":$1,"platform":"$2","sdk":"Maps","scheme":"$3","created_at":"$current_date"}
|
||||
EOF
|
||||
gzip -f $file_name
|
||||
|
||||
if [ -z `which aws` ]; then
|
||||
brew install awscli
|
||||
fi
|
||||
|
||||
aws s3 cp $file_name.gz s3://mapbox-loading-dock/raw/mobile.codecoverage/$current_date/
|
||||
echo $
|
||||
|
||||
Reference in New Issue
Block a user