All Projects → platisd → clang-tidy-pr-comments

platisd / clang-tidy-pr-comments

Licence: MIT License
Turn clang-tidy warnings and fixes to comments in your pull request

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to clang-tidy-pr-comments

Code Review Checklist
This code review checklist helps you be a more effective and efficient code reviewer.
Stars: ✭ 214 (+791.67%)
Mutual labels:  code-review, code-quality, pull-requests
Reviewdog
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language
Stars: ✭ 4,541 (+18820.83%)
Mutual labels:  code-review, code-quality
qodana-action
⚙️ Scan your Java, Kotlin, PHP, Python, JavaScript, TypeScript projects at GitHub with Qodana
Stars: ✭ 112 (+366.67%)
Mutual labels:  code-review, code-quality
effective-code-review
Presentation about my process for making code reviews as effective as possible
Stars: ✭ 63 (+162.5%)
Mutual labels:  code-review, code-quality
quickreview-for-github
Reviewing 50+ Pull Requests a day is no fun. Automate it with keyboard shortcuts.
Stars: ✭ 28 (+16.67%)
Mutual labels:  code-review, pull-requests
localhost-sonarqube
Analysing source code locally with SonarQube in a Docker environment.
Stars: ✭ 17 (-29.17%)
Mutual labels:  code-review, code-quality
Vscode Pull Request Github
GitHub Pull Requests for Visual Studio Code
Stars: ✭ 1,769 (+7270.83%)
Mutual labels:  code-review, pull-requests
sonarqube-action
Integrate SonarQube scanner to GitHub Actions
Stars: ✭ 90 (+275%)
Mutual labels:  code-review, code-quality
clang-tidy-review
Create a pull request review based on clang-tidy warnings
Stars: ✭ 33 (+37.5%)
Mutual labels:  code-review, clang-tidy
inline-plz
Inline your lint messages
Stars: ✭ 32 (+33.33%)
Mutual labels:  code-review, code-quality
critiq.vim
Github code reviews from Neovim
Stars: ✭ 69 (+187.5%)
Mutual labels:  code-review, pull-requests
auto-request-review
A GitHub Action that automatically requests review of a pull request based on files changes and/or groups the author belongs to 🤖
Stars: ✭ 52 (+116.67%)
Mutual labels:  code-review, pull-requests
flake8-broken-line
🚨 Flake8 plugin to forbid backslashes (\) for line breaks
Stars: ✭ 85 (+254.17%)
Mutual labels:  code-quality
Hacktoberfest-Flutter
For all the Flutter developers out there make your first Pull Request and earn a free Tee from GitHub!
Stars: ✭ 89 (+270.83%)
Mutual labels:  pull-requests
codeclimate-eslint
Code Climate Engine for ESLint
Stars: ✭ 86 (+258.33%)
Mutual labels:  code-quality
vet
Gerrit client using pull request workflow
Stars: ✭ 21 (-12.5%)
Mutual labels:  pull-requests
TyScan
A command-line tool for scanning TypeScript code
Stars: ✭ 19 (-20.83%)
Mutual labels:  code-review
pull-request-comment-branch
A GitHub Action to get the head ref and sha of a pull request comment
Stars: ✭ 21 (-12.5%)
Mutual labels:  pull-requests
stack-attack
A WIP CLI tool that manages stacked pull requests. Using stacked PRs is now (many small) pieces of cake
Stars: ✭ 39 (+62.5%)
Mutual labels:  pull-requests
backup-github-repo
Backup all the issues and pull requests of a Github repo, including the comments, events, and labels, as JSON and as HTML
Stars: ✭ 31 (+29.17%)
Mutual labels:  pull-requests

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

Table of contents

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). You can generate a YAML report that includes fixes for a pull request using the following methods:

    • Using the run-clang-tidy utility script with the -export-fixes argument. This script usually comes with the clang-tidy packages. You can use it to run checks for the entire codebase of a project at once.

    • Using the clang-tidy-diff utility script with the -export-fixes argument. This script also usually comes with the clang-tidy packages, and and it can be used to run checks only for code fragments that have been changed in a specific pull request.

    • Alternatively, you may use --export-fixes with clang-tidy itself in your own script.

    In any case, specify the path where you would like the report to be exported. The very same path should be supplied to this 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.

  • This Action respects existing comments and doesn't repeat the same warnings for the same line (no spam).

  • This Action allows analysis to be performed separately from the posting of the analysis results (using separate workflows with different privileges), which allows you to safely analyze pull requests from forks (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.

Basic configuration example

A basic configuration for the platisd/clang-tidy-pr-comments action (for a CMake-based project using the clang-tidy-diff script) can be seen below:

name: Static analysis

on: pull_request

jobs:
  clang-tidy:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2
    - name: Install clang-tidy
      run: |
        sudo apt-get update
        sudo apt-get install -y clang-tidy
    - name: Prepare compile_commands.json
      run: |
        cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
    - name: Create results directory
      run: |
        mkdir clang-tidy-result
    - name: Analyze
      run: |
        git diff -U0 HEAD^ | clang-tidy-diff -p1 -path build -export-fixes clang-tidy-result/fixes.yml
    - 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: clang-tidy-result/fixes.yml
        # 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

Triggering this Action manually

If you want to trigger this 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: Install clang-tidy
      run: |
        sudo apt-get update
        sudo apt-get install -y clang-tidy
    - name: Prepare compile_commands.json
      run: |
        cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
    - name: Create results directory
      run: |
        mkdir clang-tidy-result
    - name: Analyze
      run: |
        git diff -U0 HEAD^ | clang-tidy-diff -p1 -path build -export-fixes clang-tidy-result/fixes.yml
    - name: Run clang-tidy-pr-comments action
      uses: platisd/clang-tidy-pr-comments@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        clang_tidy_fixes: clang-tidy-result/fixes.yml

Using this Action to safely perform analysis of pull requests from forks

If you want to trigger this Action using the workflow_run event to run analysis on pull requests from forks in a secure manner, then you can use the following combination of workflows:

# Insecure workflow with limited permissions that should provide analysis results through an artifact
name: Static analysis

on: pull_request

jobs:
  clang-tidy:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2
    - name: Install clang-tidy
      run: |
        sudo apt-get update
        sudo apt-get install -y clang-tidy
    - name: Prepare compile_commands.json
      run: |
        cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
    - name: Create results directory
      run: |
        mkdir clang-tidy-result
    - name: Analyze
      run: |
        git diff -U0 HEAD^ | clang-tidy-diff -p1 -path build -export-fixes clang-tidy-result/fixes.yml
    - name: Save PR metadata
      run: |
        echo ${{ github.event.number }} > clang-tidy-result/pr-id.txt
        echo ${{ github.event.pull_request.head.repo.full_name }} > clang-tidy-result/pr-head-repo.txt
        echo ${{ github.event.pull_request.head.ref }} > clang-tidy-result/pr-head-ref.txt
    - uses: actions/upload-artifact@v2
      with:
        name: clang-tidy-result
        path: clang-tidy-result/
# Secure workflow with access to repository secrets and GitHub token for posting analysis results
name: Post the static analysis results

on:
  workflow_run:
    workflows: [ "Static analysis" ]
    types: [ completed ]

jobs:
  clang-tidy-results:
    # Trigger the job only if the previous (insecure) workflow completed successfully
    if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
    runs-on: ubuntu-20.04
    steps:
    - name: Download analysis results
      uses: actions/[email protected]
      with:
        script: |
          let artifacts = await github.actions.listWorkflowRunArtifacts({
              owner: context.repo.owner,
              repo: context.repo.repo,
              run_id: ${{github.event.workflow_run.id }},
          });
          let matchArtifact = artifacts.data.artifacts.filter((artifact) => {
              return artifact.name == "clang-tidy-result"
          })[0];
          let download = await github.actions.downloadArtifact({
              owner: context.repo.owner,
              repo: context.repo.repo,
              artifact_id: matchArtifact.id,
              archive_format: "zip",
          });
          let fs = require("fs");
          fs.writeFileSync("${{github.workspace}}/clang-tidy-result.zip", Buffer.from(download.data));
    - name: Set environment variables
      run: |
        mkdir clang-tidy-result
        unzip clang-tidy-result.zip -d clang-tidy-result
        echo "pr_id=$(cat clang-tidy-result/pr-id.txt)" >> $GITHUB_ENV
        echo "pr_head_repo=$(cat clang-tidy-result/pr-head-repo.txt)" >> $GITHUB_ENV
        echo "pr_head_ref=$(cat clang-tidy-result/pr-head-ref.txt)" >> $GITHUB_ENV
    - uses: actions/checkout@v2
      with:
        repository: ${{ env.pr_head_repo }}
        ref: ${{ env.pr_head_ref }}
        persist-credentials: false
    - name: Redownload analysis results
      uses: actions/[email protected]
      with:
        script: |
          let artifacts = await github.actions.listWorkflowRunArtifacts({
              owner: context.repo.owner,
              repo: context.repo.repo,
              run_id: ${{github.event.workflow_run.id }},
          });
          let matchArtifact = artifacts.data.artifacts.filter((artifact) => {
              return artifact.name == "clang-tidy-result"
          })[0];
          let download = await github.actions.downloadArtifact({
              owner: context.repo.owner,
              repo: context.repo.repo,
              artifact_id: matchArtifact.id,
              archive_format: "zip",
          });
          let fs = require("fs");
          fs.writeFileSync("${{github.workspace}}/clang-tidy-result.zip", Buffer.from(download.data));
    - name: Extract analysis results
      run: |
        mkdir clang-tidy-result
        unzip clang-tidy-result.zip -d clang-tidy-result
    - name: Run clang-tidy-pr-comments action
      uses: platisd/clang-tidy-pr-comments@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        clang_tidy_fixes: clang-tidy-result/fixes.yml
        pull_request_id: ${{ env.pr_id }}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].