Skip to content

Commit 98b1c15

Browse files
shenxianpeng2bndy5
andauthored
#8 update readme to suggest open push event by default (#9)
* #8 update readme to suggest open push event by default * Push capable (#14) * Output exit code (#10) * solution for #7 * parameterize EXIT_CODE * fix bash function calls; switch to the new docker image * fix bash array length syntax * oops need that apt update * ok now change the test code a bit * check output is working * fix bad yml syntax * is it being set at all? * use a string instead of an integer * fix bash logic syntax * single square brackets are the old way to do logic * review changes * add output var info to the readme * Update demo.cpp * Revert action to upstream master * fix dockerfile from image not exist * solution for #7 * parameterize EXIT_CODE * fix bash function calls; switch to new docker image * check output is working * show me some env vars * trigger on push events * switch action to push-capable branch * echo the JSON that lives on the runner * use cat instead of echo * remove backticks * use alpine while debugging git events * Revert "use alpine while debugging git events" This reverts commit fbbb1b5a6f8a80f8d4245ebce07d7048ff74fedd. * test push compatibility * provide version input * docker uses tags * oops update run_checks.sh * fix jq args on push * test push src change * test src change w/ GH checkout * fix filename output for push events (w/ checkouts) * test new comment body * gotta break that bad habit * check against src change * use sed directly instead of sed then cat * tidy docs lied * don't know why sed isn't working * try multiple ARG options * try to replace the docker file * maybe without dyn var * bad domain? * nope needs a docker:// domain * reverting changes to docker file FROM * fix clang-format output to file * test on src changes * list clang-fmt warnings per file * add demo.h and adjust comment body * make test action use default extensions * don't checkout repo on test action * stay in working dir. DL into a hidden file * organize output better * adjust output again * fix output; switch back to checkout repo * enforce CPP syntax in the filename (no checkout) * sed taking too much out of the path in clang-tidy out * that's better (checkout is faster) * segregate script into functions * oops uncomment from debugging locally * show me a long diff * show me a split diff * clean-up (ready for PR) * update readme * remove the version from user inputs * only apply clang-tidy checks if it was specified * switch test action back to upstream * add version for user input Co-authored-by: Brendan <[email protected]>
1 parent 936dc05 commit 98b1c15

File tree

10 files changed

+356
-114
lines changed

10 files changed

+356
-114
lines changed

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# Explicitly declare text files you want to always be normalized and converted
5+
# to native line endings on checkout.
6+
*.py text eol=lf
7+
*.rst text eol=lf
8+
*.sh text eol=lf

.github/workflows/test.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
name: Test action
22

3-
on: [pull_request]
3+
on: [push, pull_request]
44

55
jobs:
66
test:
77
runs-on: ubuntu-latest
88
steps:
9-
# - uses: actions/checkout@v2
9+
- uses: actions/checkout@v2
1010
- uses: shenxianpeng/cpp-linter-action@master
1111
id: linter
12-
with:
13-
style: file
14-
extensions: 'cpp'
1512
env:
1613
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14+
with:
15+
style: file
1716

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

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
clang-format-report.txt
2-
clang-tidy-report.txt
1+
.cpp_linter_action_changed_files.json
2+
clang_format_report.txt
3+
clang_tidy_report.txt

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
FROM xianpengshen/clang-tools:11
1+
FROM xianpengshen/clang-tools:all
2+
3+
# WORKDIR option is set by the github action to the environment variable GITHUB_WORKSPACE.
4+
# See https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#workdir
5+
26

37
LABEL com.github.actions.name="cpp-linter check"
48
LABEL com.github.actions.description="Lint your code with clang-tidy in parallel to your builds"
@@ -13,4 +17,8 @@ RUN apt-get -y install curl jq
1317

1418
COPY runchecks.sh /entrypoint.sh
1519
RUN chmod +x /entrypoint.sh
20+
21+
# github action args use the CMD option
22+
# See https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsargs
23+
# also https://docs.docker.com/engine/reference/builder/#cmd
1624
ENTRYPOINT [ "/entrypoint.sh" ]

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ Github Actions for linting the C/C++ code. Integrated clang-tidy, clang-format c
66

77
Just create a `yml` file under your GitHub repository. For example `.github/workflows/cpp-linter.yml`
88

9-
!!! Requires `secrets.GITHUB_TOKEN` set to an environment variable name "GITHUB_TOKEN".
9+
!!! Requires `secrets.GITHUB_TOKEN` set to an environment variable named `GITHUB_TOKEN`.
1010

1111
```yml
1212
name: cpp-linter
1313

14-
on: [pull_request]
14+
# Triggers the workflow on push or pull request events
15+
on: [push, pull_request]
1516
jobs:
1617
cpp-linter:
1718
name: cpp-linter
@@ -30,6 +31,13 @@ jobs:
3031
|------------|---------------|-------------|
3132
| style | 'llvm' | The style rules to use. Set this to 'file' to have clang-format use the closest relative .clang-format file. |
3233
| 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. |
34+
| tidy-checks | 'boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*' | A string of regex-like patterns specifying what checks clang-tidy will use.|
35+
| 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. |
36+
| 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. |
37+
38+
### Outputs
39+
40+
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.
3341

3442
### Outputs
3543

action.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,33 @@ branding:
55
icon: 'check-circle'
66
color: 'green'
77
inputs:
8-
style: # the specific style rules
9-
description: "The style rules to use (defaults to 'llvm'). Set this to 'file' to have clang-format use the closest relative .clang-format file."
8+
style:
9+
description: >
10+
The style rules to use (defaults to 'llvm').
11+
Set this to 'file' to have clang-format use the closest relative .clang-format file.
1012
required: false
1113
default: 'llvm'
1214
extensions:
13-
description: "The file extensions to run the action against. This comma-separated string defaults to 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx'."
15+
description: >
16+
The file extensions to run the action against.
17+
This comma-separated string defaults to 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx'.
1418
required: false
1519
default: "c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx"
20+
tidy-checks:
21+
description: >
22+
A string of regex-like patterns specifying what checks clang-tidy will use.
23+
This defaults to 'boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*'. See also clang-tidy docs for more info.
24+
required: false
25+
default: 'boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*'
26+
repo-root:
27+
description: >
28+
The relative path to the repository root directory. The default value '.' is relative to the runner's GITHUB_WORKSPACE environment variable.
29+
required: false
30+
default: '.'
31+
version:
32+
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."
33+
required: false
34+
default: '10'
1635
outputs:
1736
checks-failed:
1837
description: An integer that can be used as a boolean value to indicate if all checks failed.
@@ -22,3 +41,6 @@ runs:
2241
args:
2342
- ${{ inputs.style }}
2443
- ${{ inputs.extensions }}
44+
- ${{ inputs.tidy-checks }}
45+
- ${{ inputs.repo-root }}
46+
- ${{ inputs.version }}

demo/compile_commands.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
[
2-
{
3-
"directory": ".",
4-
"command": "/usr/bin/g++ -Wall -Werror demo.cpp",
5-
"file": "/demo.cpp"
6-
}
2+
{
3+
"directory": ".",
4+
"command": "/usr/bin/g++ -Wall -Werror demo.cpp",
5+
"file": "/demo.cpp"
6+
},
7+
{
8+
"directory": ".",
9+
"command": "/usr/bin/g++ -Wall -Werror demo.cpp",
10+
"file": "/demo.hpp"
11+
}
712
]

demo/demo.cpp

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

55

@@ -9,6 +9,8 @@ int main(){
99

1010
for (;;) break;
1111

12+
1213
printf("Hello world!\n");
1314

15+
1416
return 0;}

demo/demo.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
4+
5+
class Dummy {
6+
char* useless;
7+
int numb;
8+
Dummy() :numb(0), useless("\0"){}
9+
10+
public:
11+
void *not_usefull(char *str){useless = str;}
12+
};
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
struct LongDiff
36+
{
37+
long diff;
38+
39+
};

0 commit comments

Comments
 (0)