Skip to content

Commit

Permalink
Merge pull request #251 from qclc/add-codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-lgy authored Nov 1, 2023
2 parents 60a002b + 9ac1bd4 commit 3c336c6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
22 changes: 22 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
coverage:
status:
project:
default:
target: auto
threshold: 2%
# https://docs.codecov.com/docs/commit-status#patch-status
patch:
default:
target: 60%
if_ci_failed: error
# https://docs.codecov.com/docs/ignoring-paths
ignore:
- "config"
- "docs"
- "examples"
- "hack"
- "pkg/apis"
- "pkg/client"
- "test"
- "*_test.go"
- "fake_*.go"
25 changes: 22 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ on:
- v*
pull_request:

# TODO: coverage

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -26,7 +24,28 @@ jobs:
with:
go-version: ${{ matrix.go-version }}

- run: make test
- name: Ensure coverage is reported for every package
run: |
find pkg -type d -print0 | while IFS= read -r -d '' dir; do
go_file=$(ls -1 $dir | grep '\.go$' | grep -v '_test\.go$' | head -n1)
if [[ $go_file ]]; then
package_line=$(grep '^package' ${dir}/${go_file} | head -n1)
echo "${package_line}_test" >$dir/package_coverage_test.go
fi
done
- name: Run unit tests
run: make test

- name: Upload coverage reports to Codecov
if: ${{ github.repository == 'kubewharf/kubeadmiral' && matrix.go-version == '1.19' }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.out
flags: unittests
fail_ci_if_error: true
verbose: true

lint:
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ lint-new: lint
# Run tests
.PHONY: test
test:
go test -race -coverprofile coverage0.out ./pkg/...
go test -race -coverpkg=./pkg/... -coverprofile coverage.out.tmp ./pkg/...
# exclude generated files from coverage calculation
sed '/generated/d' coverage0.out > coverage.out
rm coverage0.out
sed '/generated/d' coverage.out.tmp > coverage.out
rm coverage.out.tmp

# Run e2e tests
.PHONY: e2e
Expand Down

0 comments on commit 3c336c6

Please sign in to comment.