GithubHelp home page GithubHelp logo

froblesmartin / sonarcloud-github-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sonarsource/sonarcloud-github-action

0.0 0.0 0.0 131 KB

Integrate SonarCloud code analysis to GitHub Actions

License: GNU Lesser General Public License v3.0

Shell 52.72% Dockerfile 47.28%

sonarcloud-github-action's Introduction

Analyze your code for free with SonarCloud

Using this GitHub Action, scan your code with SonarCloud to detects bugs, vulnerabilities and code smells in 26+ programming languages! In case you want to analyze C and C++ code: rely on our SonarCloud Scan for C and C++ and look at our sample C and C++ project

SonarCloud is the leading product for Continuous Code Quality & Code Security online, totally free for open-source projects. It supports all major programming languages, including Java, JavaScript, TypeScript, C#, C and C++, and many more. If your code is closed source, SonarCloud also offers a free, no-commitment 14-day trial to run private analyses. Start your free trial here: SonarCloud Sign up. With SonarCloud, you also get IDE Support with SonarLint integration to find code issues on the fly. SonarCloud rules and analysis settings synchronize to SonarLint, aligning teams around a single standard of Clean Code.

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 of 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
    steps:
    - uses: actions/checkout@v3
      with:
        # Disabling shallow clone is recommended for improving relevancy of reporting
        fetch-depth: 0
    - name: SonarCloud Scan
      uses: sonarsource/sonarcloud-github-action@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

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

uses: sonarsource/sonarcloud-github-action@master
with:
  projectBaseDir: my-custom-directory

In case you need to add additional analysis parameters, you can use the args option:

- name: Analyze with SonarCloud
  uses: sonarsource/sonarcloud-github-action@master
  with:
    projectBaseDir: my-custom-directory
    args: >
      -Dsonar.organization=my-organization
      -Dsonar.projectKey=my-projectkey
      -Dsonar.python.coverage.reportPaths=coverage.xml
      -Dsonar.sources=lib/
      -Dsonar.test.exclusions=tests/**
      -Dsonar.tests=tests/
      -Dsonar.verbose=true

More information about possible analysis parameters is found in the documentation at: https://docs.sonarcloud.io/advanced-setup/analysis-parameters

See also example configurations at: https://github.com/sonarsource/sonarcloud-github-action-samples/

Secrets

  • 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).

Error cleaning up workspace

In some cases, the checkout action may fail to clean up the workspace. This is a known problem for GitHub actions implemented as a docker container (such as sonarcloud-github-actions) when self-hosted runners are used. Example of the error message: File was unable to be removed Error: EACCES: permission denied, unlink '/actions-runner/_work//project/.scannerwork/.sonar_lock' To work around the problem, sonarcloud-github-action attempts to fix the permission of the temporary files that it creates. If that doesn't work, you can manually clean up the workspace by running the following action:

- name: Clean the workspace
  uses: docker://alpine
  with:
    args: /bin/sh -c "find \"${GITHUB_WORKSPACE}\" -mindepth 1 ! -name . -prune -exec rm -rf {} +"

You can find more info here.

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

  • Your code is built with Maven: run 'org.sonarsource.scanner.maven:sonar' during the build
  • Your code is built with Gradle: use the SonarQube plugin for Gradle during the build
  • You want to analyze a .NET solution: Follow our interactive tutorial for GitHub Actions after importing your project directly into SonarCloud
  • You want to analyze C and C++ code: rely on our SonarCloud Scan for C and C++ and look at our sample C and C++ project

Have questions 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 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.

sonarcloud-github-action's People

Contributors

nawar-hamo-sonarsource avatar cody-simms-sonarsource avatar tom-vanbraband-sonarsource avatar bellingard avatar bogdanakushnir avatar lukaszzdanikowski avatar colin-sonarsource avatar nottobe avatar toindev avatar peeter-piegaze-sonarsource avatar workshur avatar legion2 avatar kenhuang avatar julien-carsique-sonarsource avatar javiermonton avatar jairhenrique avatar dbmeneses avatar david-cho-lerat-sonarsource avatar dagwieers avatar antonio-garcia-sonarsource avatar axel3rd 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.