Skip to content

Commit 199ef50

Browse files
authored
Add coverage test workflow. (#7231)
This PR is a prerequisite for generating code coverage report. get_updated_files.sh will help get updated files to determine which sdk workflow to trigger. pod_test_code_coverage_report.sh will run pod tests and create xcresult bundles, with code coverage report, for SDKs The workflow test_coverage.yml will determine testing jobs to trigger and all xcresult bundles will be uploaded as artifacts on Github Actions. An upcoming PR will fetch these artifacts and combine coverage reports into a json file and then an API request will be sent with the json file to the Metrics Service, which will help generate a report.
1 parent f08f5be commit 199ef50

File tree

3 files changed

+163
-0
lines changed

3 files changed

+163
-0
lines changed

.github/workflows/test_coverage.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: test_coverage
2+
3+
on: [pull_request]
4+
#run specific jobs when specific files are updated.
5+
#https://github.community/t/how-to-execute-jobs-if-folder-updated-recursive/117344/5
6+
7+
jobs:
8+
check:
9+
name: Check changed files
10+
outputs:
11+
database_run_job: ${{ steps.check_files.outputs.database_run_job }}
12+
functions_run_job: ${{ steps.check_files.outputs.functions_run_job }}
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0
19+
- name: check files
20+
id: check_files
21+
env:
22+
pr_branch: ${{ github.event.pull_request.head.ref }}
23+
run: ./scripts/code_coverage_report/get_updated_files.sh
24+
pod-lib-lint-database:
25+
# Don't run on private repo unless it is a PR.
26+
needs: check
27+
if: github.repository == 'Firebase/firebase-ios-sdk' && needs.check.outputs.database_run_job == 'true'
28+
runs-on: macOS-latest
29+
30+
strategy:
31+
matrix:
32+
target: [ios, tvos, macos]
33+
steps:
34+
- uses: actions/checkout@v2
35+
- name: Setup Bundler
36+
run: scripts/setup_bundler.sh
37+
- name: Build and test
38+
env:
39+
SDK: database
40+
run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseDatabase "${{ matrix.target }}"
41+
- uses: actions/upload-artifact@v2
42+
with:
43+
name: database-codecoverage
44+
path: /Users/runner/*.xcresult
45+
46+
pod-lib-lint-functions:
47+
# Don't run on private repo unless it is a PR.
48+
needs: check
49+
if: github.repository == 'Firebase/firebase-ios-sdk' && needs.check.outputs.functions_run_job == 'true'
50+
runs-on: macOS-latest
51+
52+
strategy:
53+
matrix:
54+
target: [ios, tvos, macos]
55+
steps:
56+
- uses: actions/checkout@v2
57+
- name: Setup Bundler
58+
run: scripts/setup_bundler.sh
59+
- name: Build and test
60+
run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseFunctions "${{ matrix.target }}"
61+
- uses: actions/upload-artifact@v2
62+
with:
63+
name: functions-codecoverage
64+
path: /Users/runner/*.xcresult
65+
66+
create_report:
67+
needs: [pod-lib-lint-functions, pod-lib-lint-database]
68+
if: always()
69+
runs-on: macOS-latest
70+
steps:
71+
- uses: actions/download-artifact@v2
72+
id: download
73+
with:
74+
path: /Users/runner/test
75+
- name: display results
76+
run: |
77+
if [ -d "${{steps.download.outputs.download-path}}" ]; then
78+
find "/Users/runner/test" -print -regex ".*/.*\.xcresult" -exec xcrun xccov view --report {} \;
79+
fi
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
DATABASE_PATHS=("FirebaseDatabase.*" \
16+
".github/workflows/database\\.yml" \
17+
"Example/Database/" \
18+
"Interop/Auth/Public/\.\*.h")
19+
FUNCTIONS_PATHS=("Functions.*" \
20+
".github/workflows/functions\\.yml" \
21+
"Interop/Auth/Public/\.\*.h" \
22+
"FirebaseMessaging/Sources/Interop/\.\*.h")
23+
24+
# Set default flag variables which will determine if an sdk workflow will be triggererd.
25+
echo "::set-output name=database_run_job::false"
26+
echo "::set-output name=functions_run_job::false"
27+
28+
# Get most rescent ancestor commit.
29+
common_commit=$(git merge-base remotes/origin/${pr_branch} remotes/origin/master)
30+
echo "The common commit is ${common_commit}."
31+
32+
# List changed file from the base commit. This is generated by comparing the
33+
# head of the branch and the common commit from the master branch.
34+
echo "=============== list changed files ==============="
35+
cat < <(git diff --name-only $common_commit remotes/origin/${pr_branch})
36+
37+
echo "============= paths of changed files ============="
38+
git diff --name-only $common_commit remotes/origin/${pr_branch} > updated_files.txt
39+
40+
# Loop over updated files if their path match patterns then flags to trigger
41+
# SDK pod test workflow will be set to true.
42+
while IFS= read -r file
43+
do
44+
for path in "${DATABASE_PATHS[@]}"
45+
do
46+
if [[ "${file}" =~ $path ]]; then
47+
echo "This file is updated under the path, ${path}"
48+
echo "::set-output name=database_run_job::true"
49+
break
50+
fi
51+
done
52+
for path in "${FUNCTIONS_PATHS[@]}"
53+
do
54+
if [[ "${file}" =~ $path ]]; then
55+
echo "This file is updated under the path, ${path}"
56+
echo "::set-output name=functions_run_job::true"
57+
break
58+
fi
59+
done
60+
done < updated_files.txt
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
SDK="$1"
16+
platform="$2"
17+
default_output_path="/Users/runner/${SDK}-${platform}.xcresult"
18+
output_path="${3:-default_output_path}"
19+
if [ -d "/Users/runner/Library/Developer/Xcode/DerivedData" ]; then
20+
rm -r /Users/runner/Library/Developer/Xcode/DerivedData/*
21+
fi
22+
scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb "${SDK}".podspec --platforms="${platform}" --test-specs=unit
23+
find /Users/runner/Library/Developer/Xcode/DerivedData -type d -regex ".*/.*\.xcresult" -execdir cp -R '{}' "${output_path}" \;
24+

0 commit comments

Comments
 (0)