Code coverage doesn't work with GitHub action

As reported on github code coverage reports don’t work with SonarCloud github action. When running sonar-scanner with identical sonar-project.properties config, everything works as expected but when running it with github action, I get the following error:
WARN: Could not resolve 39 file paths in [/github/workspace/frontend/coverage/lcov.info], first unresolved path: /home/runner/work/myproject/myproject/frontend/src/app/app-routing.module.ts.

Any suggestions how to fix it?

2 Likes

I guess the issue is docker’s virtual working dir…

I have same error using github actions

2019-11-21T20:32:44.3692057Z INFO: Since SonarTS v2.0, TypeScript analysis is performed by SonarJS analyzer v6.0 or later. No TypeScript analysis is performed by SonarTS.
2019-11-21T20:32:44.3698717Z INFO: Sensor SonarTS [typescript] (done) | time=1ms
2019-11-21T20:32:44.3704647Z INFO: Sensor JaCoCo XML Report Importer [jacoco]
2019-11-21T20:32:44.3731158Z INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
2019-11-21T20:32:44.3738771Z INFO: Sensor SonarJS Coverage [javascript]
2019-11-21T20:32:44.3753716Z INFO: Analysing [/github/workspace/coverage/lcov.info]
2019-11-21T20:32:44.3835564Z WARN: Could not resolve 18 file paths in [/github/workspace/coverage/lcov.info], first unresolved path: /home/runner/work/account-management/account-management/src/addresses/address.entity.ts

I have the same error :pensive:

You can use sed cli utility to correct file paths in your github workflow. For example:

 - name: fix code coverage paths
	working-directory: ./coverage
	run: |
	  sed -i 's/\/home\/runner\/work\/<your-repo-name>\/<your-repo-name>\//\/github\/workspace\//g' lcov.info
	  sed -i 's/\/home\/runner\/work\/<your-repo-name>\/<your-repo-name>\//\/github\/workspace\//g' sonar-cloud-reporter.xml
4 Likes

You can also leverage the $GITHUB_WORKSPACE env variable to make the command agnostic of your repo:

sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' lcov.info

4 Likes

Thank you so much for this hassle-free solution!

Totally simplified my workflow.

I initially created a temporary directory to store those files, which made my workflow long and unreadable for novices.

This is the ultimate solution

Thanks for sharing, this was a missing link for me as well!

I also bumped into this same issue but with Gitlab and SimpleCov for Ruby files.
I’ve tried with both correct absolute and relative paths but still getting the same error:
[WARNING] File './backend/app/checkpoint_util.rb' is present in coverage report but cannot be found in filesystem or with absolute path [WARNING] File '/builds/Dev/project/backend/app/checkpoint_util.rb' is present in coverage report but cannot be found in filesystem.
Any tips or ideas how to solve it?