* fix coverage report (#1553)

* codecov
This commit is contained in:
mmetc 2022-05-24 17:22:08 +02:00 committed by GitHub
parent 1a293a2a27
commit 8ea9e83798
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 74 deletions

View file

@ -43,15 +43,21 @@ jobs:
- name: "Run tests"
run: |
TEST_COVERAGE=true make bats-test
bzip2 ./tests/local/var/lib/coverage/coverage-bats.out
- name: "Coverage report artifact"
uses: actions/upload-artifact@v2
with:
name: coverage-bats.out.bz2
path: ./tests/local/var/lib/coverage/coverage-bats.out.bz2
- name: "Show crowdsec logs"
run:
for file in $(find ./tests/local/var/log -type f); do echo ">>>>> $file"; cat $file; echo; done
if: ${{ always() }}
- name: Upload crowdsec coverage to codecov
uses: codecov/codecov-action@v2
with:
files: ./tests/local/var/lib/coverage/coverage-crowdsec.out
flags: func-crowdsec
- name: Upload cscli coverage to codecov
uses: codecov/codecov-action@v2
with:
files: ./tests/local/var/lib/coverage/coverage-cscli.out
flags: func-cscli

View file

@ -31,3 +31,10 @@ jobs:
run: make build
- name: All tests
run: go test -coverprofile coverage.out -covermode=atomic ./...
- name: Upload unit coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: coverage.out
flags: unit-windows

View file

@ -61,62 +61,3 @@ jobs:
GIST_BADGES_ID: ${{ secrets.GIST_BADGES_ID }}
GIST_BADGES_SECRET: ${{ secrets.GIST_BADGES_SECRET }}
coverage:
needs: [go-tests, bats-sqlite]
name: Coverage
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
fetch-depth: 1
path: go/src/github.com/crowdsecurity/crowdsec
- name: Download unit report
uses: actions/download-artifact@v3
with:
name: coverage.out.bz2
- name: Download bats report
uses: actions/download-artifact@v3
with:
name: coverage-bats.out.bz2
# - name: Environment
# run: env | sort
- name: merge coverage reports
run: |
go install github.com/wadey/gocovmerge@latest
bunzip2 coverage.out.bz2
bunzip2 coverage-bats.out.bz2
~/go/bin/gocovmerge coverage.out coverage-bats.out > coverage-all.out
bzip2 <coverage-all.out >coverage-all.out.bz2
# - name: coverage.out
# run: cat coverage.out
# - name: coverage-bats.out
# run: cat coverage-bats.out
- name: gcov2lcov
uses: jandelgado/gcov2lcov-action@v1.0.8
with:
infile: coverage-all.out
outfile: coverage-all.txt
env:
GOPATH: /home/runner/work/crowdsec/crowdsec/go
- name: Coverage report artifact (merged)
uses: actions/upload-artifact@v2
with:
name: coverage-all.out.bz2
path: ./coverage-all.out.bz2
- name: Coveralls
uses: coverallsapp/github-action@master
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage-all.txt

View file

@ -63,10 +63,10 @@ jobs:
- name: "Run tests"
run: |
go run github.com/ory/go-acc ./... -o coverage.out --ignore database,notifications,protobufs,cwversion,cstest,models
bzip2 ./coverage.out
- name: "Coverage report artifact"
uses: actions/upload-artifact@v2
- name: Upload unit coverage to Codecov
uses: codecov/codecov-action@v2
with:
name: coverage.out.bz2
path: ./coverage.out.bz2
files: coverage.out
flags: unit-linux

View file

@ -18,5 +18,5 @@ THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
# The '=' between flags and values is required.
exec "${BIN_DIR}/crowdsec.cover" \
-test.run="^TestBincoverRunMain$" \
-test.coverprofile="${LOCAL_DIR}/var/lib/coverage/$(date +'%s')-$$.out" \
-test.coverprofile="${LOCAL_DIR}/var/lib/coverage/crowdsec-$(date +'%s')-$$.out" \
-args-file=<(for i; do echo "$i"; done) # Behold the amazing parameter contraption!

View file

@ -25,7 +25,7 @@ set +e
# The '=' between flags and values is required.
output=$("${BIN_DIR}/cscli.cover" \
-test.run="^TestBincoverRunMain$" \
-test.coverprofile="${LOCAL_DIR}/var/lib/coverage/$(date +'%s')-$$.out" \
-test.coverprofile="${LOCAL_DIR}/var/lib/coverage/cscli-$(date +'%s')-$$.out" \
-args-file=<(for i; do echo "$i"; done))
rc=$?

View file

@ -45,5 +45,6 @@ else
fi
if [ -n "$TEST_COVERAGE" ]; then
gocovmerge "${LOCAL_DIR}"/var/lib/coverage/* > "${LOCAL_DIR}/var/lib/coverage/coverage-bats.out"
gocovmerge "${LOCAL_DIR}"/var/lib/coverage/crowdsec-* > "${LOCAL_DIR}/var/lib/coverage/coverage-crowdsec.out"
gocovmerge "${LOCAL_DIR}"/var/lib/coverage/cscli-* > "${LOCAL_DIR}/var/lib/coverage/coverage-cscli.out"
fi