Giter VIP home page Giter VIP logo

clang-tidy-pr-comments's Introduction

clang-tidy pull request comments

clang-tidy-8 support clang-tidy-9 support clang-tidy-10 support clang-tidy-11 support clang-tidy-12 support

A GitHub Action to post clang-tidy warnings and suggestions as review comments on your pull request.

action preview

What

platisd/clang-tidy-pr-comments is a GitHub Action that utilizes the exported fixes of clang-tidy for your C++ project and posts them as code review comments in the related pull request.

If clang-tidy has a concrete recommendation on how you should modify your code to fix the issue that's detected, then it will be presented as a suggested change that can be committed directly. Alternatively, the offending line will be highlighted along with a description of the warning.

The GitHub Action can be configured to request changes if clang-tidy warnings are found or merely leave a comment without blocking the pull request from being merged. It should fail only if it has been misconfigured by you, due to a bug (please contact me if that's the case) or the GitHub API acting up.

Please note the following:

  • It will not run clang-tidy for you. You are responsible for doing that and then supply the Action with the path to your generated report (see examples below).
    Specifically, the YAML report that includes the fixes is generated via the -export-fixes argument to the run-clang-tidy utility script. Alternatively, you may use --export-fixes with clang-tidy itself and then, in both cases, specify the path where you would like the report to be exported.
    The very same path should be supplied to the GitHub Action.
  • It will only comment on files and lines changed in the pull request. This is due to GitHub not allowing comments on other files outside the pull request diff. This means that there may be more warnings in your project. Make sure you fix them before starting to use this Action to ensure new warnings will not be introduced in the future.
  • Having the Action leave comments on every update of the pull request may result in spam. Specifically, existing comments are not taken into consideration and will be repeated every time the Action is triggered, as long as the violation has not been amended. If you see this becoming an issue, consider triggering it manually with a comment instead (see example below).

Supported clang-tidy versions

YAML files containing generated fixes by the following clang-tidy versions are currently supported:

  • clang-tidy-8
  • clang-tidy-9
  • clang-tidy-10
  • clang-tidy-11
  • clang-tidy-12

How

Since this action comments on files changed in pull requests, naturally, it can be only run on pull_request events. That being said, if it happens to be triggered in a different context, e.g. a push event, it will not run and fail softly by returning a success code.

A basic configuration for the platisd/clang-tidy-pr-comments action can be seen below:

name: Static analysis

on: pull_request

jobs:
  clang-tidy:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - name: Build project and/or unit tests
        run: ./your-build-script.sh
      - name: Run clang-tidy
        run: ./your-clang-tidy-script.sh --fixes-path fixes.yaml
      - name: Run clang-tidy-pr-comments action
        uses: platisd/clang-tidy-pr-comments@master
        with:
          # The GitHub token (or a personal access token)
          github_token: ${{ secrets.GITHUB_TOKEN }}
          # The path to the clang-tidy fixes generated previously
          clang_tidy_fixes: fixes.yaml
          # Optionally set to true if you want the Action to request
          # changes in case warnings are found
          request_changes: true
          # Optionally set the number of comments per review
          # to avoid GitHub API timeouts for heavily loaded
          # pull requests
          suggestions_per_comment: 10

If you want to trigger the Action manually, i.e. by leaving a comment with a particular keyword in the pull request, then you can try the following:

name: Static analysis

# Don't trigger it on pull_request events but issue_comment instead
on: issue_comment

jobs:
  clang-tidy:
    # Trigger the job only when someone comments: run_clang_tidy
    if: github.event.issue.pull_request && contains(github.event.comment.body, 'run_clang_tidy')
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - name: Build project and/or unit tests
        run: ./your-build-script.sh
      - name: Run clang-tidy
        run: ./your-clang-tidy-script.sh --fixes-path fixes.yaml
      - name: Run clang-tidy-pr-comments action
        uses: platisd/clang-tidy-pr-comments@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          clang_tidy_fixes: fixes.yaml

clang-tidy-pr-comments's People

Contributors

platisd avatar sommerlukas avatar

Watchers

 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.