Skip to content

Commit 713a889

Browse files
authored
feat: adds coverage badge workflow (#1)
* feat: adds coverage badge workflow
1 parent 17bd502 commit 713a889

3 files changed

Lines changed: 48 additions & 5 deletions

File tree

.github/workflows/go-coverage.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
with:
16+
fetch-depth: '0'
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v6
20+
with:
21+
go-version: 1.24
22+
cache: 'true'
23+
24+
- name: Build
25+
run: go install
26+
27+
- name: Test
28+
run: |
29+
go test -v -cover ./... -coverprofile coverage.out -coverpkg ./...
30+
go tool cover -func coverage.out -o coverage.out # Replaces coverage.out with the analysis of coverage.out
31+
32+
- name: Go Coverage Badge
33+
uses: tj-actions/coverage-badge-go@v3
34+
with:
35+
green: 80
36+
filename: coverage.out
37+
38+
- uses: stefanzweifel/git-auto-commit-action@v6
39+
id: auto-commit-action
40+
with:
41+
commit_message: Apply Code Coverage Badge
42+
file_pattern: ./README.md

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Exitplan
2+
[![Go Reference](https://pkg.go.dev/badge/github.com/struct0x/exitplan.svg)](https://pkg.go.dev/github.com/struct0x/exitplan)
3+
![Coverage](https://img.shields.io/badge/Coverage-83.2%25-brightgreen)
24

35
A Go library for managing the lifecycle of an application with graceful shutdown capabilities.
46

5-
[![Go Reference](https://pkg.go.dev/badge/github.com/struct0x/exitplan.svg)](https://pkg.go.dev/github.com/struct0x/exitplan)
6-
77
## Overview
88

99
The Exitplan library provides a simple mechanism for managing the lifetime of an application.

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)