1+ # This script is provided by github.com/bool64/dev.
12name : test-unit
23on :
34 push :
89env :
910 GO111MODULE : " on"
1011 RUN_BASE_COVERAGE : " on" # Runs test for PR base in case base test coverage is missing.
12+ COV_GO_VERSION : 1.17.x # Version of Go to collect coverage
1113jobs :
1214 test :
1315 strategy :
1416 matrix :
15- go-version : [ 1.13 .x, 1.14 .x, 1.15.x, 1.16.x ]
17+ go-version : [ 1.16 .x, 1.17 .x, tip ]
1618 runs-on : ubuntu-latest
1719 steps :
18- - name : Install Go
20+ - name : Install Go stable
21+ if : matrix.go-version != 'tip'
1922 uses : actions/setup-go@v2
2023 with :
2124 go-version : ${{ matrix.go-version }}
25+ - name : Install Go tip
26+ if : matrix.go-version == 'tip'
27+ run : |
28+ curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
29+ ls -lah gotip.tar.gz
30+ mkdir -p ~/sdk/gotip
31+ tar -C ~/sdk/gotip -xzf gotip.tar.gz
32+ ~/sdk/gotip/bin/go version
33+ echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
2234 - name : Checkout code
2335 uses : actions/checkout@v2
2436 - name : Go cache
@@ -34,42 +46,43 @@ jobs:
3446 restore-keys : |
3547 ${{ runner.os }}-go-cache
3648 - name : Restore base test coverage
37- if : matrix.go-version == '1.16.x'
49+ id : base-coverage
50+ if : matrix.go-version == env.COV_GO_VERSION
3851 uses : actions/cache@v2
3952 with :
4053 path : |
4154 unit-base.txt
4255 # Use base sha for PR or new commit hash for master/main push in test result key.
4356 key : ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
4457 - name : Checkout base code
45- if : matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark- base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
58+ if : matrix.go-version == env.COV_GO_VERSION && env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage .outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
4659 uses : actions/checkout@v2
4760 with :
4861 ref : ${{ github.event.pull_request.base.sha }}
4962 path : __base
5063 - name : Run test for base code
51- if : matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark- base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
64+ if : matrix.go-version == env.COV_GO_VERSION && env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage .outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
5265 run : |
5366 cd __base
54- make test-unit
55- go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > ../unit-base.txt
67+ make | grep test-unit && (make test-unit && go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > ../unit-base.txt) || echo "No test-unit in base"
5668 - name : Test
5769 id : test
5870 run : |
5971 make test-unit
6072 go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > unit.txt
6173 OUTPUT=$(test -e unit-base.txt && (diff unit-base.txt unit.txt || exit 0) || cat unit.txt)
62- OUTPUT="${OUTPUT//'%'/'%25'}"
63- OUTPUT="${OUTPUT//$'\n'/'%0A'}"
64- OUTPUT="${OUTPUT//$'\r'/'%0D'}"
74+ echo "${OUTPUT}"
75+ OUTPUT="${OUTPUT//$'\n'/%0A}"
6576 TOTAL=$(grep 'total:' unit.txt)
77+ echo "${TOTAL}"
6678 echo "::set-output name=diff::$OUTPUT"
6779 echo "::set-output name=total::$TOTAL"
6880 - name : Store base coverage
6981 if : ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
7082 run : cp unit.txt unit-base.txt
7183 - name : Comment Test Coverage
72- if : matrix.go-version == '1.16.x'
84+ continue-on-error : true
85+ if : matrix.go-version == env.COV_GO_VERSION
7386 uses : marocchino/sticky-pull-request-comment@v2
7487 with :
7588 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
8598 </details>
8699
87100 - name : Upload code coverage
88- if : matrix.go-version == '1.16.x'
101+ if : matrix.go-version == env.COV_GO_VERSION
89102 uses : codecov/codecov-action@v1
90103 with :
91104 file : ./unit.coverprofile
0 commit comments