Skip to content

Commit d65fa4b

Browse files
authored
Collect code coverage stats on Travis (#2913)
This currently only working for the main Firebase Example on iOS.
1 parent b10d454 commit d65fa4b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

scripts/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ case "$product-$method-$platform" in
188188
test
189189

190190
if [[ $platform == 'iOS' ]]; then
191+
# Code Coverage collection is only working on iOS currently.
192+
./scripts/collect_metrics.sh 'Example/Firebase.xcworkspace' "AllUnitTests_$platform"
193+
191194
# Run integration tests (not allowed on PRs)
192195
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
193196
RunXcodebuild \

scripts/collect_metrics.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2019 Google
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# USAGE: ./collect_metrics.sh workspace scheme
18+
#
19+
# Collects project health metrics and uploads them to a database. Currently just collects code
20+
# coverage for the provided workspace and scheme. Assumes that those tests have already been
21+
# executed.
22+
23+
set -euo pipefail
24+
25+
if [[ $# -ne 2 ]]; then
26+
cat 1>&2 <<EOF
27+
USAGE: $0 workspace scheme
28+
29+
Collects project health metrics and uploads them to a database. Currently just collects code
30+
coverage for the provided workspace and scheme. Assumes that those tests have already been
31+
executed.
32+
EOF
33+
exit 1
34+
fi
35+
36+
if [[ ! -z "${TRAVIS_PULL_REQUEST}" ]]; then
37+
WORKSPACE="$1"
38+
SCHEME="$2"
39+
40+
gem install xcov
41+
xcov --workspace "${WORKSPACE}" --scheme "${SCHEME}" --output_directory Metrics --json_report
42+
cd Metrics
43+
swift build
44+
.build/debug/Metrics -c report.json -p "${TRAVIS_PULL_REQUEST}"
45+
cd ..
46+
fi

0 commit comments

Comments
 (0)