Skip to content

Commit c9c60fc

Browse files
authored
Update go.yml
1 parent bd42db5 commit c9c60fc

1 file changed

Lines changed: 10 additions & 68 deletions

File tree

.github/workflows/go.yml

Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ jobs:
1717
matrix:
1818
go:
1919
- "1.21"
20+
- "stable"
2021
steps:
21-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2223

2324
- name: Set up Go
2425
uses: actions/setup-go@v5
@@ -39,73 +40,14 @@ jobs:
3940
- name: Go report card
4041
uses: creekorful/goreportcard-action@v1.0
4142

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

0 commit comments

Comments
 (0)