diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9fa6f6a..d682b34 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 @@ -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%" @@ -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)}') diff --git a/README.md b/README.md index b6c90db..ae9ee85 100644 --- a/README.md +++ b/README.md @@ -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)