Detailed Monorepo setup info for github

I have a monorepo in github with several python projects in subfolders. I tried follow the information in Monorepo Support | SonarCloud Docs but there is some information I’m struggling to figure out.
I created 8 projects in SonarCloud using the “monorepo” option as described in the document. After that the projects all ask to configure analysis. I followed the github Actions option, but not sure exactly how to do it.
It seems to need the in the root of the repo, but that makes me specify a single project and not the sub projects within the monorepo.

I also created the .github/workflows/build.yml and setup the path to one of the subprojects. I’m guessing I would create multiple .yml files, one for each project I want to scan.

Can anyone clarify what I’m missing to get the multiple projects in the monorepo to show up with the correct analysis for their subfolder?



Welcome to the community!

The underlying assumption with monorepo support is here in the docs:

each project occupies its own directory within the repository

So you would put each project’s file in its directory. The same, I think, for the yml files.


Thanks Ann. I believe I tried that yesterday, but it didnt seem to find anything. I think Github requires the yml files to be in the root of the project. I’ll try again today to see if maybe I made a mistake when I tried before.
And yes, each project has its own individual directory within the repository with no crossing between project references.

I tried moving the file to the sub-project directory, but during the scan, it gets this error:

ERROR: You must define the following mandatory properties for ‘Unknown’: sonar.projectKey, sonar.organization

Those are defined in the file, so it seems it just didnt find it.


The properties file needs to be in the directory analysis is started from. Is that the sub-project directory?


I’m not really sure. Sorry I’m a beginner with SonarCloud. I have a repo in github with several sub-projects. I followed the documents when creating the project in SonarCloud, which had me create a build.yml and file. I just created them as stated in the web site.

I’m guessing I need to specify a location somewhere in the build.yml? The documentation for setting up a monorepo is very sparse, so I’m not really sure what to look for.

I found I need to put the build.yml in the root of the repo (not project) since github is looking for them there.

build-testproject.yml for one of the projects looks like

name: Scan Test Project
      - main
      - 'lambdas/test/**'
    types: [opened, synchronize, reopened]
    name: SonarCloud
    runs-on: ubuntu-latest
      - uses: actions/checkout@v2
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Ah, looking back at your message, I finally realized, I need to add this to the build.yml to set the projectBaseDir. This really should be added to the monorepo support docs, since its a critical setting. Without that it won’t work.

uses: SonarSource/sonarcloud-github-action@master
projectBaseDir: lambdas/test

Thank you, Ann, for getting me pointed in the right direction.

Hi yes can I echo Mike’s comments, I’m new to all this and have had a nightmare today trying to get a monorepo to work (still isn’t but I think I’m getting there). The docs page and examples are hopeless, I have had to do a ton of web searches to try to work this out. Thanks


Ditto. This would have been really nice to specify in the monorepo support docs.

If anyone else is trying to set up a monorepo, where SQ analysis is needed for each project in the repo, and you’re orchestrating with Github Actions…

  1. Add a file at the repo root:
  1. Add a file at the project root:
  1. Add this step to the Github Action for your project in the monorepo:
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          projectBaseDir: dir_for_my_project_in_monorepo # <-------------
  1. You do not need separate sonar cloud tokens for each project in the repo.
1 Like