Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8da68c8

Browse files
authored
Check all files (#26)
* initial attempt (#25) * change test action to my branch * adjust workflow triggers * try log grouping with logger.critical() * change logger's format * don't upgrade pip; test some new features * test fake submodule; show me args.ignore on boot * considering alternate fmt for ignore option * remove fake submodule (it worked); * action inputs can't take a sequence; delimit by \n * specifying `--ignore` better * fix exit early when no files found * list_source_files() is malfunctioning??? * Revert "list_source_files() is malfunctioning???" This reverts commit 59522e0. * is ignore option causing malfunction? * show me what paths are being skipped * show me which paths are crawled * show me which files are considered as src files * show me comparison of ignored paths * change done debug statements * fix debugging statement in is_file_ignored() * skip comparing empty strings in ignored paths * maybe a bug about ignoring root dir * try getting python latest from src * python src build needs deps. revert to apt build * try using tojson() * bad yml fmt * try a different json approach * make yml array an explicit str * try forcing it as a py list * abandon json idea * try new log_cmder and !ignore prefix * need to separate a single str into multi args * use pipe char as delimiters * slightly different approach to passing ignore val * might need to switch to 1 line of input * how to handle spaces in a path among multiple * no need to escape quotes * fix debug prompts; and workflow-triggered paths * fix cpp-linter-test action's triggered paths * check action stil works without using new features * try log cmds to annotate * try abbotations again * use a long unlikely string as default ignore * try annotating with line and columns * try \n with minimal parameters * does file need changes to show annotation? * use html <br> and line's columns * trigger annotations * adjust annotation's output * try CRLF * simply can't use mult-line annotation msg * almost ready for PR * use proper casing in chosen style name * adjust last commit for GNU style as well * remove artifact * we don't need the `re` module anymore * new thread-comments option; update docs & README * avoid duplicate clang-tidy comments * [no ci] proofread README * Fix indent in root README for mkdocs * Use sub-headings instead of list points in README * reviewed errors in docs * switch test workflow to upstream action
1 parent aa399e7 commit 8da68c8

File tree

15 files changed

+495
-123
lines changed

15 files changed

+495
-123
lines changed

‎.github/workflows/cpp-linter.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ name: cpp-linter
22

33
on:
44
push:
5+
paths-ignore: "docs/**"
56
pull_request:
7+
paths-ignore: "docs/**"
68

79
jobs:
810
cpp-linter:
@@ -15,6 +17,9 @@ jobs:
1517
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1618
with:
1719
style: file
20+
files-changed-only: false
21+
# to ignore all demo folder contents except for demo.cpp
22+
# ignore: demo|!demo/demo.cpp
1823

1924
- name: Fail fast?!
2025
if: steps.linter.outputs.checks-failed > 0

‎.github/workflows/run-pylint.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
name: "Check python code"
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
paths:
6+
- "**.py"
7+
- .pylintrc
8+
pull_request:
9+
types: opened
10+
paths:
11+
- "**.py"
12+
- .pylintrc
413

514
jobs:
615
using-pylint:

‎.gitignore‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# local demo specific
2-
.cpp_linter_action_changed_files.json
2+
.changed_files.json
33
clang_format*.txt
44
clang_tidy*.txt
55
act.exe
@@ -180,4 +180,3 @@ CPackConfig.cmake
180180
CPackSourceConfig.cmake
181181
CMakeFiles
182182
cmake_install.cmake
183-
# compile_commands.json

‎Dockerfile‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@ LABEL maintainer="shenxianpeng <20297606+shenxianpeng@users.noreply.github.com>"
1414

1515
RUN apt-get update
1616
RUN apt-get -y install python3-pip
17-
RUN python3 -m pip install --upgrade pip
18-
# curl jq
17+
# RUN python3 -m pip install --upgrade pip
1918

20-
# COPY runchecks.sh /entrypoint.sh
21-
# RUN chmod +x /entrypoint.sh
22-
COPY python_action/ /pkg/python_action/
23-
COPY setup.py /pkg/setup.py
24-
RUN python3 -m pip install /pkg/
19+
COPY python_action/ pkg/python_action/
20+
COPY setup.py pkg/setup.py
21+
RUN python3 -m pip install pkg/
2522

2623
# github action args use the CMD option
2724
# See https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsargs
2825
# also https://docs.docker.com/engine/reference/builder/#cmd
29-
# ENTRYPOINT [ "/entrypoint.sh" ]
3026
ENTRYPOINT [ "python3", "-m", "python_action.run" ]

‎README.md‎

Lines changed: 79 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/shenxianpeng/cpp-linter-action)
99
[![cpp-linter](https://github.com/shenxianpeng/cpp-linter-action/actions/workflows/cpp-linter.yml/badge.svg)](https://github.com/shenxianpeng/cpp-linter-action/actions/workflows/cpp-linter.yml)
1010
![GitHub](https://img.shields.io/github/license/shenxianpeng/cpp-linter-action?label=license)
11-
[![Documentation Status](https://readthedocs.org/projects/cpp-linter-action/badge/?version=latest)](https://cpp-linter-action.readthedocs.io/en/latest/?badge=latest)
11+
[![Dev Docs Status](https://readthedocs.org/projects/cpp-linter-action/badge/?version=latest)](https://cpp-linter-action.readthedocs.io/en/latest/?badge=latest)
1212
[![open repo in gitpod](https://img.shields.io/badge/Gitpod-Use%20Online%20IDE-B16C04?logo=gitpod)](https://gitpod.io/#https://github.com/shenxianpeng/cpp-linter-action)
1313

14-
15-
Github Actions for linting C/C++ code. Integrated clang-tidy, clang-format check.
14+
A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of thread comments and/or annotations.
1615

1716
## Usage
1817

1918
Create a new GitHub Actions workflow in your project, e.g. at `.github/workflows/cpp-linter.yml`
2019

21-
The conetent of the file should be in the following format.
20+
The content of the file should be in the following format.
2221

2322
```yaml
2423
name: cpp-linter
@@ -31,7 +30,7 @@ on:
3130
push:
3231
pull_request:
3332
types: [opened]
34-
33+
3534
jobs:
3635
cpp-linter:
3736
name: cpp-linter
@@ -46,38 +45,99 @@ jobs:
4645
env:
4746
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4847
with:
49-
style: 'file'
48+
style: "file"
5049
```
5150
52-
`GITHUB_TOKEN` - Provided by Github (see [Authenticating with the GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow))
53-
5451
### Optional Inputs
5552
56-
| Name | Default | Description |
57-
|------------|---------------|-------------|
58-
| `style` | 'llvm' | The style rules to use. Set this to 'file' to have clang-format use the closest relative .clang-format file. |
59-
| `extensions` | 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx' | The file extensions to run the action against. This is a comma-separated string. |
60-
| `tidy-checks` | 'boost-\*,bugprone-\*,performance-\*,readability-\*,portability-\*,modernize-\*,clang-analyzer-\*,cppcoreguidelines-\*' | A string of regex-like patterns specifying what checks clang-tidy will use.|
61-
| `repo-root` | '.' | The relative path to the repository root directory. This path is relative to path designated by the runner's GITHUB_WORKSPACE environment variable. |
62-
| `version` | '10' | The desired version of the clang tools to use. Accepted options are strings which can be 6.0, 7, 8, 9, 10, 11, 12. |
63-
| `diff-only` | 'false' | Set this option to 'true' to only analyse changes in the event's diff. |
64-
| `verbosity` | '10' | This controls the action's verbosity in the workflow's logs. Supported options are defined by the python logging library's log levels. |
53+
#### `style`
54+
55+
- **Description**: The style rules to use. Set this to 'file' to have clang-format use the closest relative .clang-format file.
56+
- Default: 'llvm'
57+
58+
#### `extensions`
59+
60+
- **Description**: The file extensions to run the action against. This is a comma-separated string.
61+
- Default: 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx'
62+
63+
#### `tidy-checks`
64+
65+
- **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).
66+
- Default: 'boost-\*,bugprone-\*,performance-\*,readability-\*,portability-\*,modernize-\*,clang-analyzer-\*,cppcoreguidelines-\*'
67+
68+
#### `repo-root`
69+
70+
- **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.
71+
- Default: '.'
72+
73+
#### `version`
74+
75+
- **Description**: The desired version of the clang tools to use. Accepted options are strings which can be 6.0, 7, 8, 9, 10, 11, or 12.
76+
- Default: '10'
77+
78+
#### `verbosity`
79+
80+
- **Description**: This controls the action's verbosity in the workflow's logs. Supported options are defined by the python logging library's log levels. This option does not affect the verbosity of resulting comments or annotations.
81+
- Default: '10'
82+
83+
#### `lines-changed-only`
84+
85+
- **Description**: Set this option to true to only analyse changes in the event's diff.
86+
- Default: false
87+
88+
#### `files-changed-only`
89+
90+
- **Description**: Set this option to false to analyse any source files in the repo.
91+
- Default: true
92+
93+
#### `ignore`
94+
95+
- **Description**: Set this option with string of path(s) to ignore.
96+
- In the case of multiple paths, you can use a pipe character ('|')
97+
to separate the multiple paths. Multiple lines are forbidden as an input to this option; it must be a single string.
98+
- This can also have files, but the file's relative path has to be specified
99+
as well.
100+
- There is no need to use './' for each entry; a blank string ('') represents
101+
the repo-root path (specified by the `repo-root` input option).
102+
- Submodules are automatically ignored. Hidden directories (beginning with a '.') are also ignored automatically.
103+
- Prefix a path with a bang ('!') to make it explicitly _not_ ignored - order of
104+
multiple paths does _not_ take precedence. The '!' prefix can be applied to
105+
a submodule's path (if desired) but not hidden directories.
106+
- Glob patterns are not supported here. All asterick characters ('\*') are literal.
107+
- Default: '.github'
108+
109+
#### `thread-comments`
110+
111+
- **Description**: Set this option to false to disable the use of thread comments as feedback.
112+
- To use thread comments, the `GITHUB_TOKEN` (provided by Github to each repository) must be declared as an environment
113+
variable. See [Authenticating with the GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow)
114+
- Default: true
65115

66116
### Outputs
67117

68118
This action creates 1 output variable named `checks-failed`. Even if the linting checks fail for source files this action will still pass, but users' CI workflows can use this action's output to exit the workflow early if that is desired.
69119

70120
## Example
121+
71122
<!--intro-end-->
123+
124+
### Thread Comment
125+
72126
![github-actions bot](./docs/images/demo_comment.png)
127+
128+
### Annotations
129+
130+
![workflow annotations](./docs/images/demo_annotations.png)
131+
73132
<!--footer-start-->
133+
74134
Example comment is [here](https://github.com/shenxianpeng/cpp-linter-action/pull/5#commitcomment-55252014).
75135

76136
## Add C/C++ Lint Action badge in README
77137

78138
You can show C/C++ Lint Action status with a badge in your repository README
79139

80-
Example
140+
Example
81141

82142
```
83143
[![cpp-linter](https://github.com/shenxianpeng/cpp-linter-action/actions/workflows/cpp-linter.yml/badge.svg)](https://github.com/shenxianpeng/cpp-linter-action/actions/workflows/cpp-linter.yml)
@@ -89,8 +149,8 @@ Example
89149
90150
To provide feedback (requesting a feature or reporting a bug) please post to [issues](https://github.com/shenxianpeng/cpp-linter-action/issues).
91151
92-
93152
## License
94153
95154
The scripts and documentation in this project are released under the [MIT License](https://github.com/shenxianpeng/cpp-linter-action/blob/master/LICENSE)
155+
96156
<!--footer-end-->

‎action.yml‎

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ name: C/C++ Lint Action
22
description: Automatically checks push & pull request changes with clang-format & clang-tidy, then posts a comment with faulty results.
33
author: shenxianpeng
44
branding:
5-
icon: 'check-circle'
6-
color: 'green'
5+
icon: "check-circle"
6+
color: "green"
77
inputs:
8+
thread-comments:
9+
description: Set this option to false to disable the use of thread comments as feedback. Defaults to true.
10+
required: false
11+
default: true
812
style:
913
description: >
1014
The style rules to use (defaults to 'llvm').
1115
Set this to 'file' to have clang-format use the closest relative .clang-format file.
1216
required: false
13-
default: 'llvm'
17+
default: "llvm"
1418
extensions:
1519
description: >
1620
The file extensions to run the action against.
@@ -22,35 +26,61 @@ inputs:
2226
A string of regex-like patterns specifying what checks clang-tidy will use.
2327
This defaults to 'boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*'. See also clang-tidy docs for more info.
2428
required: false
25-
default: 'boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*'
29+
default: "boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*"
2630
repo-root:
2731
description: >
2832
The relative path to the repository root directory. The default value '.' is relative to the runner's GITHUB_WORKSPACE environment variable.
2933
required: false
30-
default: '.'
34+
default: "."
3135
version:
3236
description: "The desired version of the clang tools to use. Accepted options are strings which can be 6.0, 7, 8, 9, 10, 11, 12. Defaults to 10."
3337
required: false
34-
default: '10'
38+
default: "10"
3539
verbosity:
3640
descruption: A hidden option to control the action's log verbosity. This is the `logging` level (degaults to DEBUG)
3741
required: false
38-
default: '10'
39-
diff-only:
42+
default: "10"
43+
lines-changed-only:
4044
description: Set this option to 'true' to only analyse changes in the event's diff. Defaults to 'false'.
4145
required: false
4246
default: false
47+
files-changed-only:
48+
description: Set this option to 'false' to analyse any source files in the repo. Defaults to 'true'.
49+
required: false
50+
default: true
51+
ignore:
52+
description: >
53+
Set this option with string of path(s) to ignore.
54+
55+
- In the case of multiple paths, you can use a pipe character ('|')
56+
to separate the multiple paths. Multiple lines are forbidden as input to this option.
57+
- This can also have files, but the file's relative path has to be specified
58+
as well.
59+
- There is no need to use './' for each entry; a blank string ('') represents
60+
the repo-root path (specified by the `repo-root` input option).
61+
- Path(s) containing a space should be inside single quotes.
62+
- Submodules are automatically ignored.
63+
- Prefix a path with a bang (`!`) to make it explicitly not ignored - order of
64+
multiple paths does take precedence. The `!` prefix can be applied to
65+
submodules if desired.
66+
- Glob patterns are not supported here. All asterick characters ('*') are literal.
67+
required: false
68+
default: ".github"
4369
outputs:
4470
checks-failed:
4571
description: An integer that can be used as a boolean value to indicate if all checks failed.
4672
runs:
47-
using: 'docker'
48-
image: 'Dockerfile'
73+
using: "docker"
74+
image: "Dockerfile"
4975
args:
5076
- --style=${{ inputs.style }}
5177
- --extensions=${{ inputs.extensions }}
5278
- --tidy-checks=${{ inputs.tidy-checks }}
5379
- --repo-root=${{ inputs.repo-root }}
5480
- --version=${{ inputs.version }}
5581
- --verbosity=${{ inputs.verbosity }}
56-
- --diff-only=${{ inputs.diff-only }}
82+
- --lines-changed-only=${{ inputs.lines-changed-only }}
83+
- --files-changed-only=${{ inputs.files-changed-only }}
84+
- --thread-comments=${{ inputs.thread-comments }}
85+
- --ignore
86+
- ${{ inputs.ignore }}

‎demo/demo.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/** This is a very ugly test code (doomed to fail linting) */
22
#include "demo.hpp"
3-
#include <stdio.h>
3+
#include <stdio.h>///
44

55

66

77

88
int main(){
99

10-
for (;;) break;
10+
for (;;) break;///
1111

1212

13-
printf("Hello world!\n");
13+
printf("Hello world!\n");///
1414

1515

1616

‎demo/demo.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Dummy {
88
Dummy() :numb(0), useless("0円"){}
99

1010
public:
11-
void *not_usefull(char *str){useless = str;}
11+
void *not_usefull(char *str){useless = str;}///
1212
};
1313

1414

@@ -31,6 +31,6 @@ class Dummy {
3131
struct LongDiff
3232
{
3333

34-
long diff;
34+
long diff;///
3535

3636
};

‎docs/images/demo_annotations.png‎

23.9 KB
Loading[フレーム]

‎docs/index.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
end="<!--intro-end-->"
99
%}
1010

11-
![sample picture](images/demo_comment.png)
11+
### Thread Comment
12+
13+
![sample comment](images/demo_comment.png)
14+
15+
### Annotations
16+
17+
![workflow annotations](images/demo_annotations.png)
1218

1319
{%
1420
include-markdown "../README.md"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /