Skip to content

Commit ce8ca37

Browse files
committed
feat: adds coverage badge workflow
1 parent 17bd502 commit ce8ca37

2 files changed

Lines changed: 53 additions & 3 deletions

File tree

.github/workflows/go-coverage.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
coverage:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v5
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v6
18+
with:
19+
go-version: 1.24
20+
cache: 'true'
21+
22+
- name: Build
23+
run: go install
24+
25+
- name: Test
26+
run: |
27+
go test -v -cover ./... -coverprofile coverage.out -coverpkg ./...
28+
go tool cover -func coverage.out -o coverage.out # Replaces coverage.out with the analysis of coverage.out
29+
30+
- name: Go Coverage Badge
31+
uses: tj-actions/coverage-badge-go@v3
32+
with:
33+
green: 80
34+
filename: coverage.out
35+
36+
- uses: stefanzweifel/git-auto-commit-action@v6
37+
id: auto-commit-action
38+
with:
39+
commit_message: Apply Code Coverage Badge
40+
skip_fetch: true
41+
skip_checkout: true
42+
file_pattern: ./README.md
43+
44+
- name: Push Changes
45+
if: steps.auto-commit-action.outputs.changes_detected == 'true'
46+
uses: ad-m/github-push-action@master
47+
with:
48+
github_token: ${{ github.token }}
49+
branch: ${{ github.ref }}

exitplan_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"slices"
88
"sync"
9+
"sync/atomic"
910
"testing"
1011
"time"
1112

@@ -165,10 +166,10 @@ func TestOnExitTimeout(t *testing.T) {
165166

166167
l := exitplan.New()
167168

168-
called := false
169+
called := atomic.Bool{}
169170
l.OnExit(func() {
170171
time.Sleep(2 * timeout)
171-
called = true
172+
called.Store(true)
172173
}, exitplan.Timeout(timeout))
173174

174175
go func() {
@@ -186,7 +187,7 @@ func TestOnExitTimeout(t *testing.T) {
186187
t.Errorf("expected timeout between %v and %v, got %v", timeout-timeoutJitter, timeout+timeoutJitter, end.Sub(start))
187188
}
188189

189-
if called {
190+
if called.Load() {
190191
t.Error("callback was called")
191192
}
192193
}

0 commit comments

Comments
 (0)