Skip to content

Commit

Permalink
Add coverage report
Browse files Browse the repository at this point in the history
Signed-off-by: boot-go <[email protected]>
  • Loading branch information
boot-go committed Sep 1, 2023
1 parent 1b348b8 commit 0cc7400
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,44 @@ jobs:

- name: Test
run: go test -cpu 2 -timeout 2m -race -v ./...

- name: Test coverage
run: |
until go test -v -p 1 -covermode=count -coverprofile=coverage.out ./...; do
echo Test coverage failed, retrying in 3 seconds...
sleep 3
done
- name: Tool cover to func
run: go tool cover -func=coverage.out -o=cover.out

- name: Obtain coverage
run: echo "COVERAGE=$(grep -e 'total' cover.out | awk '{print $3;}')" >> $GITHUB_ENV

- name: Create coverage badge
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: c77b22000b3e249510dfb4542847c708
filename: test_coverage.json
label: "test coverage"
message: ${{ env.COVERAGE }}
valColorRange: ${{ env.COVERAGE }}
maxColorRange: 100
minColorRange: 0

- name: Tool cover to html
run: go tool cover -html=coverage.out -o=cover.html

- name: Obtain html coverage
run: echo "HTML_COVERAGE=$(cat cover.html)" >> $GITHUB_ENV

- name: Upload html coverage
uses: gorgbus/gist-actions@main
env:
GITHUB_TOKEN: ${{ secrets.GIST_SECRET }}
with:
action: "update"
gist_id: "c77b22000b3e249510dfb4542847c708"
file_name: "cover.html"
content: ${{ env.HTML_COVERAGE }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div align="center">
<a href="https://github.com/boot-go/boot/tags"><img alt="Commit tag" src="https://img.shields.io/github/v/tag/boot-go/boot"></a>
<a href="https://github.com/boot-go/boot/actions/workflows/action.yml"><img src="https://github.com/boot-go/boot/actions/workflows/action.yml/badge.svg?branch=main" alt="github action"></a>
<a href="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/schneegans/2ab8f1d386f13aaebccbd87dac94068d/raw/test_coverage.json"><img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/boot-go/c77b22000b3e249510dfb4542847c708/raw/test_coverage.json" alt="test coverage"></a>
<a href="https://goreportcard.com/report/github.com/boot-go/boot"><img src="https://goreportcard.com/badge/github.com/boot-go/boot" alt="go report"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
</div>
Expand Down

0 comments on commit 0cc7400

Please sign in to comment.