tl;dr: We want to run sonarcloud analyse for our java application with a github action.
we are building our application (https://github.com/synyx/urlaubsverwaltung/) with GitHub Actions as you can see in the .github directory. In the early days, before GitHub Actions, we build it with travis and the integration with sonarcloud was already there and easy to setup. But now we will migrate to GitHub Actions and I want to know how I can analyse my project with sonarcloud and not using travis.
There is already a Sonarcloud GitHub Action, but this one is not compatible with a java/maven based project.
There are two ways that would be ok for us.
First: Add a own sonarcloud github action
Second: Triggering sonarcloud via the maven build like mvn sonar:sonar
We would highly prefer the first, because it would fit the strategy and paradigm behind GitHub Actions.
What a pleasure to see the first thread about GitHub Actions!
Analysing Maven or Gradle projects on GitHub Actions is really simple: just run the standard Maven or Gradle tasks from your GitHub Action build. The mandatory parameters are:
sonar.host.url=https://sonarcloud.io
sonar.projectKey, displayed in the homepage of your SonarCloud project
sonar.organization, displayed in the homepage of your SonarCloud project too
Branches and pull requests will be automatically configured. Here is an example on the “legacy” GitHub Actions v1. The concept is the same for v2.
I hope it helps.
EDIT: sample is now upgraded to GitHub Actions v2.
thanks for your response. Are there any chances to get a SonarCloud Action with predefined, but configurable, host url and configurable projectKey and organization like
No need for hostUrl, there’s only one URL for SonarCloud
The parameters projectKey and organization could make sense indeed, but how would you support all the other analyser properties? They are known only at runtime and can’t be manually listed in the GitHub Action metadata.
Contrary to what I said, the perfect solution would be to simply drop the parameters projectKey and organization. They could be guessed from the GitHub repository. This improvement will come soon, please stay tuned.