From 56788b3234632f3cb7e8e10a7da5ad649b50ece7 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 22 Nov 2022 18:45:00 -0700 Subject: [PATCH 1/3] chore: add support for coverage reporting --- .github/workflows/code-coverage.yml | 58 +++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/code-coverage.yml diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 00000000..38c49b69 --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,58 @@ +on: + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + name: Update coverage badge + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + + - name: Setup go + uses: actions/setup-go@v2 + with: + go-version: '1.14.4' + + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Run Test + run: | + go test -v ./... -covermode=count -coverprofile=coverage.out + go tool cover -func=coverage.out -o=coverage.out + + - name: Go Coverage Badge # Pass the `coverage.out` output to this action + uses: tj-actions/coverage-badge-go@v2 + with: + filename: coverage.out + + - name: Verify Changed files + uses: tj-actions/verify-changed-files@v12 + id: verify-changed-files + with: + files: README.md + + - name: Commit changes + if: 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." + + - name: Push changes + if: steps.verify-changed-files.outputs.files_changed == 'true' + uses: ad-m/github-push-action@master + with: + github_token: ${{ github.token }} + branch: ${{ github.head_ref }} From 566e963ef33fccf7fd4e2515fadd73cb15576549 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 23 Nov 2022 01:45:36 +0000 Subject: [PATCH 2/3] chore: Updated coverage badge. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d3dd7ea4..0217b09c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/bb5dc10c1d2645c0894fa6774300639b)](https://app.codacy.com/gh/tj-actions/auto-doc?utm_source=github.com\&utm_medium=referral\&utm_content=tj-actions/auto-doc\&utm_campaign=Badge_Grade_Settings) +![Coverage](https://img.shields.io/badge/Coverage-84.1%25-brightgreen) [![Go Reference](https://pkg.go.dev/badge/github.com/tj-actions/auto-doc.svg)](https://pkg.go.dev/github.com/tj-actions/auto-doc) [![Go Report Card](https://goreportcard.com/badge/github.com/tj-actions/auto-doc)](https://goreportcard.com/report/github.com/tj-actions/auto-doc) [![CI](https://github.com/tj-actions/auto-doc/workflows/CI/badge.svg)](https://github.com/tj-actions/auto-doc/actions?query=workflow%3ACI) From e1677868199724ca08be3e6bf03743e56946b2c9 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Tue, 22 Nov 2022 18:46:44 -0700 Subject: [PATCH 3/3] Update code-coverage.yml --- .github/workflows/code-coverage.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 38c49b69..d2e7ad19 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -1,3 +1,5 @@ +name: Generate code coverage badge + on: pull_request: branches: