Skip to content

Commit 1bc1819

Browse files
authored
Update build.yml
1 parent bab10c3 commit 1bc1819

1 file changed

Lines changed: 9 additions & 67 deletions

File tree

.github/workflows/build.yml

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -46,73 +46,15 @@ jobs:
4646
- name: Go report card
4747
uses: creekorful/goreportcard-action@v1.0
4848

49-
# Generate code coverage badge and push it to the 'coverage' branch.
50-
# Reference it in your README.md like this:
51-
#
52-
# [![coverage](https://github.com/USERNAME/REPO/blob/coverage/BRANCH/badge.svg)](#)
53-
#
54-
# If you have a detailed HTML report of the coverage (here called report.html), replace the '#' with:
55-
#
56-
# https://htmlpreview.github.io/?https://github.com/USERNAME/REPO/blob/coverage/BRANCH/report.html
57-
#
58-
# You need to have given write permissions for the for the workflow:
59-
#
60-
# permissions:
61-
# contents: write
62-
#
63-
# To create the 'coverage' branch for the repository (replace 'main' with the branch you want to publish for):
64-
#
65-
# git checkout main
66-
# git checkout --orphan coverage && git rm --cached $(git ls-files) && echo '# Coverage branch' > README.md
67-
# git add README.md && git commit -m 'Add README.md' && git push origin coverage
68-
# git checkout --force main
69-
- name: Extract branch name
70-
run: echo "BRANCH=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
71-
id: extract_branch
72-
- uses: actions/checkout@v3
73-
with:
74-
ref: coverage
75-
path: coverage
76-
- name: Ensure directories for this branch exist
77-
env:
78-
BRANCH: ${{ steps.extract_branch.outputs.branch }}
79-
run: mkdir -p coverage/${BRANCH}
80-
- name: Extract code coverage
49+
50+
- name: Calculate code coverage
8151
id: coverage
82-
env:
83-
BRANCH: ${{ steps.extract_branch.outputs.branch }}
84-
# Change this to extract the coverage percentage (without the percent sign) for your language into COVERAGE.
85-
# Here we are using a 'coverage.out' file generated by 'go test -coverprofile=coverage.out ./...'
86-
# You may also generate a HTML report and place at 'coverage/${BRANCH}/report.html'.
8752
run: |
88-
echo "COVERAGE=$(go tool cover -func=coverage.out | tail -n 1 | tr -s '\t' | cut -f 3 | rev | cut -c2- | rev)" >> $GITHUB_OUTPUT
89-
go tool cover -html=coverage.out -o=coverage/${BRANCH}/report.html
90-
- name: Generate the badge SVG image
91-
uses: emibcn/badge-action@v2.0.3
53+
echo "COVERAGE=$(go tool cover -func=coverage.out | tail -n 1 | tr -s '\t' | cut -f 3)" >> $GITHUB_OUTPUT
54+
go tool cover -html=coverage.out -o=coveragereport.html.out
55+
56+
- name: Publish code coverage badge (and optional report)
57+
uses: linkdata/gitcoverage@v1
9258
with:
93-
label: 'coverage'
94-
status: ${{ steps.coverage.outputs.coverage }}%
95-
path: coverage/${{ steps.extract_branch.outputs.branch }}/badge.svg
96-
color: ${{
97-
steps.coverage.outputs.coverage > 95 && 'green' ||
98-
steps.coverage.outputs.coverage > 90 && 'yellow,green,green' ||
99-
steps.coverage.outputs.coverage > 80 && 'yellow,green' ||
100-
steps.coverage.outputs.coverage > 70 && 'yellow' ||
101-
steps.coverage.outputs.coverage > 60 && 'orange,yellow' ||
102-
steps.coverage.outputs.coverage > 50 && 'orange' ||
103-
steps.coverage.outputs.coverage > 40 && 'red,orange' ||
104-
steps.coverage.outputs.coverage > 30 && 'red,red,orange' ||
105-
steps.coverage.outputs.coverage > 20 && 'red,red,red,orange' ||
106-
'red' }}
107-
- name: Commit coverage files
108-
env:
109-
BRANCH: ${{ steps.extract_branch.outputs.branch }}
110-
run: |
111-
pushd coverage
112-
git config --local user.email "action@github.com"
113-
git config --local user.name "GitHub Action"
114-
test ! -f "${BRANCH}/badge.svg" || git add "${BRANCH}/badge.svg"
115-
test ! -f "${BRANCH}/report.html" || git add "${BRANCH}/report.html"
116-
test -z "$(git status --porcelain)" || git commit -m "update"
117-
git push
118-
popd
59+
coverage: ${{ steps.coverage.outputs.coverage }}
60+
report: "coveragereport.html.out"

0 commit comments

Comments
 (0)