github.com/matrixorigin/matrixone@v0.7.0/.github/workflows/coverage_pr.yml (about) 1 name: PR Unit Test Coverage 2 on: 3 pull_request_target: 4 types: [ opened, synchronize ] 5 branches: [ main,'[0-9]+.[0-9]+.[0-9]+' ] 6 7 concurrency: 8 group: ${{ github.event.pull_request.head.repo.full_name}}/${{ github.event.pull_request.head.ref }}/${{ github.workflow }} 9 cancel-in-progress: true 10 11 jobs: 12 ut_coverage: 13 if: ${{ !github.event.pull_request.draft }} 14 name: PR Unit Test Coverage 15 runs-on: ubuntu-latest 16 17 steps: 18 - uses: actions/checkout@v3 19 with: 20 fetch-depth: '3' 21 path: ./matrixone 22 repository: ${{ github.event.pull_request.head.repo.full_name }} 23 ref: ${{ github.event.pull_request.head.ref }} 24 25 - name: Set Variables 26 run: | 27 cd $GITHUB_WORKSPACE/matrixone 28 echo "test_scope=$(go list ./... | grep -v 'driver\|engine/aoe\|engine/memEngine\|pkg/catalog' | xargs)" >> $GITHUB_ENV 29 echo "raw_ut_coverage='ut_coverage.raw'" >> $GITHUB_ENV 30 echo "raw_bvt_coverage='bvt_coverage.raw'" >> $GITHUB_ENV 31 echo "raw_bvt_coverage_temp='bvt_coverage_temp.raw'" >> $GITHUB_ENV 32 echo "raw_ut_coverage_temp='ut_coverage_temp.raw'" >> $GITHUB_ENV 33 echo "all_coervage='all_coverage.raw'" >> $GITHUB_ENV 34 echo "test_report='test_report.out'" >> $GITHUB_ENV 35 echo "coverage_line=75" >> $GITHUB_ENV 36 37 - name: Set up Go 38 uses: actions/setup-go@v3 39 with: 40 go-version: '1.20' 41 42 - name: Set env 43 run: | 44 echo "endpoint=${{ secrets.S3ENDPOINT }}" >> $GITHUB_ENV 45 echo "region=${{ secrets.S3REGION }}" >> $GITHUB_ENV 46 echo "apikey=${{ secrets.S3APIKEY }}" >> $GITHUB_ENV 47 echo "apisecret=${{ secrets.S3APISECRET }}" >> $GITHUB_ENV 48 echo "bucket=${{ secrets.S3BUCKET }}" >> $GITHUB_ENV 49 50 - name: Get Changed Paths 51 uses: guguducken/change-paths-action@v0.0.7 52 id: ut-pr 53 with: 54 github-token: ${{ secrets.TOKEN_ACTION }} 55 ignore: "/,etc/,optools/,LICENSES/,cgo/,cmd/,docs/,proto/,test/,.github/,pkg/pb/" 56 source-path: ${{ env.test_scope }} 57 58 - name: Start PR Unit Test 59 if: ${{ steps.ut-pr.outputs.paths != '' }} 60 timeout-minutes: 60 61 run: | 62 cd $GITHUB_WORKSPACE/matrixone 63 echo "-----------------------ut start-----------------------" 64 CGO_CFLAGS="-I${GITHUB_WORKSPACE}/matrixone/cgo" 65 CGO_LDFLAGS="-L${GITHUB_WORKSPACE}/matrixone/cgo -lmo -lm" 66 make clean && make config && make cgo 67 go test -v -cover -tags matrixone_test -p 1 -covermode=set -coverprofile ${{ env.raw_ut_coverage }} -count=1 ${{ steps.ut-pr.outputs.paths }} 68 echo "-----------------------ut finish-----------------------" 69 70 - name: Clone mo-tester repository 71 if: ${{ steps.ut-pr.outputs.paths != '' }} 72 uses: actions/checkout@v3 73 with: 74 repository: matrixorigin/mo-tester 75 path: ./mo-tester 76 ref: main 77 78 - name: Set up JDK 8 for x64 79 if: ${{ steps.ut-pr.outputs.paths != '' }} 80 uses: actions/setup-java@v3 81 with: 82 java-version: '8' 83 distribution: 'adopt' 84 architecture: x64 85 86 - name: Start Test Service 87 if: ${{ steps.ut-pr.outputs.paths != '' }} 88 timeout-minutes: 10 89 run: | 90 cd $GITHUB_WORKSPACE/matrixone 91 if [ -d "./store" ]; then rm -rf ./store; fi 92 GOLDFLAGS=-ldflags="-X 'main.GoVersion=$(go version)' -X 'main.BranchName=$(git rev-parse --abbrev-ref HEAD)' -X 'main.CommitID=$(git rev-parse HEAD)' -X 'main.BuildTime=$(date)' -X 'main.Version=$(git describe --always --tags $(git rev-list --tags --max-count=1))'" 93 export GOCOVERDIR=$GITHUB_WORKSPACE/matrixone 94 go build -cover "$GOLDFLAGS" -o mo-service ./cmd/mo-service/ 95 ./optools/run_bvt.sh $GITHUB_WORKSPACE/matrixone launch-tae-CN-tae-DN 96 97 - name: Start PR BVT Test 98 if: ${{ steps.ut-pr.outputs.paths != '' }} 99 id: bvt_on_pr_version 100 continue-on-error: true 101 run: | 102 cd $GITHUB_WORKSPACE/mo-tester 103 ./run.sh -n -g -p $GITHUB_WORKSPACE/matrixone/test/distributed/cases 2>&1 104 105 - name: Coverage Calculate 106 if: ${{ steps.ut-pr.outputs.paths != '' }} 107 run: | 108 cd $GITHUB_WORKSPACE/matrixone 109 echo "--------------------coverage start--------------------" 110 go tool covdata textfmt -i="$GITHUB_WORKSPACE/matrixone" -o ${{ env.raw_bvt_coverage }} 111 cat ${{ env.raw_bvt_coverage }} | grep "${{ steps.ut-pr.outputs.files }}" > ${{ env.raw_bvt_coverage_temp }} 112 cat ${{ env.raw_ut_coverage }} | grep "${{ steps.ut-pr.outputs.files }}" > ${{ env.raw_ut_coverage_temp }} 113 awk -F '[ ]+' 'FNR==NR{arr[$1,$2]=$3;next}{if(arr[$1,$2]==0 && $3>=1){arr[$1,$2]=1}}END{for(i in arr){split(i,ind,SUBSEP);printf("%s %s %s\n",ind[1],ind[2],arr[i])};}' ${{ env.raw_ut_coverage_temp }} ${{ env.raw_bvt_coverage_temp }} > ${{ env.all_coervage }} 114 awk -F '[:, ]+' '{all[$1]+=$4;hit[$1]+=0;if($5>0) hit[$1]+=$4;}END{for(i in all) print(i,all[i],hit[i],hit[i]/all[i]*100)}' ${{ env.all_coervage }} > ${{ env.test_report }} 115 awk 'BEGIN{flag=1}{if($4<${{ env.coverage_line }}){flag=0;print("error: the code coverage of "$1" is "$4"% which is below ${{ env.coverage_line }}%");} else { print("info: the code coverage of "$1" is "$4"% which is up to ${{ env.coverage_line }}%") }}END{if(flag==0) {exit 1;}}' ${{ env.test_report }} 116 rm -rf ${{ env.raw_ut_coverage }} ${{ env.test_report }} ${{ env.raw_bvt_coverage_temp }} ${{ env.raw_bvt_coverage }} ${{ env.all_coervage }} 117 echo "--------------------coverage finished--------------------"