No coverage information will be saved because all LCOV files cannot be found for my javascript project using Github actions

Code coverage reports don’t work with SonarCloud github action

Sonar-test.yml

  sonarcloud:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          # Disabling shallow clone is recommended for improving relevancy of reporting.
          fetch-depth: 0
      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

sonar-project.properties:

sonar.projectKey={key}
sonar.projectName={name}
sonar.organization={org}

sonar.sources=src/
sonar.tests=test/
# sonar.test.exclusions= < No exclusions currently >
sonar.javascript.lcov.reportPaths=coverage/lcov.info

INFO: No LCOV files were found using coverage/lcov.info
WARN: No coverage information will be saved because all LCOV files cannot be found.

Any suggestions how to fix it?

1 Like

Hello Ravali,

I see that you shared only a part of your Github Action yml file. Are you actually running the tests and generating the coverage report file prior to running the SonarCloud step ?

@Gregoire_Aubert I get the same error message and yes, I’m running tests and generating lcov report before sonarcloud step. This used to work perfectly last week, and without any change in the workflow files or sonarcloud settings, we get that message.

Please advise,
Laurentiu

This is our own workflow.

name: Test React

on:
  - pull_request
jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 1
    - uses: actions/setup-node@v2
      with:
        node-version: '15.x'
    - uses: actions/cache@v2
      with:
        path: |
          node_modules
          ~/.npm
        key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
    - name: install
      run: |
        npm config set //registry.npmjs.org/:_authToken "${{ secrets.NPM_TOKEN }}"
        npm install --legacy-peer-deps
        npm run test
        ls
        ls coverage/
    - name: SonarCloud Scan
      uses: sonarsource/sonarcloud-github-action@master
      with:
        projectBaseDir: app
        args: >
          -Dsonar.organization={org_key}
          -Dsonar.projectKey={our_project_key}
          -Dsonar.sources=.
          -Dsonar.coverage.exclusions=**/tests/**
          -Dsonar.test.inclusions=**/tests/**
          -Dsonar.tests=.
          -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
          -Dsonar.eslint.eslintconfigpath=.modern-eslintrc
    env:
      CI: true
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Hello Laurentiu,

Do you know exactly when it stopped working correctly ? You probably can find the information by checking the coverage in the activity page of your project.

I’ll try to find out if we deployed anything related to this on that day and see if there is a bug on our side.

@Gregoire_Aubert I also get the same error message and I’m running the tests and generating the LCOV report before sonarcloud step.

This is a part of sonar properties file:

sonar.projectKey={key}
sonar.organization={org}
sonar.javascript.lcov.reportPaths=coverage/lcov.info

and this is the github action workflow:

name: Code Quality
env:
    NPM_TOKEN: ${{secrets.NPM_TOKEN}}
on:
  pull_request:
  push:
    branches:
      - main

jobs:
  test:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install npm packages
        run: yarn --frozen-lockfile
      - name: Run linters
        run: yarn lint

  unit-test:
    name: unit-test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install npm packages
        run: yarn --frozen-lockfile
      - name: Run unit tests
        run: yarn test
      - name: Archive code coverage results
        uses: actions/upload-artifact@v2
        with:
          name: code-coverage-report
          path: coverage/lcov.info

  sonarcloud:
    name: SonarCloud
    runs-on: ubuntu-latest
    needs: unit-test
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: Download code coverage results
        uses: actions/download-artifact@v2
        with:
          name: code-coverage-report
          path: coverage/lcov.info  
      - name: check on report
        run: cd coverage && ls
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

I have also added a step to check on the report and it’s there.
Can you please advise?

You script seems correct. You should check if the files paths generated inside the lcov files are correct compared to where the analysis is run. Sometime coverage tools generate absolute path which are then not usable by the analyzer.

Same problem here with a node application. Sometimes coverage and duplication verification works. I run the tests and the folder coverage is generated with the file lcov.info.

github actions:

name: CI-Sonarcloud

on:
  pull_request:
    branches: 
      - master

jobs:
  check-application:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      
      - name: Install dependencies
        run: npm install

      - name: Run tests
        run: npm test

      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

sonar properties:

sonar.projectKey=IgorCSilva_ci-sonarcloud
sonar.organization=igorcsilva

sonar.sourceEncoding=UTF-8

sonar.sources=.
sonar.exclusions=**/*.test.js

sonar.tests=.
sonar.test.inclusions=**/*.test.js

sonar.javascript.coveragePlugin=lcov
sonar.javascript.lcov.reportPaths=coverage/lcov.info

i am facing the same issue

sonar.host.url = https://sonarcloud.io

sonar.projectVersion=1.0

sonar.sourceEncoding=UTF-8

sonar.sources=src

#sonar.exclusions=**/node_modules/**,**/*.spec.js,**/*.stories.ts,**/*.stories.tsx,**/android/**,**/ios/**,**.js,**/fs-app/**,**/fs-renderer/**,**/*.e2e.tsx,**/loaders/**,**/services/**,**/realm/**,**/i18next/**, **/e2e/**, **/src/index.tsx

#sonar.test.exclusions=**/*.png, **/*.jpg, **/*.e2e.tsx,**/loaders/**,**/services/**,**/utils/**,**/realm/**,**/i18next/**,**/e2e/**

sonar.tests=test

sonar.test.inclusions=test/**/*.test.ts #path to tests

sonar.language=ts #ts stands for typescript

sonar.javascript.coveragePlugin=lcov

sonar.javascript.lcov.reportPaths=coverage/lcov.info

For anyone still having this problem in GitHub actions, the key thing is where you are running your tests vs where you are running your sonar scan in the GitHub workflow. If they are in different jobs in the workflow, you have to save the lcov.info as an artifact so that it is available to the sonarscan job. Or, a much easier solution, run your tests and the sonarscan in the same job. That is what I did and it solved this problem.

Faced same problem. I tried from my laptop and the coverage showed up. Then I re-ran the github action and it pushed coverage too. Strange that it didn’t push first time!