@@ -14,8 +14,10 @@ concurrency:
1414
1515env :
1616 GO111MODULE : " on"
17+ RUN_BASE_COVERAGE : " on" # Runs test for PR base in case base test coverage is missing.
1718 DOCKER_COMPOSE_FILE : ./docker-compose.yml
1819 GO_VERSION : 1.18.x
20+ TARGET_DELTA_COV : 90 # Target coverage of changed lines, in percents
1921jobs :
2022 test :
2123 runs-on : ubuntu-latest
3436 tar -C ~/sdk/gotip -xzf gotip.tar.gz
3537 ~/sdk/gotip/bin/go version
3638 echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
39+
3740 - name : Checkout code
3841 uses : actions/checkout@v2
42+
3943 - name : Go cache
4044 uses : actions/cache@v2
4145 with :
@@ -48,43 +52,84 @@ jobs:
4852 key : ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
4953 restore-keys : |
5054 ${{ 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
5171 - name : Docker Compose
5272 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+
5379 - name : Test
5480 id : test
5581 run : |
5682 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
5884 TOTAL=$(grep 'total:' integration.txt)
5985 echo "${TOTAL}"
6086 echo "::set-output name=total::$TOTAL"
87+
6188 - name : Annotate missing test coverage
6289 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 != ''
6491 run : |
6592 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} )
6895 echo "${REP}"
6996 REP="${REP//$'\n'/%0A}"
7097 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)
71102 echo "::set-output name=rep::$REP"
103+ echo "::set-output name=diff::$DIFF"
104+ echo "::set-output name=total::$TOTAL"
105+
72106 - name : Comment Test Coverage
73- if : matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
74107 continue-on-error : true
108+ if : github.event.pull_request.base.sha != ''
75109 uses : marocchino/sticky-pull-request-comment@v2
76110 with :
77111 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
78112 header : integration-test
79113 message : |
80114 ### Integration Test Coverage
81115 ${{ steps.test.outputs.total }}
116+ ${{ steps.annotate.outputs.total }}
82117 <details><summary>Coverage of changed lines</summary>
83118
84119 ${{ steps.annotate.outputs.rep }}
85120
86121 </details>
87122
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+
88133 - name : Upload code coverage
89134 uses : codecov/codecov-action@v1
90135 with :
0 commit comments