No coverage information, No LCOV files were found using coverage/lcov.info

I’m using github actions, and it seems like SonarCloud can’t find the unit tests’ coverage report and so the coverage info is not displayed.
I’m running the tests and generating the LCOV report before sonarcloud step.

I have checked the CI logs and this is what I got:

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

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?

Hey there.

My first suggestion would be to check the base directory being used by the scanner.

INFO: Base dir: /github/workspace/repo1

Is your coverage report located correctly relative to that location?

@Colin Hi thanks for your reply,

So Sonar is running with the base directory “/github/workspace”
while the lcov,info file is being downloaded in this location “/home/runner/work///coverage/lcov.info”

I finally reached a solution, having unit tests and sonar cloud running in different jobs and copying the artifacts over didn’t work, mainly due to a directory issue, that I didn’t fully get my head around.

So what worked for me was to have the unit tests and sonar run in the same job, here is how it looks like now.

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

  unitTest_sonarcloud:
    name: unitTest_sonarcloud
    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 npm packages
        run: yarn --frozen-lockfile
      - name: Run unit tests
        run: yarn test
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

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