GitHub PR decoration with CI based analysis from AWS CodeBuild

  • ALM used: GitHub
  • CI system used: AWS CodePipeline with AWS CodeBuild as the build executor
  • Scanner command used when applicable (private details masked)
  • Languages of the repository: python and TypeScript

Hi,

I would like to configure our project to report the analysis status to GitHub PRs on our short-lived branches. We run our unit tests in an AWS CodeBuild container and use the sonar-scanner to report the static analysis and code coverage to Sonarcloud.

This works fine and I can see the different branches, but I have not found clear steps on how to integrate the report from sonar-scanner to be published to the GitHub PR.

Could you provide clear example on what steps I need to do and what configuration keys I need to have in sonar-project.properties or in SonarCloud project settings to get the analysis reported to the GitHub PR?

This is how we invoke sonar-scanner:

sonar-scanner -Dsonar.login="$SONAR_TOKEN" -Dsonar.branch.name="$BRANCH"

Here’s our current sonar-project.properties:

sonar.organization=REDACTED
sonar.projectKey=REDACTED
sonar.host.url=https://sonarcloud.io
sonar.javascript.node.maxspace=4096
sonar.sourceEncoding=UTF-8
sonar.scm.disabled=true
sonar.sources=src
sonar.exclusions=**/generated_types_*.py,**/node_modules/**/*,**/htmlcov/**/*,**/lcov-report/**/*,**/dist/**/*,**/dist_s3/**/*,**/build/**/*,**/frontend/main-app/src/setupTests.js, src/frontend/slides-app/**
sonar.cpd.exclusions=**/lcov-report/**/*
sonar.coverage.exclusions=**/src/integration-tests/**/*.py,**/generated_types_*.py,**/tests/**/*.py,**/setup.py,**/*.test.ts,**/*.test.tsx,**/*.stories.tsx,**/__mocks__/*.ts*,src/frontend/main-app/src/fixtures,src/**/src/migration/m*.py,src/frontend/**/public/*.js,src/infra/auth0/src/rules/tests/*
sonar.python.coverage.reportPaths=**/coverage.xml
sonar.javascript.lcov.reportPaths=src/frontend/main-app/coverage/lcov.info
1 Like

Hi @hanninen ,

Welcome to the community!

Is your organization bound to GitHub? Do you see the icon of the GitHub near your org name in the UI ?image

About the properties you are missing two: sonar.pullrequest.github.repository=<your_repo_slug> and sonar.pull.request.provider=GitHub

Best,
Marcin

1 Like