Monorepo setup with github actions don't work

Hi, we’re using github with Sonarcloud paid version with those tools:

  • ALM used (GitHub private)
  • CI system used (Azure DevOps)

Currently I’m trying to setup code analysis on monorepo. I have read documentation and searched this forum for related issues, but was not able to find out how to properly setup monorepo with GH actions.

I have imported private github monorepo in Sonarcloud and added projects with keys.
However when I go to project and follow steps to add GH action analysis it says:
Create a configuration file in the root directory of the project and name it sonar-project.properties
Why in root? Not sure… Where can I find some tutorial or sample properties file how it should work?
How should I run Sonarcloud on each folder(project) inside monorepo? Should this be done in GH action or where?
When just import github repo as monorepo and added sonar-project.properties files inside each project (folder) but nothing added on root folder, then GH action return obvious err: You must define the following mandatory properties for ‘Unknown’: sonar.projectKey, sonar.organization
Did I miss something?

Any help would be appreciated.

Hey there.

Welcome to our community!

You should run the GitHub action from the base directory of each project in the monorepo. And there’s a clever projectBaseDir parameter available for the action! Take a look at the example below:

jobs:
  sonarcloud:
    name: SonarCloud
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        with:
          projectBaseDir: repo1/
      - name: SonarCloud Scan 2
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        with:
          projectBaseDir: repo2/

So with a setup like this, and a sonar-project.properties file in each base directory, you’re good to go.

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