Skip to content

Commit

Permalink
Adding coverage badge (Checkmarx#2952)
Browse files Browse the repository at this point in the history
Signed-off-by: Rogério Peixoto <[email protected]>
  • Loading branch information
rogeriopeixotocx authored Apr 22, 2021
1 parent 6391652 commit 46e8d8e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
11 changes: 10 additions & 1 deletion .github/scripts/get-coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,16 @@ def main():
stats = calc_file_stats(lines)
total = total_cov(stats)
if os.environ.get('GITHUB_RUN_ID'):
print(f"::set-output name=coverage::{total}")
if total >= 90:
color = 'brightgreen'
elif total >= 80:
color = 'green'
elif total >= 75:
color = 'orange'
else:
color = 'red'
print("::set-output name=coverage::%.2f" % (total))
print(f"::set-output name=color::{color}")
print(f"Total coverage: {total}")


Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/go-ci-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: go-ci-coverage

on:
push:
branches:
- "master"

jobs:
coverage:
name: test-coverage
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: Run test metrics script
id: testcov
run: make test-coverage-report
- name: Generate badge
run: |
git config --global user.name "KICSBot"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout gh-pages
curl -L https://img.shields.io/badge/Go%20Coverage-${{ steps.testcov.outputs.coverage }}%25-${{ steps.testcov.outputs.color }}.svg > coverage.svg
git add coverage.svg
git add coverage.html
git commit -m 'chore: updating coverage'
git push origin gh-pages
16 changes: 1 addition & 15 deletions .github/workflows/go-ci-metrics.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: go-ci-metrics

on:
push:
branches:
- "master"
pull_request:
branches: [master]

Expand All @@ -22,15 +19,4 @@ jobs:
run: sudo apt install zsh
- name: Run test metrics script
run: zsh .github/scripts/get-test-metrics.sh
coverage:
name: test-coverage
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v2
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: Run test metrics script
run: make test-coverage-report

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
![Docker Pulls](https://img.shields.io/docker/pulls/checkmarx/kics)
[![Documentation](https://img.shields.io/badge/docs-viewdocs-blue.svg?style=flat-square "Viewdocs")](https://docs.kics.io/)
[![Gitter](https://badges.gitter.im/kics-io/community.svg)](https://gitter.im/kics-io/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Go Coverage](https://raw.githubusercontent.com/Checkmarx/kics/gh-pages/coverage.svg)](https://docs.kics.io/coverage.html)


<img alt="KICS - Keep Infrastructure as Code Secure" src="docs/img/logo/kics-black.png" width="250">
Expand Down

0 comments on commit 46e8d8e

Please sign in to comment.