Skip to content

Commit 8c0c3f6

Browse files
authored
Add test coverage check workflow (GoogleCloudPlatform#306)
* Add test coverage check workflow
1 parent 2a3a4ad commit 8c0c3f6

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

.github/workflows/chat-notification.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ on:
1616
push:
1717
branches:
1818
- master
19-
pull_request:
2019
name: notification
2120
jobs:
2221
notify:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2022 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+
on:
16+
push:
17+
branches:
18+
- master
19+
pull_request:
20+
name: code-coverage-check
21+
jobs:
22+
coverage:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: actions/setup-go@v2
27+
with:
28+
go-version: '1.16'
29+
30+
- name: Unit tests
31+
run: |
32+
go test ./... -coverprofile coverage.out -covermode count
33+
go tool cover -func coverage.out
34+
35+
- name: Quality Gate - Test coverage should be above threshold
36+
env:
37+
TESTCOVERAGE_THRESHOLD: 50
38+
run: |
39+
echo "Quality Gate: checking if test coverage is above threshold ..."
40+
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
41+
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
42+
echo "Current test coverage : $totalCoverage %"
43+
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
44+
echo "OK"
45+
else
46+
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
47+
echo "Failed"
48+
exit 1
49+
fi

0 commit comments

Comments
 (0)