An open API service indexing awesome lists of open source software.

https://github.com/webispy/checkpatch-action

Github action for checkpatch.pl
https://github.com/webispy/checkpatch-action

action c checkpatch checkpatch-action code-review docker kernel lint

Last synced: about 1 month ago
JSON representation

Github action for checkpatch.pl

Awesome Lists containing this project

README

        

# 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](https://raw.githubusercontent.com/wiki/webispy/checkpatch-action/img/action_conversation_check.png)

### Code annotations

![annotations](https://raw.githubusercontent.com/wiki/webispy/checkpatch-action/img/action_annotations.png)

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

![console log](https://raw.githubusercontent.com/wiki/webispy/checkpatch-action/img/action_console.png)

## Action setup guide

### Pull Request

.github/workflows/main.yml

```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:

```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 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:

```yml
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.

#### Example for `.checkpatch.conf` file

```text
# 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](https://github.com/zephyrproject-rtos/zephyr) project:

-

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

-

### Docker image

You can find the Dockerfile from [docker](https://github.com/webispy/checkpatch-action/tree/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).