Skip to content

Commit

Permalink
Add Sonar unit test coverage reporting
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dfarrell07 committed Oct 13, 2022
1 parent 13fb714 commit 9a284ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9a284ee

Please sign in to comment.