Skip to content

Commit

Permalink
combined code coverage (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengaudet authored Jul 28, 2023
1 parent b260264 commit 184de99
Showing 1 changed file with 49 additions and 22 deletions.
71 changes: 49 additions & 22 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,17 @@ jobs:
with:
go-version: '1.20.3'
- uses: actions/checkout@v3
- name: Setup Code Climate test-reporter
run: |
curl -L "$CC_BINARY_URL" > ./cc-test-reporter
chmod +x ./cc-test-reporter
- name: Run tests
run: |
export GIT_COMMIT_SHA='${{ github.sha }}'
export GIT_BRANCH="$(echo '${{ github.ref }}' | sed -E -e 's/.*\/(.*)/\1/')"
export CC_TEST_REPORTER_ID='${{ secrets.CC_TEST_REPORTER_ID }}'
./cc-test-reporter before-build
echo "Running tests..."
go test $(go list ./... | grep -v integration_test) -coverprofile c.out ./...
mod="$(cat go.mod | awk '/^module/ {print $2}')"
if [[ ! -z "$CC_TEST_REPORTER_ID" ]]; then
echo "Generating coverage report..."
./cc-test-reporter after-build -p "${mod}/" -t gocov
fi
mkdir unitcoverage
go test -cover $(go list ./... | grep -v integration_test) -args -test.gocoverdir="$PWD/unitcoverage"
- uses: actions/upload-artifact@v3
with:
name: unit-test-coverage
path: ./unitcoverage/

publish:
name: Goreleaser
Expand Down Expand Up @@ -115,7 +105,7 @@ jobs:
- current
- next
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Login to DockerHub
uses: docker/login-action@v2
if: "!startsWith(github.ref, 'refs/tags/v')"
Expand Down Expand Up @@ -162,10 +152,47 @@ jobs:
docker compose kill;
rm -f gcp-token.json;
rm -f service-principal.key;
go tool covdata textfmt -i=./coverage -o=./coverage/cov.txt;
sed -i 's/\/go\/src\/github.com/github.com/g' ./coverage/cov.txt;
go tool cover -html=./coverage/cov.txt -o=./coverage/integrationtestcoverage.html;
- uses: actions/upload-artifact@v3
with:
name: integrationtest-coverage-env${{ matrix.testenvs }}
path: ./integration_test/coverage/integrationtestcoverage.html
name: integration-test-coverage-env${{ matrix.testenvs }}
path: ./integration_test/coverage/

report-coverage:
needs: integration-tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Setup Code Climate test-reporter
run: |
curl -L "$CC_BINARY_URL" > ./cc-test-reporter
chmod +x ./cc-test-reporter
- uses: actions/download-artifact@v3
with:
name: unit-test-coverage
path: unit-test-coverage
- uses: actions/download-artifact@v3
with:
name: integration-test-coverage-envcurrent
path: integration-test-coverage-envcurrent
- uses: actions/download-artifact@v3
with:
name: integration-test-coverage-envnext
path: integration-test-coverage-envnext
- name: Report Coverage
run: |
export CC_TEST_REPORTER_ID='${{ secrets.CC_TEST_REPORTER_ID }}'
if [[ ! -z "$CC_TEST_REPORTER_ID" ]]; then
echo "Generating coverage report..."
export GIT_COMMIT_SHA='${{ github.sha }}'
export GIT_BRANCH="$(echo '${{ github.ref }}' | sed -E -e 's/.*\/(.*)/\1/')"
./cc-test-reporter before-build
go tool covdata textfmt -i=./unit-test-coverage,./integration-test-coverage-envcurrent,./integration-test-coverage-envnext -o ./c.out
rm -rf ./unit-test-coverage
rm -rf ./integration-test-coverage-envcurrent
rm -rf ./integration-test-coverage-envnext
sed -i 's/\/go\/src\/github.com/github.com/g' ./c.out
mod="$(cat go.mod | awk '/^module/ {print $2}')"
./cc-test-reporter after-build -p "${mod}/" -t gocov
fi

0 comments on commit 184de99

Please sign in to comment.