diff --git a/.github/workflows/build_and_test.sh b/.github/workflows/build_and_test.sh index ae5c2094d..55388efe1 100644 --- a/.github/workflows/build_and_test.sh +++ b/.github/workflows/build_and_test.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +coverage=$1 + # find all path that contains go.mod. for file in `find . -name go.mod`; do dirpath=$(dirname $file) @@ -54,10 +56,15 @@ for file in `find . -name go.mod`; do cd $dirpath go mod tidy go build ./... - go test ./... -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...,github.com/gogf/gf/... || exit 1 + # check coverage + if [ "${coverage}" = "coverage" ]; then + go test ./... -race -coverprofile=coverage.out -covermode=atomic -coverpkg=./...,github.com/gogf/gf/... || exit 1 - if grep -q "/gogf/gf/.*/v2" go.mod; then + if grep -q "/gogf/gf/.*/v2" go.mod; then sed -i "s/gogf\/gf\(\/.*\)\/v2/gogf\/gf\/v2\1/g" coverage.out + fi + else + go test ./... -race || exit 1 fi cd - diff --git a/.github/workflows/gf.yml b/.github/workflows/gf.yml index f0ed9f1e1..aab1a12bc 100644 --- a/.github/workflows/gf.yml +++ b/.github/workflows/gf.yml @@ -190,14 +190,18 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ matrix.go-version }} - cache: false - cache-dependency-path: '**/go.sum' + cache-dependency-path: '**/go.sum' - name: Before Script run: bash .github/workflows/before_script.sh - name: Build & Test - run: bash .github/workflows/build_and_test.sh + if: ${{ (github.event_name == 'push' && github.ref != 'refs/heads/master') || github.event_name == 'pull_request' }} + run: bash .github/workflows/build_and_test.sh + + - name: Build & Test & Coverage + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + run: bash .github/workflows/build_and_test.sh coverage - name: Stop Redis Cluster Containers run: docker-compose -f ".github/workflows/redis/docker-compose.yml" down @@ -213,6 +217,6 @@ jobs: - name: Report Coverage uses: codecov/codecov-action@v3 + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} with: flags: go-${{ matrix.go-version }}-${{ matrix.goarch }} -