Github Actions Sonar Scanner can't resolve file paths in lcov.info

First off, I am aware, that there are resolved issues that are similar to mine, but I’ve tried every possible answer 50 times, so I think my case might be unique.

I’m trying to upload the lcov.info coverage data, generated with nyc of my mocha tests, to my SonarQube instance.
Unfortunately, no matter what I try, the sonar-scanner can’t seem to find the files indicated in the lcov file:

WARN: Could not resolve 7 file paths in [/github/workspace/coverage/lcov.info]
WARN: First unresolved path: config/file:config/config.ts

Here are some relevant debug logs of the scanner: 2022-06-14T13:54:08.0400335Z ##[group]Run sonarsource/sonarqube-scan-action@mast - Pastebin.com

yarn test: nyc --reporter=lcovonly --reporter=text-summary mocha -r ts-node/register 'tests/run.test.ts'

SonarScanner workflow file:

name: Build
on:
  push:
      branches: [ master ]
  pull_request:
      types: [opened, synchronize, reopened]
      branches: [ master ]
jobs:
  sonarqube:
    name: sonarqube
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Install dependencies
        run: yarn
      - name: Run Tests
        run: yarn test

      ## This is one of the suggested fixes. 
      ## Im removing the dir paths that were tested for and make them relative paths.
      - name: Fix coverage report
        run: sed -i "s+/home/runner/work/rest-api/rest-api/++g" coverage/lcov.info

      - name: Run SonarQube Scan
        uses: sonarsource/sonarqube-scan-action@master
        with:
          ## used to debug sonarqube-scan-action
          args: >
            -Dsonar.verbose=true
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

sonar-project.properties

sonar.language=ts
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.sources=.
sonar.tests=tests/
sonar.coverage.exclusions=tests/**
sonar.test.inclusions=tests/**
sonar.projectKey=<PROJECT-KEY>

Hey there.

These are some pretty odd file paths. Can you upload your coverage/lcov.info file (without any further processing?)

Hey Colin, thanks for the quick reply!
Here’s the lcov file.

TN:
SF:config/file:/home/runner/work/rest-api/rest-api/config/config.ts
FNF:0
FNH:0
DA:1,1
DA:2,1
DA:4,1
DA:6,1
DA:17,1
DA:18,1
DA:19,1
DA:23,1
DA:24,4
DA:25,0
DA:26,0
DA:30,1
LF:12
LH:10
BRDA:7,0,0,1
BRDA:7,0,1,0
BRDA:8,1,0,1
BRDA:8,1,1,0
BRDA:11,2,0,1
BRDA:11,2,1,0
BRDA:14,3,0,0
BRDA:14,3,1,1
BRDA:17,4,0,1
BRDA:17,4,1,0
BRDA:24,5,0,0
BRDA:24,5,1,4
BRF:12
BRH:6
end_of_record
TN:
SF:file:/home/runner/work/rest-api/rest-api/server.ts
FN:18,(anonymous_1)
FN:22,(anonymous_2)
FN:28,(anonymous_3)
FN:34,(anonymous_4)
FNF:4
FNH:2
FNDA:1,(anonymous_1)
FNDA:1,(anonymous_2)
FNDA:0,(anonymous_3)
FNDA:0,(anonymous_4)
DA:1,1
DA:2,1
DA:3,1
DA:5,1
DA:6,1
DA:8,1
DA:9,1
DA:12,1
DA:14,1
DA:16,1
DA:18,1
DA:19,1
DA:22,1
DA:23,1
DA:27,1
DA:28,0
DA:29,0
DA:34,1
DA:35,0
DA:38,1
LF:20
LH:17
BRDA:12,0,0,0
BRDA:12,0,1,1
BRDA:27,1,0,0
BRDA:27,1,1,1
BRF:4
BRH:2
end_of_record
TN:
SF:modules/dbHandler/file:/home/runner/work/rest-api/rest-api/modules/dbHandler/dbHandler.ts
FN:11,(anonymous_1)
FNF:1
FNH:1
FNDA:1,(anonymous_1)
DA:1,1
DA:3,1
DA:4,1
DA:6,1
DA:7,1
DA:9,1
DA:10,1
DA:11,1
DA:12,1
DA:15,1
DA:17,1
LF:11
LH:11
BRDA:9,0,0,0
BRDA:9,0,1,1
BRF:2
BRH:1
end_of_record
TN:
SF:modules/dbHandler/file:/home/runner/work/rest-api/rest-api/modules/dbHandler/snipModel.ts
FN:10,(anonymous_1)
FN:14,(anonymous_2)
FN:18,(anonymous_3)
FN:23,(anonymous_4)
FN:27,(anonymous_5)
FN:33,(anonymous_6)
FN:39,(anonymous_7)
FNF:7
FNH:7
FNDA:2,(anonymous_1)
FNDA:2,(anonymous_2)
FNDA:1,(anonymous_3)
FNDA:5,(anonymous_4)
FNDA:2,(anonymous_5)
FNDA:2,(anonymous_6)
FNDA:2,(anonymous_7)
DA:1,1
DA:2,1
DA:5,1
DA:11,2
DA:15,2
DA:19,1
DA:24,5
DA:28,2
DA:34,2
DA:40,2
DA:44,1
LF:11
LH:11
BRF:0
BRH:0
end_of_record
TN:
SF:modules/dbHandler/schemas/file:/home/runner/work/rest-api/rest-api/modules/dbHandler/schemas/fileSchema.ts
FNF:0
FNH:0
DA:1,1
DA:3,1
DA:5,1
DA:15,1
DA:17,1
LF:5
LH:5
BRF:0
BRH:0
end_of_record
TN:
SF:modules/dbHandler/schemas/file:/home/runner/work/rest-api/rest-api/modules/dbHandler/schemas/snipSchema.ts
FNF:0
FNH:0
DA:1,1
DA:2,1
DA:3,1
DA:5,1
DA:7,1
DA:16,1
LF:6
LH:6
BRF:0
BRH:0
end_of_record
TN:
SF:routers/file:/home/runner/work/rest-api/rest-api/routers/snip.ts
FN:15,(anonymous_1)
FN:24,(anonymous_2)
FN:34,(anonymous_3)
FN:37,(anonymous_4)
FN:40,(anonymous_5)
FN:50,(anonymous_6)
FN:53,(anonymous_7)
FN:59,(anonymous_8)
FN:67,(anonymous_9)
FN:75,(anonymous_10)
FN:78,(anonymous_11)
FN:82,(anonymous_12)
FN:85,(anonymous_13)
FN:88,(anonymous_14)
FN:91,(anonymous_15)
FN:103,(anonymous_16)
FNF:16
FNH:12
FNDA:1,(anonymous_1)
FNDA:1,(anonymous_2)
FNDA:0,(anonymous_3)
FNDA:2,(anonymous_4)
FNDA:2,(anonymous_5)
FNDA:1,(anonymous_6)
FNDA:1,(anonymous_7)
FNDA:1,(anonymous_8)
FNDA:0,(anonymous_9)
FNDA:1,(anonymous_10)
FNDA:1,(anonymous_11)
FNDA:1,(anonymous_12)
FNDA:0,(anonymous_13)
FNDA:1,(anonymous_14)
FNDA:1,(anonymous_15)
FNDA:0,(anonymous_16)
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:8,1
DA:10,1
DA:11,1
DA:15,1
DA:16,1
DA:25,1
DA:34,0
DA:37,1
DA:38,2
DA:39,2
DA:41,2
DA:50,1
DA:53,1
DA:54,1
DA:55,1
DA:57,1
DA:58,1
DA:60,1
DA:61,1
DA:63,0
DA:64,0
DA:68,0
DA:71,0
DA:75,1
DA:76,1
DA:77,1
DA:79,1
DA:82,1
DA:85,0
DA:88,1
DA:89,1
DA:90,1
DA:92,1
DA:93,1
DA:96,1
DA:97,1
DA:101,1
DA:103,0
DA:106,1
LF:45
LH:38
BRDA:57,0,0,1
BRDA:57,0,1,0
BRDA:60,1,0,1
BRDA:60,1,1,0
BRDA:96,2,0,1
BRDA:96,2,1,0
BRF:6
BRH:3
end_of_record

Hello,

I have the same problem, but the error is not sonar… is ts-node 10.8.1, when I use the ts-node 10.7.0, all istanbull reports are ok…

So, you need to change the package.json and use, for now, 10.7.0 … not ^10.7.0

Best regards

2 Likes

Thanks @Yadickson! That’s really helpful.

For future reference:

1 Like

Thank you so much!