Can SonarCloud Github Action run more than once per commit?

Use case:

We’re dealing with a C++ code base that takes significant amount of time to build and run tests. We would like to get code quality scan to complete first since it only requires raw source code as an input and not have to wait for the build + test steps to complete.

What I’m trying to do

I would like to run SonarCloud Github Action twice:

  1. once at the start of the CI workflow to initiate the code quality analysis
  2. second time after tests with coverage instrumentation have completed in order to feed the coverage data to SonarCloud

Yes, I understand that SonarCloud will perform code quality analysis both times.

What my questions are

  1. Will I get any benefit from initiating quality analysis without coverage data early?
  2. Will SonarCloud be able to merge multiple scans per commit in order to update the final PR status?

Hi @Ivan_Ribakov

Thanks for reaching out.

We are aware that running the analysis and importing the coverage in a single step is a CI design restriction that prevents some optimizations. We have it on our radar and we are considering options.

About your questions.
First, let me rectify that:

That’s not correct for all languages. Especially for C++, source code is not enough; you also need to know how to parse it. It primarily means getting include directories and preprocessor directives. This can be handled in different ways, depending on which analysis configuration method you use for your C++ analysis:

  • If you use the build-wrapper, you must wait for your build to be finished before starting the analysis.
  • If you use a compilation database, often, there is a way to generate it without building the code. In that case, you could do an analysis parallel to the build.
  • If you use the automatic analysis for C++, it does not take these extra bits of information as input, it infers them. In that case, the analysis happens independently from the build.

Back to your questions

The simple answer is no for both questions. Not at the moment.
There is no way to split the scanner run into two parallel runs, one for the code analysis and the other for importing the coverage results.
One could think of a hacky workaround using CFamily’s filesystem-based cache, but I do not recommend going down that route.

I keep track of your interest and when we are ready, we will collect interest for that topic there.

1 Like

I keep track of your interest and when we are ready, we will collect interest for that topic there.

Thanks, I’ve actually came across a related proposal in a different thread and submitted another version that is more aligned with what was discussed in this thread but I guess submitted ideas must first pass some internal review before becoming publicly available since I can’t see my submitted idea online.

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