Skip to content

Commit

Permalink
Add code coverage measuring
Browse files Browse the repository at this point in the history
  • Loading branch information
danie1k committed Apr 14, 2022
1 parent 78ede2e commit b85ed00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
48 changes: 19 additions & 29 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,28 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: "true"
- uses: docker://kcov/kcov:latest
with:
args: kcov --include-path src/ codecov/ ./test/bats/bin/bats test/
- uses: actions/upload-artifact@v3
with:
name: code-coverage-report-${GITHUB_RUN_ID}
path: codecov/

coverage:
needs: unit-tests

name: Upload Coverage report
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
- name: Run tests
uses: docker://kcov/kcov:latest
with:
name: code-coverage-report-${GITHUB_RUN_ID}
path: codecov/
- run: |
xml="$(ls -1 codecov/bats*/cobertura.xml | head -1)"
json="$(ls -1 codecov/bats*/coverage.json | head -1)"
# removing trailing slash in cobertura <source>
# this works around an issue with the codeclimate formatter
sed -r "s#<source>(.+)/</source>#<source>\1</source>#" "$xml" > cobertura_tmp.xml
args: kcov --include-path src/ codecov/ ./test/bats/bin/bats test/

# make paths relative
sed -r "s#/github/workspace##" cobertura_tmp.xml > cobertura.xml
sed -r "s#/github/workspace##" "$json" > coverage.json
- uses: codecov/codecov-action@v2
# https://github.com/particleflux/kcov-bats-circleci-codeclimate/blob/master/.circleci/config.yml
- name: Prepare coverage report
run: |2
_xml="$(ls -1 codecov/bats*/cobertura.xml | head -1)"
sed -r \
's#"bats"#"src"#;s#/github/workspace/##;s#<source>(.+)/</source>#<source>/github/workspace/</source>#' \
"$_xml" > coverage.xml
- name: Upload coverage report
uses: codecov/codecov-action@v2
# https://github.com/SimonKagstrom/kcov/blob/master/doc/codecov.md
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./cobertura.xml,./coverage.json
fail_ci_if_error: true
files: coverage.xml
fail_ci_if_error: false

- uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: coverage.xml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Lint](https://github.com/danie1k/rsync-backup/actions/workflows/lint.yml/badge.svg)](https://github.com/danie1k/rsync-backup/actions/workflows/lint.yml)
[![Test](https://github.com/danie1k/rsync-backup/actions/workflows/test.yml/badge.svg)](https://github.com/danie1k/rsync-backup/actions/workflows/test.yml)
[![Code Coverage](https://codecov.io/gh/danie1k/rsync-backup/branch/master/graph/badge.svg?token=07IXMZ0DWO)](https://codecov.io/gh/danie1k/rsync-backup)
[![MIT License](https://img.shields.io/github/license/danie1k/rsync-backup)](https://github.com/danie1k/rsync-backup/blob/master/LICENSE)

# rsync-backup
Expand Down

0 comments on commit b85ed00

Please sign in to comment.