Debian Codegraph @

.github/workflows/coverage.yaml

raw
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 name: code coverage
16 on: [pull_request]
17
18 jobs:
19 build:
20 runs-on: ubuntu-latest
21 steps:
22 - name: Setup Go
23 uses: actions/setup-go@v3
24 with:
25 go-version: "1.21"
26
27 - name: Checkout base branch
28 uses: actions/checkout@v3
29 with:
30 ref: ${{ github.base_ref }}
31 - name: Calculate base code coverage
32 run: |
33 go test -short -coverprofile current_cover.out ./... || true
34 export CUR_COVER=$(go tool cover -func current_cover.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
35 echo "CUR_COVER=$CUR_COVER" >> $GITHUB_ENV
36
37 - name: Checkout PR branch
38 uses: actions/checkout@v3
39 - name: Calculate PR code coverage
40 run: |
41 go test -short -coverprofile pr_cover.out ./... || true
42 export PR_COVER=$(go tool cover -func pr_cover.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
43 echo "PR_COVER=$PR_COVER" >> $GITHUB_ENV
44
45 - name: Verify code coverage. If your reading this and the step has failed, please add tests to cover your changes.
46 run: |
47 go tool cover -func pr_cover.out
48 if [ "${{ env.PR_COVER }}" -lt "${{ env.CUR_COVER }}" ]; then
49 exit 1;
50 fi