From 213324732172bec216974cef1fb378c3468c118c Mon Sep 17 00:00:00 2001 From: Ilya Amelevich <46163087+iamelevich@users.noreply.github.com> Date: Wed, 18 Jan 2023 20:17:53 +0100 Subject: [PATCH] Add coverage badge (#1) * Add coverage badge * Fix coverage badge action * Fix coverage badge action * Fix coverage badge action * Fix coverage badge action * Fix coverage badge action * chore: Updated coverage badge. Co-authored-by: github-actions[bot] --- .github/workflows/coverage-badge.yml | 59 ++++++++++++++++++++++++++++ .github/workflows/go.yml | 25 ------------ README.md | 1 + 3 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/coverage-badge.yml delete mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/coverage-badge.yml b/.github/workflows/coverage-badge.yml new file mode 100644 index 0000000..0b93318 --- /dev/null +++ b/.github/workflows/coverage-badge.yml @@ -0,0 +1,59 @@ +name: Test + +on: + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + name: Update coverage badge + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.18 + + - uses: actions/cache@v3 + 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 "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + 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: + branch: ${{ github.head_ref }} \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index b417071..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,25 +0,0 @@ -# This workflow will build a golang project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go - -name: Go - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -jobs: - - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.18 - - - name: Test - run: go test -v ./... diff --git a/README.md b/README.md index df0c411..de5ddae 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ +![Coverage](https://img.shields.io/badge/Coverage-58.8%25-yellow) * [Overview](#overview) * [Requirements](#requirements)