From ce8ca37f587bcc9201e545d460896f388ec48919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Dejnek?= Date: Fri, 24 Oct 2025 20:03:35 +0200 Subject: [PATCH 1/4] feat: adds coverage badge workflow --- .github/workflows/go-coverage.yml | 49 +++++++++++++++++++++++++++++++ exitplan_test.go | 7 +++-- 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/go-coverage.yml diff --git a/.github/workflows/go-coverage.yml b/.github/workflows/go-coverage.yml new file mode 100644 index 0000000..a5a98b5 --- /dev/null +++ b/.github/workflows/go-coverage.yml @@ -0,0 +1,49 @@ +name: Coverage + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: 1.24 + cache: 'true' + + - name: Build + run: go install + + - name: Test + run: | + go test -v -cover ./... -coverprofile coverage.out -coverpkg ./... + go tool cover -func coverage.out -o coverage.out # Replaces coverage.out with the analysis of coverage.out + + - name: Go Coverage Badge + uses: tj-actions/coverage-badge-go@v3 + with: + green: 80 + filename: coverage.out + + - uses: stefanzweifel/git-auto-commit-action@v6 + id: auto-commit-action + with: + commit_message: Apply Code Coverage Badge + skip_fetch: true + skip_checkout: true + file_pattern: ./README.md + + - name: Push Changes + if: steps.auto-commit-action.outputs.changes_detected == 'true' + uses: ad-m/github-push-action@master + with: + github_token: ${{ github.token }} + branch: ${{ github.ref }} diff --git a/exitplan_test.go b/exitplan_test.go index ce63b09..5954cad 100644 --- a/exitplan_test.go +++ b/exitplan_test.go @@ -6,6 +6,7 @@ import ( "fmt" "slices" "sync" + "sync/atomic" "testing" "time" @@ -165,10 +166,10 @@ func TestOnExitTimeout(t *testing.T) { l := exitplan.New() - called := false + called := atomic.Bool{} l.OnExit(func() { time.Sleep(2 * timeout) - called = true + called.Store(true) }, exitplan.Timeout(timeout)) go func() { @@ -186,7 +187,7 @@ func TestOnExitTimeout(t *testing.T) { t.Errorf("expected timeout between %v and %v, got %v", timeout-timeoutJitter, timeout+timeoutJitter, end.Sub(start)) } - if called { + if called.Load() { t.Error("callback was called") } } From 08ae5bb362567044f4d43279c4991c151accb772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Dejnek?= Date: Fri, 24 Oct 2025 20:17:14 +0200 Subject: [PATCH 2/4] fix: coverage workflow --- .github/workflows/go-coverage.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/go-coverage.yml b/.github/workflows/go-coverage.yml index a5a98b5..5816484 100644 --- a/.github/workflows/go-coverage.yml +++ b/.github/workflows/go-coverage.yml @@ -12,6 +12,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 + with: + fetch-depth: '0' - name: Set up Go uses: actions/setup-go@v6 @@ -37,13 +39,4 @@ jobs: id: auto-commit-action with: commit_message: Apply Code Coverage Badge - skip_fetch: true - skip_checkout: true file_pattern: ./README.md - - - name: Push Changes - if: steps.auto-commit-action.outputs.changes_detected == 'true' - uses: ad-m/github-push-action@master - with: - github_token: ${{ github.token }} - branch: ${{ github.ref }} From 9a438ef150912a5ca3575637a95ae6934bd57c72 Mon Sep 17 00:00:00 2001 From: IAmRadek <91426891+IAmRadek@users.noreply.github.com> Date: Fri, 24 Oct 2025 18:17:53 +0000 Subject: [PATCH 3/4] Apply Code Coverage Badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index efea2a0..9a24191 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Exitplan +![Coverage](https://img.shields.io/badge/Coverage-83.2%25-brightgreen) A Go library for managing the lifecycle of an application with graceful shutdown capabilities. From fec1918fb1912cd78f64b8142778cc531c8b88ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Dejnek?= Date: Fri, 24 Oct 2025 20:21:38 +0200 Subject: [PATCH 4/4] chore: readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a24191..42c2626 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ # Exitplan +[![Go Reference](https://pkg.go.dev/badge/github.com/struct0x/exitplan.svg)](https://pkg.go.dev/github.com/struct0x/exitplan) ![Coverage](https://img.shields.io/badge/Coverage-83.2%25-brightgreen) A Go library for managing the lifecycle of an application with graceful shutdown capabilities. -[![Go Reference](https://pkg.go.dev/badge/github.com/struct0x/exitplan.svg)](https://pkg.go.dev/github.com/struct0x/exitplan) - ## Overview The Exitplan library provides a simple mechanism for managing the lifetime of an application.