webispy / checkpatch-action

Github action for checkpatch.pl
7 stars 6 forks source link
action c checkpatch checkpatch-action code-review docker kernel lint

Github action for checkpatch.pl

The checkpatch.pl is a perl script to verify that your code conforms to the Linux kernel coding style. This project uses checkpatch.pl to automatically review and leave comments on pull requests.

Screenshots

Result of checkpatch

check

Code annotations

annotations

You can also check the comments directly in the console log.

console log

Action setup guide

Pull Request

.github/workflows/main.yml

name: checkpatch review
on: [pull_request]
jobs:
  my_review:
    name: checkpatch review
    runs-on: ubuntu-latest
    steps:
    - name: 'Calculate PR commits + 1'
      run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> $GITHUB_ENV
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.event.pull_request.head.sha }}
        fetch-depth: ${{ env.PR_FETCH_DEPTH }}
    - name: Run checkpatch review
      uses: webispy/checkpatch-action@v9

For using a custom checkpatch script, pass the CHECKPATCH_COMMAND environment variable. For example, for DPDK's checkpatches.sh script use:

name: checkpatch review
on: [pull_request]
jobs:
  my_review:
    name: checkpatch review
    runs-on: ubuntu-latest
    steps:
    - name: 'Calculate PR commits + 1'
      run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> $GITHUB_ENV
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.event.pull_request.head.sha }}
        fetch-depth: ${{ env.PR_FETCH_DEPTH }}
    - name: Run DPDK checkpatches.sh review
      uses: webispy/checkpatch-action@v9
      env:
        DPDK_CHECKPATCH_PATH: /usr/bin/checkpatch.pl
        CHECKPATCH_COMMAND: ./devtools/checkpatches.sh

Note: For private repositories this action needs access to the GITHUB_TOKEN. It needs read access to contents and pull-requests as minimum permissions. For example:

name: checkpatch review
on: [pull_request]
jobs:
  my_review:
    name: checkpatch review
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: read
    steps:
    - name: 'Calculate PR commits + 1'
      run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> $GITHUB_ENV
    - uses: actions/checkout@v3
      with:
        ref: ${{ github.event.pull_request.head.sha }}
        fetch-depth: ${{ env.PR_FETCH_DEPTH }}
    - name: Run checkpatch review
      uses: webispy/checkpatch-action@v9
      env:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

checkpatch.pl configuration

The checkpatch.pl tool supports a configuration file for setting options. Just create a .checkpatch.conf file in the top-level directory of your project and specify options in it.

https://docs.kernel.org/dev-tools/checkpatch.html#type-descriptions

Example for .checkpatch.conf file

# This isn't actually a Linux kernel tree
--no-tree

--ignore CONFIG_DESCRIPTION
--ignore FILE_PATH_CHANGES
--ignore GERRIT_CHANGE_ID
--ignore GIT_COMMIT_ID
--ignore NEW_TYPEDEFS
--ignore SPDX_LICENSE_TAG
--ignore SPACING
--ignore CONST_STRUCT
--ignore EMBEDDED_FUNCTION_NAME
--exclude externals
--exclude examples

References

checkpatch tool

Following files are used to this project.

Patch

Add option for excluding directories

From zephyr project:

Disable warning for "No structs that should be const ..."

Docker image

You can find the Dockerfile from docker branch of this repository.

License

The checkpatch.pl file is a script in the Linux kernel source tree, so checkpatch-action projects and forked projects must comply with the GPL-2.0 license (kernel license).