Skip to content

Commit

Permalink
sonar: add test coverage (#9988)
Browse files Browse the repository at this point in the history
- attempt to integrate sonar with test coverage by following 
-
https://sonarcloud.io/project/configuration/GitHubActions?id=ledgerwatch_erigon
-
https://docs.sonarsource.com/sonarcloud/advanced-setup/ci-based-analysis/github-actions-for-sonarcloud/
- adds sonar properties file to specify code coverage output
- also properties file can be used to filter out generated code from
sonar scan
    - protobuf
    - graphql
    - ignore pedersen hash bindings code
- ... there will be more ignores coming in later PRs (e.g. some c/c++
code we dont need to scan, some js code, some contract gen code, etc.)
  • Loading branch information
taratorio authored Apr 23, 2024
1 parent 0fa85d2 commit ff05e20
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ jobs:
- name: Test
run: make test

- name: SonarCloud
if: runner.os == 'Linux'
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
continue-on-error: true

tests-windows:
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
strategy:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ go.work*
docker-compose.*.yml
.env
coverage.out
coverage-erigon.out
coverage-erigon-lib.out

dist
__debug_bin
Expand All @@ -99,4 +101,4 @@ node_modules
/config.yaml
/config.yml

vendor
vendor
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test-erigon-ext:

## test: run unit tests with a 100s timeout
test: test-erigon-lib
$(GOTEST) --timeout 10m
$(GOTEST) --timeout 10m -coverprofile=coverage-erigon.out

test3: test-erigon-lib
$(GOTEST) --timeout 10m -tags $(BUILD_TAGS),e3
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ lint-deps: lintci-deps lint-licenses-deps
lint: lintci lint-licenses lint-mod-tidy

test:
$(GOTEST) --count 1 -p 2 ./...
$(GOTEST) --count 1 -p 2 -coverprofile=coverage-erigon-lib.out ./...

test-no-fuzz:
$(GOTEST_NOFUZZ) --count 1 -p 2 ./...
11 changes: 11 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sonar.projectKey=ledgerwatch_erigon
sonar.organization=ledgerwatch
sonar.projectName=erigon

sonar.sources=.
sonar.exclusions=**/*.pb.go,cmd/rpcdaemon/graphql/graph/generated.go,erigon-lib/pedersen_hash/**

sonar.tests=.
sonar.test.inclusions=**/*_test.go,tests/**

sonar.go.coverage.reportPaths=coverage-erigon.out,coverage-erigon-lib.out

0 comments on commit ff05e20

Please sign in to comment.