From 9a284eeb142cfff618d35b4342f142680ac3fa36 Mon Sep 17 00:00:00 2001 From: Daniel Farrell Date: Mon, 3 Oct 2022 13:43:18 -0400 Subject: [PATCH] Add Sonar unit test coverage reporting Add GHA to run unit tests, generate coverage report, and upload the report to SonarCloud. Add configuration to ignore code that shouldn't count for coverage. Relates-to: stolostron/backlog#22706 Signed-off-by: Daniel Farrell --- .github/workflows/report.yml | 20 ++++++++++++++++++++ sonar-project.properties | 10 ++++++++++ 2 files changed, 30 insertions(+) create mode 100644 sonar-project.properties diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml index 489e3036e..c64c40290 100644 --- a/.github/workflows/report.yml +++ b/.github/workflows/report.yml @@ -10,6 +10,26 @@ on: permissions: {} jobs: + unit-coverage: + name: Go Unit Test Coverage + if: github.repository_owner == 'submariner-io' + runs-on: ubuntu-latest + steps: + - name: Check out the repository + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + + - name: Run Go unit tests + run: make unit + + - name: Run SonarScan, upload Go test results and coverage + uses: sonarsource/sonarcloud-github-action@de2e56b42aa84d0b1c5b622644ac17e505c9a049 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + --debug + variant-analysis: name: Variant Analysis runs-on: ubuntu-latest diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 000000000..84ee5d837 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,10 @@ +sonar.projectKey=submariner-io_submariner-operator +sonar.projectName=submariner-operator +sonar.organization=submariner-io +sonar.sources=. +sonar.exclusions=**/vendor/**,**/*_test.go,test/e2e/** +sonar.tests=. +sonar.test.inclusions=**/*_test.go,test/e2e/** +sonar.test.exclusions=**/vendor/** +sonar.go.tests.reportPaths=**/junit.xml +sonar.go.coverage.reportPaths=**/unit.coverprofile