Skip to content

Commit 5f54f1a

Browse files
authored
Add badge through tj-actions/coverage-badge-go@v2 (#15)
1 parent f0123e1 commit 5f54f1a

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

.github/workflows/ci.yaml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,11 @@ jobs:
117117
- module: v2
118118
path: v2
119119

120-
defaults:
121-
run:
122-
working-directory: ${{ matrix.path }}
123-
124120
steps:
125121
- name: Checkout code
126122
uses: actions/checkout@v4
123+
with:
124+
ref: ${{ github.head_ref }}
127125

128126
- name: Set up Go
129127
uses: actions/setup-go@v4
@@ -141,12 +139,15 @@ jobs:
141139
ubuntu-latest-go-1.24-
142140
143141
- name: Download dependencies
142+
working-directory: ${{ matrix.path }}
144143
run: go mod download
145144

146145
- name: Run tests with coverage
146+
working-directory: ${{ matrix.path }}
147147
run: go test -coverprofile=coverage.out ./...
148148

149149
- name: Calculate coverage
150+
working-directory: ${{ matrix.path }}
150151
run: |
151152
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
152153
echo "Coverage: $COVERAGE%"
@@ -163,17 +164,41 @@ jobs:
163164
fi
164165
165166
- name: Generate coverage report
167+
working-directory: ${{ matrix.path }}
166168
run: go tool cover -html=coverage.out -o coverage.html
167169

168170
- name: Upload coverage report
169171
uses: actions/upload-artifact@v4
170172
with:
171-
name: coverage-report
173+
name: coverage-report-${{ matrix.module }}
172174
path: |
173-
coverage.out
174-
coverage.html
175+
${{ matrix.path }}/coverage.out
176+
${{ matrix.path }}/coverage.html
177+
178+
- name: Go Coverage Badge # Pass the `coverage.out` output to this action
179+
if: matrix.module == 'v2'
180+
uses: tj-actions/coverage-badge-go@v2
181+
with:
182+
value: $COVERAGE
183+
184+
- name: Verify Changed files
185+
if: matrix.module == 'v2'
186+
uses: tj-actions/verify-changed-files@v16
187+
id: verify-changed-files
188+
with:
189+
files: README.md
190+
191+
- name: Commit and push changes
192+
if: matrix.module == 'v2' && steps.verify-changed-files.outputs.files_changed == 'true'
193+
run: |
194+
git config --local user.email "action@github.com"
195+
git config --local user.name "GitHub Action"
196+
git add README.md
197+
git commit -m "chore: Updated coverage badge."
198+
git push
175199
176200
- name: Add coverage to PR comment
201+
working-directory: ${{ matrix.path }}
177202
if: github.event_name == 'pull_request'
178203
run: |
179204
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
44
[![CI](https://github.com/floatdrop/debounce/actions/workflows/ci.yaml/badge.svg)](https://github.com/floatdrop/debounce/actions/workflows/ci.yaml)
5+
![Coverage](https://img.shields.io/badge/Coverage-100.0-brightgreen)
56
[![Go Report Card](https://goreportcard.com/badge/github.com/floatdrop/debounce)](https://goreportcard.com/report/github.com/floatdrop/debounce)
67
[![Go Reference](https://pkg.go.dev/badge/github.com/floatdrop/debounce/v2.svg)](https://pkg.go.dev/github.com/floatdrop/debounce/v2)
78
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

0 commit comments

Comments
 (0)