[HELP] Golang code coverage not working anymore

New UI

The Old/current version that we use


Currently, we successfully to add code coverage in our sonar cloud, using Github-action, but several days ago, after the UI of the sonar cloud has quite changed, we can’t reproduce the code coverage again, is it from our sonar-properties getting wrong?

  • Github action
on:
  # Trigger analysis when pushing in master or pull requests, and when creating
  # a pull request.
  push:
    branches:
      - dev
      - master
      - pre_release
  pull_request:
    types: [opened, synchronize, reopened]
name: Main Workflow
jobs:
  sonarcloud:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          # Disabling shallow clone is recommended for improving relevancy of reporting
          fetch-depth: 0
      - uses: actions/setup-go@v2
      - run: |
              go version &&
              go test -covermode=atomic -coverprofile=coverage.out ./... &&
              ls -lah
              exit 0
      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  • Sonar properties file
sonar.organization=myproject
sonar.projectKey=myproject_pservice
sonar.projectVersion=1.0

sonar.sources=.
sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/*

sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**
sonar.go.coverage.reportPaths=coverage.out
sonar.go.tests.reportPaths=report.json

Hi Juliper!

From what I see in your screenshot of the old UI your coverage wasn’t setup correctly.
In the new UI, the default tab shows the coverage only for the new code, or if you are on a PR it shows the coverage only if we received the report for the PR code.

On the old UI it was showing the “estimated after merge” coverage even if we didn’t receive any coverage report, just one coverage report in the life of the project on the main branch was enough to display this value.

So I suggest that you check in your github action logs what’s happening with the coverage file, if it’s correctly generated, with the right values and if it’s correctly passed down to SonarCloud.

@Gregoire_Aubert do you have any suggestions for the GitHub action? and I think the coverage success full generated and loaded

INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /github/workspace/sonar-project.properties
INFO: Analyzing on SonarCloud
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=759ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=169ms
INFO: Load/download plugins (done) | time=35751ms
INFO: Loaded core extensions: developer-scanner
INFO: Found an active CI vendor: 'Github Actions'
INFO: Load project settings for component key: 'obfuscated'
INFO: Load project settings for component key: 'obfuscated' (done) | time=147ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: obfuscated
INFO: Base dir: /github/workspace
INFO: Working dir: /github/workspace/.scannerwork
INFO: Load project branches
INFO: Load project branches (done) | time=150ms
INFO: Check ALM binding of project 'obfuscated'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'obfuscated' (done) | time=132ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=147ms
INFO: Load branch configuration
INFO: Github event: pull_request
INFO: Auto-configuring pull request 533
INFO: Load branch configuration (done) | time=617ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=175ms
INFO: Load active rules
INFO: Load active rules (done) | time=4461ms
INFO: Organization key: obfuscated
INFO: Pull request 533 for merge into dev from f_sonarcloud
INFO: Load project repositories
INFO: Load project repositories (done) | time=165ms
INFO: SCM collecting changed files in the branch
INFO: SCM collecting changed files in the branch (done) | time=285ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/*_test.go
INFO:   Included tests: **/*_test.go
INFO: 267 files indexed
INFO: 22 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for go: Sonar way
INFO: Quality profile for plsql: Sonar way
INFO: Quality profile for yaml: Sonar way
INFO: ------------- Run sensors on module obfuscated
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=136ms
INFO: Sensor CSS Rules [cssfamily]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor CSS Rules [cssfamily] (done) | time=3ms
INFO: Sensor IaC CloudFormation Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC CloudFormation Sensor [iac] (done) | time=56ms
INFO: Sensor PL/SQL Sensor [plsql]
WARN: The Data Dictionary is not configured for PLSQL analyzer which prevents rule(s) S3641, S3921, S3618, S3651 to raise issues. See https://sonarcloud.io/documentation/analysis/languages/plsql/
INFO: 142 source files to be analyzed
INFO: 142/142 source files have been analyzed
INFO: Sensor PL/SQL Sensor [plsql] (done) | time=1705ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=4ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=17ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=1ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=7ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=3ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=0ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=14ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
INFO: Sensor Code Quality and Security for Go [go]
INFO: 115 source files to be analyzed
ERROR: Test report can't be loaded, file not found: '/github/workspace/report.json', ignoring this file.
INFO: 115/115 source files have been analyzed
INFO: Sensor Code Quality and Security for Go [go] (done) | time=4106ms
INFO: Sensor Go Unit Test Report [go]
INFO: Sensor Go Unit Test Report [go] (done) | time=8ms
INFO: Sensor Go Cover sensor for Go coverage [go]
INFO: Load coverage report from '/github/workspace/coverage.out'
INFO: Sensor Go Cover sensor for Go coverage [go] (done) | time=80ms
INFO: Sensor Import of GoMetaLinter issues [go]
WARN: Unable to import GoMetaLinter report file(s):
- /github/workspace/gometalinter-report.out
The report file(s) can not be found. Check that the property 'sonar.go.gometalinter.reportPaths' is correctly configured.
INFO: Sensor Import of GoMetaLinter issues [go] (done) | time=3ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=4ms
INFO: Sensor ThymeLeaf template sensor [securityjavafrontend]
INFO: Sensor ThymeLeaf template sensor [securityjavafrontend] (done) | time=1ms
INFO: Sensor Serverless configuration file sensor [securityjsfrontend]
INFO: 0 Serverless function entries were found in the project
INFO: 0 Serverless function handlers were kept as entrypoints
INFO: Sensor Serverless configuration file sensor [securityjsfrontend] (done) | time=84ms
INFO: Sensor AWS SAM template file sensor [securityjsfrontend]
INFO: Sensor AWS SAM template file sensor [securityjsfrontend] (done) | time=4ms
INFO: Sensor JavaSecuritySensor [security]
INFO: Reading type hierarchy from: /github/workspace/.scannerwork/ucfg2/java
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /github/workspace/.scannerwork/ucfg2/java
INFO: No UCFGs have been included for analysis.
INFO: Sensor JavaSecuritySensor [security] (done) | time=5ms
INFO: Sensor CSharpSecuritySensor [security]
INFO: Reading type hierarchy from: /github/workspace/ucfg_cs2
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /github/workspace/ucfg_cs2
INFO: No UCFGs have been included for analysis.
INFO: Sensor CSharpSecuritySensor [security] (done) | time=1ms
INFO: Sensor PhpSecuritySensor [security]
INFO: Reading type hierarchy from: /github/workspace/.scannerwork/ucfg2/php
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /github/workspace/.scannerwork/ucfg2/php
INFO: No UCFGs have been included for analysis.
INFO: Sensor PhpSecuritySensor [security] (done) | time=2ms
INFO: Sensor PythonSecuritySensor [security]
INFO: Reading type hierarchy from: /github/workspace/.scannerwork/ucfg2/python
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /github/workspace/.scannerwork/ucfg2/python
INFO: No UCFGs have been included for analysis.
INFO: Sensor PythonSecuritySensor [security] (done) | time=5ms
INFO: Sensor JsSecuritySensor [security]
INFO: Reading type hierarchy from: /github/workspace/.scannerwork/ucfg2/js
INFO: Read 0 type definitions
INFO: Reading UCFGs from: /github/workspace/.scannerwork/ucfg2/js
INFO: 02:51:49.574036 Building Runtime Type propagation graph
INFO: 02:51:49.577881 Running Tarjan on 0 nodes
INFO: 02:51:49.578596 Tarjan found 0 components
INFO: 02:51:49.578754 Variable type analysis: done
INFO: 02:51:49.57916 Building Runtime Type propagation graph
INFO: 02:51:49.579322 Running Tarjan on 0 nodes
INFO: 02:51:49.579435 Tarjan found 0 components
INFO: 02:51:49.579527 Variable type analysis: done
INFO: Analyzing 2 ucfgs to detect vulnerabilities.
INFO: Taint analysis starting. Entrypoints: 3
INFO: Running symbolic analysis for 'JS'
INFO: Taint analysis: done.
INFO: Sensor JsSecuritySensor [security] (done) | time=422ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=20ms
INFO: CPD Executor 110 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 147 files
INFO: CPD Executor CPD calculation finished (done) | time=118ms
INFO: SCM writing changed lines
INFO: SCM writing changed lines (done) | time=19ms
INFO: Analysis report generated in 234ms, dir size=424 KB
INFO: Analysis report compressed in 224ms, zip size=232 KB
INFO: Analysis report uploaded in 764ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=obfuscated&pullRequest=533
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AXy6gt4Zf_16RicQQGnl
INFO: Analysis total time: 20.265 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:01.812s
INFO: Final Memory: 38M/130M
INFO: ------------------------------------------------------------------------

So I can see in the report that the coverage file seems to be correctly loaded:

INFO: Sensor Go Cover sensor for Go coverage [go]
INFO: Load coverage report from '/github/workspace/coverage.out'

Can you confirm that the file /github/workspace/coverage.out correctly contains the coverage information for the whole project ?
Also are the paths in the coverage file correct regarding the root folder of the analysis ? There is no mismatch ? (for example your analysis is ran from root folder and the coverage from root/src, so the reference paths in the coverage report would not match)

@Gregoire_Aubert sir
here the content of coverage.out

mode: atomic
github.com/qoala/promotion-service/domain/category/repository/repository.go:19.42,21.2 1 9
github.com/qoala/promotion-service/domain/category/repository/repository.go:23.94,27.16 3 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:32.2,32.26 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:27.16,30.3 2 0
github.com/qoala/promotion-service/domain/category/repository/repository.go:35.88,36.55 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:40.2,40.12 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:36.55,38.3 1 0
github.com/qoala/promotion-service/domain/category/repository/repository.go:43.109,44.62 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:48.2,48.12 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:44.62,46.3 1 0
github.com/qoala/promotion-service/domain/category/repository/repository.go:51.88,56.16 2 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:60.2,60.12 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:56.16,58.3 1 0
github.com/qoala/promotion-service/domain/category/repository/repository.go:63.146,67.16 3 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:72.2,72.33 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:67.16,70.3 2 0
github.com/qoala/promotion-service/domain/category/repository/repository.go:75.107,86.16 4 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:91.2,91.52 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:95.2,95.24 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:86.16,89.3 2 0
github.com/qoala/promotion-service/domain/category/repository/repository.go:91.52,93.3 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:99.109,108.16 4 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:113.2,113.53 1 1
github.com/qoala/promotion-service/domain/category/repository/repository.go:117.2,117.24 1 1

oh ya sir… for the old UI I ever screenshot the result for the branch analyzed before the UI updated

This case is close, the root cause is I just add sonar-project.properties and github-action without any changes in the code project.

Thank you @Gregoire_Aubert for helping analysis.

Great to hear that it was solved for you!

I’m just wondering, what do you mean by:

You already had those files in your project no ?

Already have sir…, but when doing integration the changes just adding sonar-project.properties and github-action not changes in go file sir…

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.