Code Monkey home page Code Monkey logo

sonarqube-quality-gate-action's Introduction

SonarQube Quality Gate check QA

Check the Quality Gate of your code with SonarQube to ensure your code meets your own quality standards before you release or deploy new features.

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

A previous step must have run an analysis on your code.

Read more information on how to analyze your code here

Usage

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

    # Triggering SonarQube analysis as results of it are required by Quality Gate check.
    - name: SonarQube Scan
      uses: sonarsource/sonarqube-scan-action@master
      env:
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

    # Check the Quality Gate status.
    - name: SonarQube Quality Gate check
      id: sonarqube-quality-gate-check
      uses: sonarsource/sonarqube-quality-gate-action@master
      # Force to fail step after specific time.
      timeout-minutes: 5
      env:
       SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
       SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} #OPTIONAL

    # Optionally you can use the output from the Quality Gate in another step.
    # The possible outputs of the `quality-gate-status` variable are `PASSED`, `WARN` or `FAILED`.
    - name: "Example show SonarQube Quality Gate Status value"
      run: echo "The Quality Gate status is ${{ steps.sonarqube-quality-gate-check.outputs.quality-gate-status }}"

Make sure to set up timeout-minutes property in your step, to avoid wasting action minutes per month (see above example).

When using this action with sonarsource/sonarqube-scan action or with C/C++ code analysis you don't have to provide scanMetadataReportFile input, otherwise you should alter the location of it.

Typically, report metadata file for different scanners can vary and can be located in:

  • target/sonar/report-task.txt for Maven projects
  • build/sonar/report-task.txt for Gradle projects
  • .sonarqube/out/.sonar/report-task.txt for .NET projects

Example usage:

- name: SonarQube Quality Gate check
  uses: sonarsource/sonarqube-quality-gate-action@master
  with:
    scanMetadataReportFile: target/sonar/report-task.txt

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 โ€“ Optional this tells the scanner where SonarQube is hosted, otherwise it will get the one from the scan report. 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).

Quality Gate check run

Have questions or feedback?

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

License

Scripts and documentation in this project are released under the LGPLv3 License.

sonarqube-quality-gate-action's People

Contributors

jacek-poreda-sonarsource avatar julien-carsique-sonarsource avatar wouter-admiraal-sonarsource avatar aldass avatar lemosd-ppb avatar lukasz-jarocki-sonarsource avatar belen-pruvost-sonarsource avatar

Stargazers

Roman avatar Roshan Patil avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.