Giter Site home page Giter Site logo

leonardocarreras / sonarcloud-github-c-cpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sonarsource/sonarcloud-github-c-cpp

0.0 0.0 0.0 153 KB

Integrate SonarCloud code analysis to GitHub Actions when build wrapper or relative paths support is required. Use https://github.com/SonarSource/sonarcloud-github-action otherwise

License: GNU Lesser General Public License v3.0

Shell 100.00%

sonarcloud-github-c-cpp's Introduction

Analyze your code for free with SonarCloud

This SonarSource project, available as a GitHub Action, helps you configure and scan your C, C++, and Objective-C projects with SonarCloud, to produce Clean Code.

SonarCloud is a widely used static analysis solution for continuous code quality and security inspection. It helps developers identify and fix issues in their code that could lead to bugs, vulnerabilities, or decreased development velocity. SonarCloud supports the most popular programming languages, including Java, JavaScript, TypeScript, C#, Python, C, C++, and many more.

Requirements

  • Create your account on SonarCloud. Sign up for free now if it's not already the case! SonarCloud Sign Up
  • The repository to analyze is set up on SonarCloud. Set it up in just one click.

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.organization=<replace with your SonarCloud organization key>
sonar.projectKey=<replace with the key generated when setting up the project on SonarCloud>

# relative paths to source directories. More details and properties are described
# in https://sonarcloud.io/documentation/project-administration/narrowing-the-focus/
sonar.sources=.

The workflow, usually declared in .github/workflows/build.yml, looks like:

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:
  sonarcloud:
    runs-on: ubuntu-latest
    env:
      BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
    steps:
    - uses: actions/checkout@v3
      with:
        # Disabling shallow clone is recommended for improving relevancy of reporting
        fetch-depth: 0
    - name: Install sonar-scanner and build-wrapper
      uses: sonarsource/sonarcloud-github-c-cpp@v2
    - name: Run build-wrapper
      run: |
      #here goes your compilation wrapped with build-wrapper; See https://docs.sonarcloud.io/advanced-setup/languages/c-c-objective-c/#analysis-steps-using-build-wrapper for more information
      # build-preparation steps
      # build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} build-command
    - name: Run sonar-scanner
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
      run: sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" #Consult https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarscanner-cli/ for more information and options

You can change the build-wrapper and sonar-scanner installation path by using the optional input installation-path like this:

uses: sonarsource/sonarcloud-github-c-cpp@v2
with:
  installation-path: my/custom/directory/path

Also, the absolute paths to the installed build-wrapper and sonar-scanner binaries are returned as outputs from the action.

Moreover, by default the action will cache sonar-scanner installation. However, you can disable caching by using the optional input: cache-binaries like this:

uses: sonarsource/sonarcloud-github-c-cpp@v2
with:
  cache-binaries: false

See also example configurations

Secrets

Following secrets are required for successful invocation of sonar-scanner:

  • SONAR_TOKEN โ€“ Required this is the token used to authenticate access to SonarCloud. You can generate a token on your Security page in SonarCloud. You can set the SONAR_TOKEN environment variable in the "Secrets" settings page of your repository.
  • GITHUB_TOKEN โ€“ Provided by Github (see Authenticating with the GITHUB_TOKEN).

Example of pull request analysis

Want to see more examples of SonarCloud in action? You can explore current Open Source projects in SonarCloud that are using the Clean as You Code methodology.

Do not use this GitHub action if you are in the following situations

  • You want to analyze code written in a language other than C or C++. Use SonarCloud GitHub Action instead
  • You want to run the action on a 32-bits system - build wrappers support only 64-bits OS

Additional information

This action installs coreutils if run on macOS

Have question or feedback?

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

License

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

sonarcloud-github-c-cpp's People

Contributors

tomasz-kaminski-sonarsource avatar anita-stanisz-sonarsource avatar claire-villard-sonarsource avatar nawar-hamo-sonarsource avatar tomverin avatar bogdanakushnir avatar github-actions[bot] avatar n-coder avatar vil02 avatar tom-vanbraband-sonarsource avatar enzo-pellegrini 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.