Giter Club home page Giter Club logo

coverage-badge-go's Introduction

Ubuntu Mac OS Windows Public workflows that use this action.

All Contributors

coverage-badge-go

Generate a coverage badge like this one for your Golang projects without uploading results to a third party.

              ๐Ÿ‘‡

CI Coverage Update release version.

Usage

name: Generate code coverage badge

on:
  pull_request:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    name: Update coverage badge
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        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@v4
        with:
          go-version-file: 'go.mod'

      - 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@v16
        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 "[email protected]"
          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 }}

Signed commits

In order to create signed commits see full guide here

Inputs

- uses: tj-actions/coverage-badge-go@v2
  id: coverage-badge-go
  with:
    # Color of the badge - green/yellow/red
    # Type: string
    color: ''

    # File containing the tests output
    # Type: string
    # Default: "coverage.out"
    filename: ''

    # At what percentage does the badge become green instead 
    # of yellow (default: 70) 
    # Type: string
    green: ''

    # Optional URL when you click the badge
    # Type: string
    link: ''

    # Target file (default "README.md")
    # Type: string
    target: ''

    # Text on the left side of the badge (default: "Coverage") 
    # Type: string
    text: ''

    # Text on the right side of the badge
    # Type: string
    value: ''

    # At what percentage does the badge become yellow instead 
    # of red (default 30) 
    # Type: string
    yellow: ''

If you feel generous and want to show some extra appreciation:

Buy me a coffee

Credits

This package was created with Cookiecutter using cookiecutter-action

Report Bugs

Report bugs at https://github.com/tj-actions/coverage-badge-go/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your workflow that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

Michael Donahue
Michael Donahue

๐Ÿ› ๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

coverage-badge-go's People

Contributors

allcontributors[bot] avatar dependabot[bot] avatar github-actions[bot] avatar jackton1 avatar mdonahue-godaddy avatar renovate-bot avatar renovate[bot] avatar repo-ranger[bot] avatar tj-actions-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

coverage-badge-go's Issues

[Feature] Rename filename to path

Is this feature missing in the latest version?

  • I'm using the latest release

Is your feature request related to a problem? Please describe.

I'll like to specify a path to the coverage output

Describe the solution you'd like?

Using path instead of filename would be a preferred input name that communicates support for paths i.e sub project coverage.

Describe alternatives you've considered?

No response

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[BUG] How do I signed commits generated by this actions

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

The below script works properly, creating a commit with updated coverage info in README.md. The problem is that the Pull Request is not able to be merged because the badge commit is not signed:

Merging is blocked
The base branch requires all commits to be signed.

My coverage_badge.yml

# https://github.com/tj-actions/coverage-badge-go
name: "Coverage Badge"
on:
  pull_request:
    branches:
      - develop

jobs:
  test:
    runs-on: ubuntu-latest
    name: Update coverage badge
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        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@v3
        with:
          go-version: "1.18"

      - name: Install OS dependencies
        run: sudo apt-get update && sudo apt-get install libgl1-mesa-dev xorg-dev

      - 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/[email protected]
        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 "[email protected]"
          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 }}

To Reproduce

  1. Add above script to project and commit
  2. Create a PR on a branch that requires commits to be signed
  3. Observe that GitHub will not allow the PR to be merged

What OS are you seeing the problem on?

macos-latest or macos-10.15

Expected behavior?

I expected the commit to be signed

Relevant log output

No response

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

[BUG] <cannot use -o flag with multiple packages>

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

when use the yml file you provide, workflow will exit with this message

image

To Reproduce

when i change go version to 1.17, error will disappear.

What OS are you seeing the problem on?

all

Expected behavior?

fix this

Relevant log output

No response

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Doc error

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

In your doc, you are using the wrong id for verify-changes:

    if: steps.changed_files.outputs.files_changed == 'true'

Should be:

    if: steps.verify-changed-files.outputs.files_changed == 'true'

To Reproduce

See doc

What OS are you seeing the problem on?

all

Expected behavior?

    if: steps.verify-changed-files.outputs.files_changed == 'true'

Relevant log output

No response

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codacy-analysis.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • codacy/codacy-analysis-cli-action v4.4.0
  • github/codeql-action v3
.github/workflows/codeql.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
.github/workflows/rebase.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • cirrus-actions/rebase 1.8
.github/workflows/sync-release-version.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • tj-actions/release-tagger v4
  • tj-actions/sync-release-version v13
  • tj-actions/git-cliff v1
  • peter-evans/create-pull-request v6.0.5
.github/workflows/test.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • reviewdog/action-golangci-lint v2
  • actions/setup-go v5
  • tj-actions/verify-changed-files v19
  • peter-evans/create-pull-request v6
.github/workflows/update-readme.yml
  • actions/checkout v4@0ad4b8fadaa221de15dcec353f45205ec38ea70b
  • tj-actions/auto-doc v3
  • tj-actions/remark v3
  • tj-actions/verify-changed-files v19
  • peter-evans/create-pull-request v6

  • Check this box to trigger a request for Renovate to run again on this repository

[BUG] <why my badge generated not in % form>

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

why my badge generated not in % form

image

To Reproduce

use your .yml

What OS are you seeing the problem on?

all

Expected behavior?

become % form.

Relevant log output

No response

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.