Go to file
Trabelsi Tobias 7295e71c95 REL-2179 update base image 2022-02-22 15:09:40 +01:00
.github fix(BUILD-1287): add repository owner 2022-02-02 18:58:14 +01:00
images Update README.md 2021-05-18 09:37:58 +02:00
test Test fail-fast strategies as well 2021-05-17 10:59:33 +02:00
.gitignore SONAR-14822 Provide a GitHub Action to scan a project 2021-05-14 10:14:11 +02:00
Dockerfile REL-2179 update base image 2022-02-22 15:09:40 +01:00
LICENSE.txt SONAR-14822 Provide a GitHub Action to scan a project 2021-05-14 10:14:11 +02:00
README.md Docker-10 document locales and remove ANSI locale to use the one from the parent image 2021-09-24 08:03:04 +02:00
action.yml Update action.yml 2021-05-17 08:28:26 +02:00
contributing.md Updating contributing md 2021-06-25 10:55:16 +02:00
entrypoint.sh SONAR-14822 Provide a GitHub Action to scan a project 2021-05-14 10:14:11 +02:00

Scan your code with SonarQube QA

Using this GitHub Action, scan your code with SonarQube to detects Bugs, Vulnerabilities and Code Smells in up to 27 programming languages!

SonarQube is the leading product for Continuous Code Quality & Code Security. It supports most popular programming languages, including Java, JavaScript, TypeScript, C#, Python, C, C++, and many more.

Requirements

To run an analysis on your code, you first need to set up your project on SonarQube. Your SonarQube instance must be accessible from GitHub, and you will need an access token to run the analysis (more information below under Environment variables).

Read more information on how to analyze your code here.

Usage

Project metadata, including the location to the sources to be analyzed, must be declared in the file sonar-project.properties in the base directory:

sonar.projectKey=<replace with the key generated when setting up the project on SonarQube>

# relative paths to source directories. More details and properties are described
# in https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/ 
sonar.sources=.

The workflow YAML file will usually look something like this:

on:
  # Trigger analysis when pushing in master or pull requests, and when creating
  # a pull request. 
  push:
    branches:
      - master
  pull_request:
      types: [opened, synchronize, reopened]

name: Main Workflow
jobs:
  sonarqube:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        # Disabling shallow clone is recommended for improving relevancy of reporting
        fetch-depth: 0
    - name: SonarQube Scan
      uses: sonarsource/sonarqube-scan-action@master
      env:
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

If your source code file names contain special characters that are not covered by the locale range of en_US.UTF-8, you can configure your desired locale like this:

    - name: SonarQube Scan
      uses: sonarsource/sonarqube-scan-action@master
      env:
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
        LC_ALL: "ru_RU.UTF-8"

You can change the analysis base directory by using the optional input projectBaseDir like this:

- name: SonarQube Scan
  uses: sonarsource/sonarqube-scan-action@master
  with:
    projectBaseDir: app/src

In case you need to add additional analysis parameters, and you do not wish to set them in the sonar-project.properties file, you can use the args option:

- name: SonarQube Scan
  uses: sonarsource/sonarqube-scan-action@master
  with:
    projectBaseDir: app/src
    args: >
      -Dsonar.python.coverage.reportPaths=coverage.xml
      -Dsonar.tests=tests/
      -Dsonar.verbose=true      

More information about possible analysis parameters can be found in the documentation.

Environment variables

  • SONAR_TOKEN Required this is the token used to authenticate access to SonarQube. You can read more about security tokens here. You can set the SONAR_TOKEN environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended).
  • SONAR_HOST_URL Required this tells the scanner where SonarQube is hosted. You can set the SONAR_HOST_URL environment variable in the "Secrets" settings page of your repository, or you can add them at the level of your GitHub organization (recommended).

Alternatives for Java, .NET, and C/C++ projects

This GitHub Action will not work for all technologies. If you are in one of the following situations, you should use the following alternatives:

Have question or feedback?

To provide feedback (requesting a feature or reporting a bug) please post on the SonarSource Community Forum.

License

The Dockerfile and associated scripts and documentation in this project are released under the LGPLv3 License.

Container images built with this project include third party materials.