Sonarcloud-github-action coverage percentage missing from sonar cloud

I am using github actions for Sonar Cloud scan this is my yml

jobs: 
  sonarcloud:
    name: SonarCloud
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Use NodeJs
        uses: actions/setup-node@v2
        with: 
          node-version: "16.x"
      - run: npm i -g typescript typings
      - run: npm i -g npm-cli-login
      - run: npm-cli-login -u "$NPM_USER" -p "$NPM_PASS" -e "$NPM_EMAIL" -r "$NPM_REGISTRY" -s "$NPM_SCOPE"
      - run: npm config set registry "$NPM_REGISTRY"
      - run: npm install --registry "$NPM_REGISTRY" 
      - run: npm i -g mocha  
      - run: npm run build
      - run: npm run cover
      - 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 }}

Workflow runs successfully, but report in sonar gives 0%. There sis no error, any help is appreciated.

Hey there.

Did you follow the documentation on https://docs.sonarcloud.io/enriching/test-coverage/javascript-typescript-test-coverage/?

If so, what do the logs say?

Hi Colin,

I have checked the logs also, sonar scanner is completed successfully. Attaching the logs.

But in the logs it says
INFO: Analysing [/github/workspace/coverage/lcov.info]
WARN: Could not resolve 109 file paths in [/github/workspace/coverage/lcov.info]
logs.txt (21.6 KB)

Thanks. Can you share how your GitHub Actions YML is configured (including where you generate the code coverage lcov.info file)?

name: Deploy to Amazon ECS

on:
  push:
    branches:
      - develop
      - feature/*
  pull_request:
    types: [opened, synchronize, reopened]

env:
  NPM_USER: ${{ secrets.NPM_USER }}
  NPM_PASS: ${{ secrets.NPM_PASS }}
  NPM_EMAIL: ${{ secrets.NPM_EMAIL }}
  NPM_REGISTRY: ${{ secrets.NPM_REGISTRY }}
  NPM_SCOPE: ${{ secrets.NPM_SCOPE }}
  AWS_REGION: us-east-1               
  ECR_REPOSITORY: auth-api          
  BUILD_NUMBER: ${{ github.run_number }}
  APPLICATION_NAME: Auth-API
  

permissions:
  contents: read

jobs: 
  sonarcloud:
    name: SonarCloud
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Use NodeJs
        uses: actions/setup-node@v2
        with: 
          node-version: "16.x"
      - run: npm i -g typescript typings
      - run: typings install
      - run: npm i -g npm-cli-login
      - run: npm-cli-login -u "$NPM_USER" -p "$NPM_PASS" -e "$NPM_EMAIL" -r "$NPM_REGISTRY" -s "$NPM_SCOPE"
      - run: npm config set registry "$NPM_REGISTRY"
      - run: npm install --registry "$NPM_REGISTRY" --force
      - run: npm i -g mocha  
      - run: npm run build
      - run: npm run cover
      - run: echo "${{ github.workspace }}"
      - run: cat "${{ github.workspace }}/coverage/lcov-report/index.html"
      - run: ls -la
        working-directory: ${{ github.workspace }}
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@v1.7
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

This is the yml i am running. coverage report is generated in root folder. I have attached the logs where i have printed the report itself.
all-logs.txt (255.7 KB)

It looks like the scanner and the coverage report understand where these files are located very differently.

/github/workspace/

2023-09-07T05:58:27.3155600Z INFO: Creating TypeScript program (done) | time=7513ms
2023-09-07T05:58:27.3157676Z INFO: Starting analysis with current program
2023-09-07T05:58:29.8060914Z INFO: 1/155 file analyzed, current file: /github/workspace/src/model/entity/address.ts
2023-09-07T05:58:39.8072443Z INFO: 46/155 files analyzed, current file: /github/workspace/src/service/org/org.ts
2023-09-07T05:58:49.8078163Z INFO: 65/155 files analyzed, current file: /github/workspace/src/service/auth/impl/auth.ts
2023-09-07T05:58:59.8080977Z INFO: 105/155 files analyzed, current file: /github/workspace/spec/controller/attribute-standard.spec.ts
2023-09-07T05:59:06.4407785Z INFO: Analyzed 155 file(s) with current program
2023-09-07T05:59:06.4453106Z INFO: 155/155 source files have been analyzed

/home/runner/work/

2023-09-07T05:59:06.4604290Z INFO: Sensor JavaScript/TypeScript Coverage [javascript]
2023-09-07T05:59:06.4609533Z INFO: Analysing [/github/workspace/coverage/lcov.info]
2023-09-07T05:59:06.4731055Z WARN: Could not resolve 109 file paths in [/github/workspace/coverage/lcov.info]
2023-09-07T05:59:06.4736753Z WARN: First unresolved path: /home/runner/work/users-service-auth-api/users-service-auth-api/newrelic.js (Run in DEBUG mode to get full list of unresolved paths)
2023-09-07T05:59:06.4737947Z INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=13ms

What could be causing this (basically: why does your coverage report use /home/runner/work/ and not /github/workspace/. I can’t really reason why.

Two notes:

Can you try reomving this? I wonder if it’s affecting the working directory of future steps.

The latest version if this action is v2