diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index 3ff55d3..bdd1d0e 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -23,4 +23,24 @@ jobs: - name: Run Unit Tests run: | ginkgo -r --randomize-all --randomize-suites --fail-on-pending --cover --trace --v --coverprofile=coverage.out ./... - go tool cover -html=coverage.out -o coverage-report.html \ No newline at end of file + - name: Upload Coverage Report to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: coverage.out + flag: unittests + - name: Generate Coverage Comment + id: generate-comment + run: | + COVERAGE_PERCENT=$(go tool cover -func=coverage.out | grep total | awk '{print $NF}') + COMMENT_MESSAGE="Code coverage: $COVERAGE_PERCENT%" + echo "::set-output name=comment::$COMMENT_MESSAGE" + - name: Comment on Pull Request + run: | + COMMENT_BODY="${{ steps.generate-comment.outputs.comment }}" + curl \ + -X POST \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d "{\"body\":\"$COMMENT_BODY\"}" \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ No newline at end of file diff --git a/README.md b/README.md index f9f5a98..2389620 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # go-commons + +[![codecov](https://codecov.io/github/cloud-bulldozer/go-commons/branch/main/graph/badge.svg?token=CFPW1UV7FO)](https://codecov.io/github/cloud-bulldozer/go-commons) \ No newline at end of file