Template for a good new topic, formatted with Markdown:
- Github
- Github Actions
- Ruby, JavaScript
We have a monorepo using a Ruby on Rails backend and a JavaScript client in the same repository. I’m trying to get them both set up for code coverage & analysis, and the monorepo page (https://sonarcloud.io/documentation/advanced-setup/monorepo-support/) gets me most of the way there, but I feel like I’m missing the last mile.
I’ve created a Github Action to run tests/lint for each project. In SonarCloud, I’ve created a Sonar project for each project, and a corresponding sonar-project.properties file with the relevant key & identifier. I’ve got the different tokens set up as Github secrets. I then attempt to set up the Github Actions using the guides on your website, by adding a build.yml
and using the provided Github Action SonarSource/sonarcloud-github-action
:
name: Build
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
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 }}
However, when I run this, I get:
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 45.815s
ERROR: Error during SonarScanner execution
INFO: Final Memory: 7M/24M
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.organization
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
INFO: ------------------------------------------------------------------------
This actually makes sense to me, because I don’t have a top-level sonar-project.properties
nor even a top-level job. My mental model is that there are 2 completely independent projects, each running under a different folder within the monorepo (backend/
and web/
), each with their own sonar-project.properties
. Presumably, there will also need to be 2 different SonarCloud scans.
If I want to trigger a SonarCloud scan of these projects, do I use the Github action (sonarsource/sonarcloud-github-action
)? Or does that github action not work in monorepos, and I’ll need to manually download & run the sonar-scanner
executable?