@@ -14,8 +14,10 @@ concurrency:
14
14
15
15
env :
16
16
GO111MODULE : " on"
17
+ RUN_BASE_COVERAGE : " on" # Runs test for PR base in case base test coverage is missing.
17
18
DOCKER_COMPOSE_FILE : ./docker-compose.yml
18
19
GO_VERSION : 1.18.x
20
+ TARGET_DELTA_COV : 90 # Target coverage of changed lines, in percents
19
21
jobs :
20
22
test :
21
23
runs-on : ubuntu-latest
34
36
tar -C ~/sdk/gotip -xzf gotip.tar.gz
35
37
~/sdk/gotip/bin/go version
36
38
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
39
+
37
40
- name : Checkout code
38
41
uses : actions/checkout@v2
42
+
39
43
- name : Go cache
40
44
uses : actions/cache@v2
41
45
with :
@@ -48,43 +52,84 @@ jobs:
48
52
key : ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
49
53
restore-keys : |
50
54
${{ runner.os }}-go-cache
55
+
56
+ - name : Restore base test coverage
57
+ id : base-coverage
58
+ uses : actions/cache@v2
59
+ with :
60
+ path : |
61
+ integration-base.txt
62
+ # Use base sha for PR or new commit hash for master/main push in test result key.
63
+ key : ${{ runner.os }}-integration-test-base-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
64
+
65
+ - name : Checkout base code
66
+ if : env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
67
+ uses : actions/checkout@v2
68
+ with :
69
+ ref : ${{ github.event.pull_request.base.sha }}
70
+ path : __base
51
71
- name : Docker Compose
52
72
run : (test -f ${{ env.DOCKER_COMPOSE_FILE }} && docker-compose -f ${{ env.DOCKER_COMPOSE_FILE }} up -d && docker ps && docker-compose -f ${{ env.DOCKER_COMPOSE_FILE }} logs) || echo "::warning ::Missing ${{ env.DOCKER_COMPOSE_FILE }} file"
73
+ - name : Run test for base code
74
+ if : env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
75
+ run : |
76
+ cd __base
77
+ make | grep test-integration && (make test-integration && go tool cover -func=./integration.coverprofile > ../integration-base.txt) || echo "No test-integration in base"
78
+
53
79
- name : Test
54
80
id : test
55
81
run : |
56
82
make test-integration
57
- go tool cover -func=./integration.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > integration.txt
83
+ go tool cover -func=./integration.coverprofile > integration.txt
58
84
TOTAL=$(grep 'total:' integration.txt)
59
85
echo "${TOTAL}"
60
86
echo "::set-output name=total::$TOTAL"
87
+
61
88
- name : Annotate missing test coverage
62
89
id : annotate
63
- if : matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
90
+ if : github.event.pull_request.base.sha != ''
64
91
run : |
65
92
git fetch origin master ${{ github.event.pull_request.base.sha }}
66
- curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.0.0 /linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && echo "6b8bec07488b84e46c1b8993353323effe863493013309fd3df4f2cba9a2bb29 gocovdiff" | shasum -c
67
- REP=$(./gocovdiff -cov unit .coverprofile -gha-annotations gha-integration.txt)
93
+ curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.3.2 /linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && echo "78146b31ec37ac8037a25d33b0f3c70c85adb0f8b682441b04b3daa518eaa489 gocovdiff" | shasum -c
94
+ REP=$(./gocovdiff -cov integration .coverprofile -gha-annotations gha-integration.txt -delta-cov-file delta-cov-integration.txt -target-delta-cov ${TARGET_DELTA_COV} )
68
95
echo "${REP}"
69
96
REP="${REP//$'\n'/%0A}"
70
97
cat gha-integration.txt
98
+ test -e integration-base.txt && cat integration-base.txt
99
+ DIFF=$(test -e integration-base.txt && ./gocovdiff -func-cov integration.txt -func-base-cov integration-base.txt || echo "Missing base coverage file")
100
+ DIFF="${DIFF//$'\n'/%0A}"
101
+ TOTAL=$(cat delta-cov-integration.txt)
71
102
echo "::set-output name=rep::$REP"
103
+ echo "::set-output name=diff::$DIFF"
104
+ echo "::set-output name=total::$TOTAL"
105
+
72
106
- name : Comment Test Coverage
73
- if : matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
74
107
continue-on-error : true
108
+ if : github.event.pull_request.base.sha != ''
75
109
uses : marocchino/sticky-pull-request-comment@v2
76
110
with :
77
111
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
78
112
header : integration-test
79
113
message : |
80
114
### Integration Test Coverage
81
115
${{ steps.test.outputs.total }}
116
+ ${{ steps.annotate.outputs.total }}
82
117
<details><summary>Coverage of changed lines</summary>
83
118
84
119
${{ steps.annotate.outputs.rep }}
85
120
86
121
</details>
87
122
123
+ <details><summary>Coverage diff with base branch</summary>
124
+
125
+ ${{ steps.annotate.outputs.diff }}
126
+
127
+ </details>
128
+
129
+ - name : Store base coverage
130
+ if : ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
131
+ run : cp integration.txt integration-base.txt
132
+
88
133
- name : Upload code coverage
89
134
uses : codecov/codecov-action@v1
90
135
with :
0 commit comments