Skip to content
Merged
39 changes: 32 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ jobs:
- module: v2
path: v2

defaults:
run:
working-directory: ${{ matrix.path }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up Go
uses: actions/setup-go@v4
Expand All @@ -141,12 +139,15 @@ jobs:
ubuntu-latest-go-1.24-

- name: Download dependencies
working-directory: ${{ matrix.path }}
run: go mod download

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

- name: Calculate coverage
working-directory: ${{ matrix.path }}
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
echo "Coverage: $COVERAGE%"
Expand All @@ -163,17 +164,41 @@ jobs:
fi

- name: Generate coverage report
working-directory: ${{ matrix.path }}
run: go tool cover -html=coverage.out -o coverage.html

- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
name: coverage-report-${{ matrix.module }}
path: |
coverage.out
coverage.html
${{ matrix.path }}/coverage.out
${{ matrix.path }}/coverage.html

- name: Go Coverage Badge # Pass the `coverage.out` output to this action
if: matrix.module == 'v2'
uses: tj-actions/coverage-badge-go@v2
with:
value: $COVERAGE

- name: Verify Changed files
if: matrix.module == 'v2'
uses: tj-actions/verify-changed-files@v16
id: verify-changed-files
with:
files: README.md

- name: Commit and push changes
if: matrix.module == 'v2' && steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "chore: Updated coverage badge."
git push

- name: Add coverage to PR comment
working-directory: ${{ matrix.path }}
if: github.event_name == 'pull_request'
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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