Code analysis being run on files not created in PR

  • ALM: Github
  • CI system: cloud build

Hey, I’m trying to run sonar cloud’s code analysis to get the coverage percentage of new files (new in this case refering only to files updated in the current pull request) but it seems to always analyze some old files that were already merged

my yaml file

steps:
  - name: 'gcr.io/cloud-builders/yarn:lts'
    entrypoint: 'yarn'
    args: ['install', '--frozen-lockfile']
    id: 'Install dependencies'
    secretEnv: ['GITHUB_TOKEN']

  - name: 'gcr.io/cloud-builders/yarn:lts'
    entrypoint: 'yarn'
    args: ['prisma:generate']
    id: 'Prisma generate'
    secretEnv: ['GITHUB_TOKEN']

  - name: 'gcr.io/cloud-builders/yarn:lts'
    entrypoint: 'bash'
    env: ['NODE_OPTIONS=--max_old_space_size=8192']
    args: ['-c', 'yarn vitest run --coverage --testTimeout=10000']
    id: 'Test and coverage'
    secretEnv: ['GITHUB_TOKEN']

  - name: 'sonarsource/sonar-scanner-cli:latest'
    entrypoint: 'bash'
    args:
      - '-c'
      - |
        sonar-scanner \
          -Dsonar.working.directory=/tmp/sonar \
          -Dsonar.token=$$SONAR_TOKEN \
          -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info \
          $(test "$_PR_NUMBER" != "" && echo "-Dsonar.pullrequest.key=${_PR_NUMBER} -Dsonar.pullrequest.branch=${_HEAD_BRANCH} -Dsonar.pullrequest.base=${_BASE_BRANCH}")
    id: 'SonarCloud Scan'
    secretEnv: ['SONAR_TOKEN']

Hi,

Welcome to the community!

Could you share what makes you say this? Is it that you see old files in the PR analysis? Something else?

Also, could you share your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann