Skip to content

Commit

Permalink
docs overhaul (#198)
Browse files Browse the repository at this point in the history
- inputs and outputs are in a dedicated page
- README and docs landing page auto-sync with MD substitutions
- permissions are noted where needed (per feature)
- adds pr-review-caveats doc
- add examples recipes (resolves #195)
- demo folder moved to docs/examples and corresponding CI adjusted
- use readthedocs to build doc previews in PRs
  • Loading branch information
2bndy5 authored Feb 29, 2024
1 parent 176a6b0 commit d4202dc
Show file tree
Hide file tree
Showing 21 changed files with 894 additions and 196 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/cpp-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ name: cpp-linter

on:
push:
paths-ignore: "docs/**"
paths:
- "!**"
- "docs/examples/demo/*"
pull_request:
paths-ignore: "docs/**"
paths:
- "!**"
- "docs/examples/demo/*"


jobs:
cpp-linter:
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ repos:
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-yaml
# special mkdocs config to include inline icons fails (see `pymdownx.emoji` in mkdocs.yml)
args: ['--unsafe'] # use `--unsafe` to workaround yaml loading
- id: requirements-txt-fixer
19 changes: 19 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Read the Docs configuration file for MkDocs projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"

mkdocs:
configuration: mkdocs.yml

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt
224 changes: 48 additions & 176 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<!--intro-start-->
[file-annotations]: https://cpp-linter.github.io/cpp-linter-action/inputs-outputs/#file-annotations
[thread-comments]: https://cpp-linter.github.io/cpp-linter-action/inputs-outputs/#thread-comments
[step-summary]: https://cpp-linter.github.io/cpp-linter-action/inputs-outputs/#step-summary
[tidy-review]: https://cpp-linter.github.io/cpp-linter-action/inputs-outputs/#tidy-review
[format-review]: https://cpp-linter.github.io/cpp-linter-action/inputs-outputs/#format-review

[io-doc]: https://cpp-linter.github.io/cpp-linter-action/inputs-outputs
[recipes-doc]: https://cpp-linter.github.io/cpp-linter-action/examples

[format-annotations-preview]: https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/annotations-clang-format.png
[tidy-annotations-preview]: https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/annotations-clang-tidy.png
[thread-comment-preview]: https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/comment.png
[step-summary-preview]: https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/step-summary.png
[tidy-review-preview]: https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/tidy-review.png
[format-review-preview]: https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/format-review.png
[format-suggestion-preview]: https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/format-suggestion.png

<!--README-start-->

# C/C++ Linter Action <sub><sup>| clang-format & clang-tidy</sup></sub>

Expand All @@ -8,7 +25,11 @@
[![MkDocs Deploy](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/mkdocs-deploy.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/mkdocs-deploy.yml)
![GitHub](https://img.shields.io/github/license/cpp-linter/cpp-linter-action?label=license&logo=github)

A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of [`file-annotations`](#file-annotations), [`thread-comments`](#thread-comments), workflow [`step-summary`](#step-summary), and Pull Request reviews (with [`tidy-review`](#tidy-review) or [`format-review`](#format-review)).
A Github Action for linting C/C++ code integrating clang-tidy and clang-format
to collect feedback provided in the form of
[`file-annotations`][file-annotations], [`thread-comments`][thread-comments],
workflow [`step-summary`][step-summary], and Pull Request reviews (with
[`tidy-review`][tidy-review] or [`format-review`][format-review]).

> [!WARNING]
> We only support Linux runners using a Debian based Linux OS (like Ubuntu and many others).
Expand Down Expand Up @@ -41,218 +62,69 @@ Create a new GitHub Actions workflow in your project, e.g. at [.github/workflows
The content of the file should be in the following format.

```yaml
name: cpp-linter

on: pull_request

jobs:
cpp-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: cpp-linter/cpp-linter-action@v2
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: file
# The following value will only update a single comment
# in a pull request's thread. Set it to false to disable the comment.
# Set it to true to post a new comment (and delete the old comment).
style: 'file' # Use .clang-format config file
tidy-checks: '' # Use .clang-tidy config file
# only 'update' a single comment in a pull request's thread.
thread-comments: ${{ github.event_name == 'pull_request' && 'update' }}

- name: Fail fast?!
if: steps.linter.outputs.checks-failed > 0
run: echo "Some files failed the linting checks!"
# for actual deployment
# run: exit 1
run: exit 1
```
### Optional Inputs

#### `style`

- **Description**: The style rules to use.
- Set this to 'file' to have clang-format use the closest relative .clang-format file.
- Set this to a blank string (`''`) to disable the use of clang-format entirely.
- Any code style supported by the specified version of clang-format.
- Default: 'llvm'

#### `extensions`

- **Description**: The file extensions to run the action against. This is a comma-separated string.
- Default: 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx'

#### `tidy-checks`

- **Description**: Comma-separated list of globs with optional `-` prefix. Globs are processed in order of appearance in the list. Globs without `-` prefix add checks with matching names to the set, globs with the `-` prefix remove checks with matching names from the set of enabled checks. This option's value is appended to the value of the 'Checks' option in a .clang-tidy file (if any).
- It is possible to disable clang-tidy entirely by setting this option to `'-*'`.
- It is also possible to rely solely on a .clang-tidy config file by specifying this option as a blank string (`''`).
- Default: 'boost-\*,bugprone-\*,performance-\*,readability-\*,portability-\*,modernize-\*,clang-analyzer-\*,cppcoreguidelines-\*'

#### `repo-root`

- **Description**: The relative path to the repository root directory. This path is relative to the path designated as the runner's GITHUB_WORKSPACE environment variable.
- Default: '.'

#### `version`

- **Description**: The desired version of the [clang-tools](https://github.com/cpp-linter/clang-tools-pip) to use. Accepted options are strings which can be 17, 16, 15, 14, 13, 12, 11, 10, 9, 8 or 7.
- Set this option to a blank string (`''`) to use the platform's default installed version.
- This value can also be a path to where the clang tools are installed (if using a custom install location).
- Default: '12'

#### `verbosity`

- **Description**: This controls the action's verbosity in the workflow's logs. Supported options are `info` or `debug`. This option does not affect the verbosity of resulting thread comments or file annotations.
- The verbosity can also be engaged by enabling debug logs when [re-running jobs or workflows](https://docs.github.com/en/actions/managing-workflow-runs/re-running-workflows-and-jobs).
- Default: 'info'

#### `lines-changed-only`

- **Description**: This controls what part of the files are analyzed. The following values are accepted:
- false: All lines in a file are analyzed.
- true: Only lines in the diff that contain additions are analyzed.
- diff: All lines in the diff are analyzed (including unchanged lines but not subtractions).
- Default: false.

#### `files-changed-only`

- **Description**: Set this option to false to analyze any source files in the repo. This is automatically enabled if lines-changed-only is enabled.
- Default: true
- NOTE: The `GITHUB_TOKEN` should be supplied when running on a private repository with this option enabled, otherwise the runner does not not have the privilege to list changed files for an event. See [Authenticating with the GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow)

#### `ignore`

- **Description**: Set this option with string of path(s) to ignore.
- In the case of multiple paths, you can use a pipe character (`|`)
to separate the multiple paths. Multiple lines are forbidden as an input to this option; it must be a single string.
- This can also have files, but the file's relative path has to be specified
as well.
- There is no need to use `./` for each entry; a blank string (`''`) represents
the repo-root path (specified by the `repo-root` input option).
- Submodules are automatically ignored. Hidden directories (beginning with a `.`) are also ignored automatically.
- Prefix a path with a bang (`!`) to make it explicitly _not_ ignored. The order of
multiple paths does _not_ take precedence. The `!` prefix can be applied to
a submodule's path (if desired) but not hidden directories.
- Glob patterns are not supported here. All asterisk characters (`*`) are literal.
- Default: '.github'

#### `thread-comments`

- **Description**: Set this option to true to enable the use of thread comments as feedback. Set this to 'update' to update an existing comment if one exists; the value 'true' will always delete an old comment and post a new one if necessary.
- To use thread comments, the `GITHUB_TOKEN` (provided by Github to each repository) must be declared as an environment
variable. See [Authenticating with the GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow)
- Default: false
- NOTE: If run on a private repository, then this feature is disabled because the GitHub REST API behaves differently for thread comments on a private repository.
For all explanations of our available input parameters and output variables, see our
[Inputs and Outputs document][io-doc].
#### `no-lgtm`

- **Description**: Set this option to true or false to enable or disable the use of a thread comment or pull request review that basically says 'Looks Good To Me' (when all checks pass).
- See [`thread-comments`](#thread-comments), [`tidy-review`](#tidy-review), and [`format-review`](#format-review) options for further details.
- Default: true (meaning no LGTM comment used)

#### `step-summary`

- **Description**: Set this option to true to append content as part of workflow's job summary.
- See implementation details in GitHub's documentation about
[Adding a job summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary).
This option is independent of the [`thread-comments`](#thread-comments) option, rather this option uses the same content that the [`thread-comments`](#thread-comments) option would use.
- Note: The [`no-lgtm`](#no-lgtm) option is _not_ applied to step summaries.
- Default: false

#### `file-annotations`

- **Description**: Set this option to false to disable the use of file annotations as feedback.
- Default: true

#### `database`

- **Description**: The directory containing compilation database (like compile_commands.json) file.
- Default: ''

#### `extra-args`

- **Description**: A string of extra arguments passed to clang-tidy for use as compiler arguments (like `-std=c++14 -Wall`).
- Default: ''

#### `tidy-review`

**Beta feature** 🚧

- **Description**: Set this option to true to enable Pull Request reviews from clang-tidy.
- To use Pull Request reviews, the `GITHUB_TOKEN` (provided by Github to each repository) must be declared as an environment
variable. See [Authenticating with the GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow)
- See also [the PR review feature caveats](https://cpp-linter.github.io/cpp-linter/pr_review_caveats.html)
- Note: The [`no-lgtm`](#no-lgtm) option is applicable to Pull Request reviews.
- Default: false

#### `format-review`

- **Description**: Set this option to true to enable Pull Request reviews from clang-format.
- To use Pull Request reviews, the `GITHUB_TOKEN` (provided by Github to each repository) must be declared as an environment
variable. See [Authenticating with the GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow)
- See also [the PR review feature caveats](https://cpp-linter.github.io/cpp-linter/pr_review_caveats.html)
- Note: The [`no-lgtm`](#no-lgtm) option is applicable to Pull Request reviews.
- Default: false

### Outputs

This action creates 3 output variables. Even if the linting checks fail for source files this action will still pass, but users' CI workflows can use this action's outputs to exit the workflow early if that is desired.

#### `checks-failed`

The total number of concerns raised by both clang-format and clang-tidy.

#### `clang-tidy-checks-failed`

The total number of concerns raised by clang-tidy only.

#### `clang-format-checks-failed`

The total number of concerns raised by clang-format only.
See also our [example recipes][recipes-doc].
## Example
<!--intro-end-->

### Annotations
Using [`file-annotations`](#file-annotations):
Using [`file-annotations`][file-annotations]:

#### clang-format annotations

![clang-format annotations](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/annotations-clang-format.png)
![clang-format annotations][format-annotations-preview]

#### clang-tidy annotations

![clang-tidy annotations](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/annotations-clang-tidy.png)
![clang-tidy annotations][tidy-annotations-preview]

### Thread Comment

Using [`thread-comments`](#thread-comments):
Using [`thread-comments`][thread-comments]:

![sample comment](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/comment.png)
![sample thread-comment][thread-comment-preview]

### Step Summary

Using [`step-summary`](#step-summary):
Using [`step-summary`][step-summary]:

![step summary](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/step-summary.png)
![step summary][step-summary-preview]

### Pull Request Review

Using only clang-tidy ([`tidy-review`](#tidy-review)):
#### Only clang-tidy

Using [`tidy-review`][tidy-review]:

![sample tidy-review][tidy-review-preview]

![sample tidy-review](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/tidy-review.png)
#### Only clang-format

Using only clang-format ([`format-review`](#format-review)):
Using [`format-review`][format-review]:

![sample format-review](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/format-review.png)
![sample format-review][format-review-preview]

![sample tidy-review](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/format-suggestion.png)
![sample format-suggestion][format-suggestion-preview]

<!--footer-start-->

## Add C/C++ Linter Action badge in README

Expand All @@ -274,4 +146,4 @@ To provide feedback (requesting a feature or reporting a bug) please post to [is

The scripts and documentation in this project are released under the [MIT License](https://github.com/cpp-linter/cpp-linter-action/blob/main/LICENSE)

<!--footer-end-->
<!--README-end-->
Loading

1 comment on commit d4202dc

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format reports: 2 file(s) not formatted
  • src/demo.cpp
  • src/demo.hpp
clang-tidy reports: 6 concern(s)

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.