Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support wildcards for coverage report paths #578

Closed
vilchik-elena opened this issue Apr 26, 2017 · 17 comments · Fixed by #2742
Closed

Support wildcards for coverage report paths #578

vilchik-elena opened this issue Apr 26, 2017 · 17 comments · Fixed by #2742
Assignees
Labels
type: enhancement Improving existing functionality
Milestone

Comments

@vilchik-elena
Copy link
Contributor

vilchik-elena commented Apr 26, 2017

Currently property for coverage LCOV report paths doesn't accept paths with wildcards. This might be very useful when path is not stable (e.g. see question on SOF).

Property name: sonar.javascript.lcov.reportPaths

We should decide whether this feature should be implemented for old properties (still supported for SQ < 6.2):

  • sonar.javascript.lcov.reportPath
  • sonar.javascript.lcov.itReportPath

Example:
"sonar.javascript.lcov.reportPaths=reports/*" would match
reports/report1.lcov
reports/report2.lcov

"sonar.javascript.lcov.reportPaths=**/report.lcov" would match
reports1/report.lcov
reports2/report.lcov

@vilchik-elena vilchik-elena added the type: enhancement Improving existing functionality label Apr 26, 2017
@ivandalbosco
Copy link
Contributor

ivandalbosco commented Apr 26, 2017

+1
As regards SQ < 6.2: I suggest we simply pick the cheapest solution between support and non support of wild cards.

@ideadapt
Copy link

ideadapt commented Dec 5, 2017

I use something like

{ type: 'lcov', dir: 'test/reports/unit/coverage/lcov/', subdir: function(browser) {
    // keep a consistent browser name across different OS & browser versions
    return browser.toLowerCase().split(/[ /-]/)[0];
  }
}

to generate a version neutral path. Found at https://github.com/karma-runner/karma-coverage/blob/master/docs/configuration.md

@vilchik-elena vilchik-elena added this to the 4.2 milestone Jul 9, 2018
@vilchik-elena vilchik-elena self-assigned this Jul 16, 2018
@vilchik-elena
Copy link
Contributor Author

There is implementation for wildcard support in sonarGo and SonarPython. We should migrate it to sonar-analyzer-commons

@vilchik-elena vilchik-elena removed this from the 4.2 milestone Jul 16, 2018
@vilchik-elena vilchik-elena removed their assignment Jul 16, 2018
@hzdavid
Copy link

hzdavid commented Dec 11, 2018

so Could we use wildcards to . sonar.jacoco.reportPaths now ?

@fadc80
Copy link

fadc80 commented Jun 4, 2019

Is there any chance to see this issue resolved soon?

@roy-bakker-new10
Copy link

Would still love this!

@dblees
Copy link

dblees commented Jul 15, 2019

sonar.jacoco.reportPaths and sonar.jacoco.classes .. this does not seem to support wildcards .. is this correct? If so, until this is supported this feels brittle. every time a codebase changes, this forces maintenance of configuration to capture reports and classes. please consider this feature. thanks.

@Rai-Rai
Copy link

Rai-Rai commented Oct 10, 2019

👍
Need support for wildcards for sonar.typescript.lcov.reportPaths really desperate....

@vilchik-elena
Copy link
Contributor Author

@Rai-Rai since last release (SonarTS 2.0 and SonarJS 6.0) there is single logic and property to load coverage for TS and JS: sonar.javascript.lcov.reportPaths

@brenuart
Copy link

brenuart commented Aug 26, 2020

Would love this too - and not only for SonarJS but not only for coverage report paths but others as well, like:

  • sonar.javascript.lcov.reportPaths
  • sonar.typescript.tslint.reportPaths
  • sonar.testExecutionReportPaths (generic report)

As @vilchik-elena said, they all share a common logic located in sonar-analyzer-commons (https://github.com/SonarSource/sonar-analyzer-commons/blob/master/commons/src/main/java/org/sonarsource/analyzer/commons/ExternalReportProvider.java#L35) - can't we simply adapt it to support ANT-style patterns for instance?

Would you consider a PR for this ?

@brenuart
Copy link

brenuart commented Aug 27, 2020

Any chance this issue gets some attention from maintainers? At least some indication about whether this feature request makes sense or not.. ?
Ping @andrey-tyukin-sonarsource, @vilchik-elena ...

@pburkindine
Copy link

Also badly need this feature for js/ts

@clok
Copy link

clok commented Aug 3, 2021

Bump. This would be very helpful!

@lpcruz
Copy link

lpcruz commented Aug 3, 2021

Bumping this as well--- currently in a situation where we need to support multiple lcov reports so having it be a capability of Sonar itself would be amazing.

@mariamatthews
Copy link

mariamatthews commented Aug 28, 2021

Note: I am aware that this is now closed and merged in the new version, but for those who cannot upgrade

Hi guys, could I suggest using a quick bash script before your SonarQube runs that would identify the file/folder locations for you as a workaround?

Putting the below path and updating the packages folder name to the root folder of your projects should find the exact locations for you.

Code:

  - bash: |
      for entry in packages/*/
      do
      if [ "$entry" == "packages/common/" ] ; then
            continue;
      fi
      testPaths=${testPaths}${entry}test-report.xml,
      coveragePaths=${coveragePaths}${entry}coverage/lcov.info,
      done
      testPaths=${testPaths%,}
      coveragePaths=${coveragePaths%,}
      echo "Test and coverage reports paths found: "
      echo "Test reports: $testPaths"
      echo "Coverage reports: $coveragePaths"
      echo "Setting pipeline variables..."
      echo "##vso[task.setvariable variable=TESTPATHS]$testPaths"
      echo "##vso[task.setvariable variable=COVERAGEPATHS]$coveragePaths"
    displayName: Getting report paths for SonarQube

The above task would iterate over the folders and add the files found within the temporary Azure Pipelines variables.
The if statement is where you could add any folders you would like it to skip.

This means that you can set SonarQube reportPaths like:

      sonar.testExecutionReportPaths=$(TESTPATHS)
      sonar.javascript.lcov.reportPaths=$(COVERAGEPATHS)

Let me know if you have found it useful and if it worked for you (in the case where you can't upgrade your SonarQube instance) 🧡

@hoch4
Copy link

hoch4 commented Dec 28, 2021

This workaround works well too

#!/bin/sh
coverage=$(find -type f -name '*coverage.lcov' -printf "%p,")
testResults=$(find -type f -name '*test-result.xml' -printf "%p,")

mvn sonar:sonar \
  -Dsonar.projectKey=my.project.key.from.sonarqube \
  -Dsonar.host.url=http://mysonarqubeserver.com:9000 \
  -Dsonar.login=kd94kaek94ad9duiope67fbn89vbnnn89dw \
  -Dsonar.sources="." \
  -Dsonar.tests="." \
  -Dsonar.test.inclusions="**/*.spec.ts" \
  -Dsonar.javascript.lcov.reportPaths="${coverage}" \
  -Dsonar.testExecutionReportPaths="${testResults}"

@arobinson
Copy link

arobinson commented Feb 14, 2024

I'm still having this problem. I've tried both * and ** with no luck with sonar.javascript.lcov.reportPaths

Using

export SONAR_SCANNER_VERSION="5.0.1.3006"

And

"sonarqube-scanner": "^3.3.0

Error:

14:47:08  INFO: No LCOV files were found using /home/ec2-user/workspace/Client/some-workspace/test-results/coverage/*.lcov.info
14:47:08  WARN: No coverage information will be saved because all LCOV files cannot be found.

I archived the test-results/coverage folder as part of the Jenkins job, and verified the path is correct and should have matched 4 files. Also, from the error, it does not sound like it is using the code that was in the fix for this issue.

What version needs to be used to obtain the fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improving existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.