Skip to content

[CI] Integrate SonarCloud to the repository#5845

Draft
meenbeese wants to merge 1 commit into
organicmaps:masterfrom
meenbeese:integrate-sonarcloud
Draft

[CI] Integrate SonarCloud to the repository#5845
meenbeese wants to merge 1 commit into
organicmaps:masterfrom
meenbeese:integrate-sonarcloud

Conversation

@meenbeese

@meenbeese meenbeese commented Aug 27, 2023

Copy link
Copy Markdown
Contributor

Resolves #3180

SonarCloud sales pitch: Using this GitHub Action, scan your code with SonarCloud to detect bugs, vulnerabilities and code smells in C and C++!

I chose the C/C++/Objective-C version of the workflow as this covers more than 80% of our code.
I also took the first steps to integrate SonarCloud but some actions are needed from the maintainers:

  • Have an account on SonarCloud. Sign up for free now if it's not already the case!
  • The repository to analyze is set up on SonarCloud. Set it up in just one click.
  • Generate the SONAR_TOKEN and GITHUB_TOKEN – Resources: Security page in SonarCloud. You can set the SONAR_TOKEN environment variable in the "Secrets" settings page of your repo and (see Authenticating with the GITHUB_TOKEN).
  • Populate the .github/workflows/sonar-analyze.yml and sonar-project.properties files with the secrets.
  • Configure actions in the workflow (maybe sonar-project.properties too) according to the needs of the project .

Some useful documentation:

@biodranik

Copy link
Copy Markdown
Member

Thanks! Did you test it in your fork? Is it helpful? Is there a lot of unimportant noise?

@meenbeese

meenbeese commented Aug 28, 2023

Copy link
Copy Markdown
Contributor Author

Thanks! Did you test it in your fork? Is it helpful? Is there a lot of unimportant noise?

I didn't test it in my fork as I wanted to save myself the hassle of configuring it. Yet, I have seen many open-source projects use it which they wouldn't if it wasn't adequately useful.

As for the noise, it is really minimal and is only in the form of a reply comment on a PR with the analyzed results. Here is a screenshot for context:
image

@rtsisyk rtsisyk self-assigned this Aug 28, 2023
@rtsisyk

rtsisyk commented Aug 28, 2023

Copy link
Copy Markdown
Contributor

I will take a look.

@meenbeese meenbeese changed the title [workflows] Integrate SonarCloud to the repo [CI] Integrate SonarCloud to the repository Aug 29, 2023
@AndrewShkrob

Copy link
Copy Markdown
Member

You can preview how it will appear in our project by checking here:
AndrewShkrob#2
https://sonarcloud.io/summary/new_code?id=AndrewShkrob_organicmaps&pullRequest=2

@meenbeese meenbeese force-pushed the integrate-sonarcloud branch from 92e7737 to a3895d5 Compare October 10, 2023 22:24
@meenbeese meenbeese force-pushed the integrate-sonarcloud branch from a3895d5 to 6aa4ea3 Compare July 13, 2024 21:14
@meenbeese

Copy link
Copy Markdown
Contributor Author

Should I rework the PR with @AndrewShkrob's changes and prepare it to be merged? @biodranik

I see a lot of potential value here in regards to saving maintainers' time.

@biodranik

Copy link
Copy Markdown
Member

How actionable is this list of many issues and smells? Note that we also have third-party code that should be ignored. And there is Java which may be useful to analyze.

выява

@rtsisyk

rtsisyk commented Aug 24, 2024

Copy link
Copy Markdown
Contributor

@meenbeese , I've created an organization, started the scan, added SONAR_TOKEN to this repo and invited you to the organization.

Comment thread .github/workflows/sonar-analyze.yml Outdated
Comment thread sonar-project.properties Outdated
Comment thread sonar-project.properties Outdated
@rtsisyk

rtsisyk commented Aug 24, 2024

Copy link
Copy Markdown
Contributor

Please let me know if you need any help.

@meenbeese meenbeese force-pushed the integrate-sonarcloud branch 3 times, most recently from 20efa05 to a42a05f Compare August 25, 2024 22:20
@meenbeese

Copy link
Copy Markdown
Contributor Author

@meenbeese , I've created an organization, started the scan, added SONAR_TOKEN to this repo and invited you to the organization.

Thanks, I have seen the invite and joined the org, as well as applied the suggested changes. Since the sources and exclusions are also done, should we move ahead with customizing the sonar-analyze workflow?

@rtsisyk

rtsisyk commented Aug 26, 2024

Copy link
Copy Markdown
Contributor

Let's try to get it working.

https://github.com/organicmaps/organicmaps/actions/runs/10550477538/job/29226696423

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 6.889s
ERROR: Error during SonarScanner execution
INFO: Final Memory: 11M/54M
INFO: ------------------------------------------------------------------------
ERROR: Could not find a default branch for project with key 'organicmaps'. Make sure project exists.
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
Error: Process completed with exit code 2.

@rtsisyk

rtsisyk commented Aug 26, 2024

Copy link
Copy Markdown
Contributor
Analysis status
Last analysis failed
Analysis ID "AZGNmunTRjEkc6bEtEo0"
Your analysis with ID "AZGNmunTRjEkc6bEtEo0" has failed because it took too much time. Please try another CI tool to analyze your project.

[See troubleshooting documentation](https://docs.sonarsource.com/sonarcloud/appendices/troubleshooting/#automatic-analysis-timeout/)

@AndrewShkrob

Copy link
Copy Markdown
Member

Let's try to get it working.

https://github.com/organicmaps/organicmaps/actions/runs/10550477538/job/29226696423

INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 6.889s
ERROR: Error during SonarScanner execution
INFO: Final Memory: 11M/54M
INFO: ------------------------------------------------------------------------
ERROR: Could not find a default branch for project with key 'organicmaps'. Make sure project exists.
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
Error: Process completed with exit code 2.

What are you expecting to see here if the workflow is not configured? 😄

@rtsisyk

rtsisyk commented Aug 26, 2024

Copy link
Copy Markdown
Contributor

What are you expecting to see here if the workflow is not configured? 😄

What should be done to get it "configured"? The workflow is in this PR..

@AndrewShkrob

AndrewShkrob commented Aug 26, 2024

Copy link
Copy Markdown
Member

What are you expecting to see here if the workflow is not configured? 😄

What should be done to get it "configured"? The workflow is in this PR..

This workflow is just a template. Steps "Run build-wrapper" and "Run sonar-scanner" do nothing. That's why you see failures in the runner.
You can copy-paste the configuration from my PR that I prepared a long time ago
AndrewShkrob#2

But my config doesn't include everything supported by sonarcloud, f.e. test coverage, ios, android

@meenbeese meenbeese force-pushed the integrate-sonarcloud branch 6 times, most recently from 8809a2c to 7b9fd78 Compare August 26, 2024 23:29
@meenbeese meenbeese force-pushed the integrate-sonarcloud branch from 83da58f to d7d9a3a Compare August 26, 2024 23:35
@meenbeese

Copy link
Copy Markdown
Contributor Author

Interesting Sonar error after resolving dependency issues:

Run sonar-scanner --define sonar.cfamily.build-wrapper-output="build_wrapper_output_directory"
23:49:28.367 INFO Scanner configuration file: /home/runner/work/organicmaps/organicmaps/.sonar/sonar-scanner-6.1.0.4477-linux-x64/conf/sonar-scanner.properties
23:49:28.370 INFO Project root configuration file: /home/runner/work/organicmaps/organicmaps/sonar-project.properties
23:49:28.386 INFO SonarScanner CLI 6.1.0.4477
23:49:28.389 INFO Java 17.0.11 Eclipse Adoptium (64-bit)
23:49:28.389 INFO Linux 6.8.0-1012-azure amd64
23:49:28.422 INFO User cache: /home/runner/.sonar/cache
23:49:28.971 INFO JRE provisioning: os[linux], arch[x86_64]
23:49:30.206 INFO EXECUTION FAILURE
23:49:30.208 INFO Total time: 1.843s
23:49:30.208 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Error status returned by url [https://api.sonarcloud.io/analysis/jres?os=linux&arch=x86_64]: 401
at org.sonarsource.scanner.lib.internal.http.ServerConnection.callUrl(ServerConnection.java:182)
at org.sonarsource.scanner.lib.internal.http.ServerConnection.callApi(ServerConnection.java:145)
at org.sonarsource.scanner.lib.internal.http.ServerConnection.callRestApi(ServerConnection.java:123)
at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.getJreMetadata(JavaRunnerFactory.java:159)
at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.getJreFromServer(JavaRunnerFactory.java:138)
at org.sonarsource.scanner.lib.internal.JavaRunnerFactory.createRunner(JavaRunnerFactory.java:85)
at org.sonarsource.scanner.lib.internal.ScannerEngineLauncherFactory.createLauncher(ScannerEngineLauncherFactory.java:53)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:118)
at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:63)
23:49:30.209 ERROR
23:49:30.209 ERROR Re-run SonarScanner CLI using the -X switch to enable full debug logging.

Comment thread .github/workflows/sonar-analyze.yml Outdated
@meenbeese meenbeese force-pushed the integrate-sonarcloud branch 3 times, most recently from 2246a00 to 1c9e9c1 Compare October 6, 2024 00:31
Signed-off-by: Meenbeese <meenbeese@tutanota.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate SonarCloud

4 participants