Skip to content

Push capable #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 60 commits into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
7f36438
Output exit code (#10)
2bndy5 Aug 20, 2021
936dc05
fix dockerfile from image not exist
shenxianpeng Aug 20, 2021
1067ccf
solution for #7
2bndy5 Aug 19, 2021
b851ba6
parameterize EXIT_CODE
2bndy5 Aug 19, 2021
439be79
fix bash function calls; switch to new docker img
2bndy5 Aug 19, 2021
110fdb6
check output is working
2bndy5 Aug 19, 2021
1aca951
show me some env vars
2bndy5 Aug 19, 2021
4b50854
trigger on push events
2bndy5 Aug 19, 2021
f9a95fc
switch action to push-capable branch
2bndy5 Aug 19, 2021
ef13fbb
echo the json that lives on the runner
2bndy5 Aug 19, 2021
d25e246
use cat instead of echo
2bndy5 Aug 19, 2021
6b6b596
remove backticks
2bndy5 Aug 19, 2021
fb96c68
use alpine while debugging git events
2bndy5 Aug 19, 2021
dd3960d
Revert "use alpine while debugging git events"
2bndy5 Aug 19, 2021
b514f0f
test push compatibility
2bndy5 Aug 19, 2021
4f33f51
provide version input
2bndy5 Aug 19, 2021
7b71a60
docker uses tags
2bndy5 Aug 19, 2021
b5123a7
oops update run_checks.sh
2bndy5 Aug 19, 2021
29997b8
fix jq args on push
2bndy5 Aug 19, 2021
cd40a4a
test push src change
2bndy5 Aug 19, 2021
81ba2a8
test src change w/ GH checkout
2bndy5 Aug 19, 2021
743ad4c
fix filename output for push events (w/ checkouts)
2bndy5 Aug 19, 2021
e797fc1
test new comment body
2bndy5 Aug 20, 2021
280b3da
gotta break that bad habit
2bndy5 Aug 20, 2021
6f24cda
check against src change
2bndy5 Aug 20, 2021
d222ebc
use sed directly instead sed then cat
2bndy5 Aug 20, 2021
2e9d8ef
tidy docs lied
2bndy5 Aug 20, 2021
87f070d
don't know why sed isn't working
2bndy5 Aug 20, 2021
5176a82
try multiple ARG options
2bndy5 Aug 20, 2021
57f7807
try to replace the dockerfile
2bndy5 Aug 20, 2021
ad7c735
maybe without dyn var
2bndy5 Aug 20, 2021
2728f8c
bad domain?
2bndy5 Aug 20, 2021
3cb990a
nope needs a docker:// domain
2bndy5 Aug 20, 2021
b061a87
reverting changes to dockerfile FROM
2bndy5 Aug 20, 2021
787888b
fix clang-format output to file
2bndy5 Aug 20, 2021
055c69f
test on src changes
2bndy5 Aug 20, 2021
ea3c3a9
list clang-fmt warnings per file
2bndy5 Aug 21, 2021
77e840a
add demo.h and adjust comment body
2bndy5 Aug 21, 2021
8debe93
make test action use default extensions
2bndy5 Aug 21, 2021
ef193a2
don't checkout repo on test action
2bndy5 Aug 21, 2021
a1e0ce1
stay in working dir. DL into hidden file
2bndy5 Aug 21, 2021
786d1cd
organize output better
2bndy5 Aug 21, 2021
3efde58
adjust output again
2bndy5 Aug 21, 2021
ef76af3
fix output; switch back to checkout repo
2bndy5 Aug 21, 2021
357927e
enforce CPP syntax in filename (no checkout)
2bndy5 Aug 21, 2021
39fd839
sed taking too much out of path in clang-tidy out
2bndy5 Aug 21, 2021
f26cabc
that's better (checkout is faster)
2bndy5 Aug 21, 2021
52fbcdb
segragate script into functions
2bndy5 Aug 21, 2021
0ee8542
oops uncomment from debugging locally
2bndy5 Aug 21, 2021
51a6a6d
show me a long diff
2bndy5 Aug 21, 2021
e3d0540
show me a split diff
2bndy5 Aug 21, 2021
368b5a5
clean-up (ready for PR)
2bndy5 Aug 22, 2021
9dd6d96
update readme
2bndy5 Aug 22, 2021
aeddc84
remove version from user inputs
2bndy5 Aug 22, 2021
a4cb305
only apply clang-tidy checks if it was specified
2bndy5 Aug 22, 2021
28c0d98
fix last commit
2bndy5 Aug 22, 2021
9ae405d
switch test action back to upstream
2bndy5 Aug 22, 2021
4b92de2
review changes
2bndy5 Aug 22, 2021
84b32c0
more review changes
2bndy5 Aug 22, 2021
7ae348e
add version for user input
2bndy5 Aug 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.py text eol=lf
*.rst text eol=lf
*.sh text eol=lf
17 changes: 12 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
name: Test action

on: [pull_request]
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
# - uses: actions/checkout@v2
- uses: actions/checkout@v2
- uses: shenxianpeng/cpp-linter-action@master
with:
style: file
extensions: 'cpp'
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: file

- name: Fail fast?!
if: steps.linter.outputs.checks-failed > 0
run: |
echo "Some files failed the linting checks!"
# for actual deployment
# run: exit 1
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
clang-format-report.txt
clang-tidy-report.txt
.cpp_linter_action_changed_files.json
clang_format_report.txt
clang_tidy_report.txt
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM ubuntu:latest
FROM xianpengshen/clang-tools:all

# WORKDIR option is set by the github action to the environment variable GITHUB_WORKSPACE.
# See https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#workdir

LABEL com.github.actions.name="cpp-linter check"
LABEL com.github.actions.description="Lint your code with clang-tidy in parallel to your builds"
Expand All @@ -8,10 +11,13 @@ LABEL com.github.actions.color="gray-dark"
LABEL repository="https://github.com/shenxianpeng/cpp-linter-action"
LABEL maintainer="shenxianpeng <20297606+shenxianpeng@users.noreply.github.com>"

# WORKDIR /build
RUN apt-get update
RUN apt-get -y install curl clang-tidy cmake jq clang clang-format
RUN apt-get -y install curl jq

COPY runchecks.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# github action args use the CMD option
# See https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsargs
# also https://docs.docker.com/engine/reference/builder/#cmd
ENTRYPOINT [ "/entrypoint.sh" ]
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Github Actions for linting the C/C++ code. Integrated clang-tidy, clang-format c

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

!!! Requires `secrets.GITHUB_TOKEN` set to an environment variable name "GITHUB_TOKEN".
!!! Requires `secrets.GITHUB_TOKEN` set to an environment variable named `GITHUB_TOKEN`.

```yml
name: cpp-linter
Expand All @@ -30,6 +30,13 @@ jobs:
|------------|---------------|-------------|
| style | 'llvm' | The style rules to use. Set this to 'file' to have clang-format use the closest relative .clang-format file. |
| 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. |
| tidy-checks | 'boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*' | A string of regex-like patterns specifying what checks clang-tidy will use.|
| 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. |
| 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. |

### Outputs

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.

## Results of GitHub Actions

Expand Down
31 changes: 28 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,42 @@ branding:
icon: 'check-circle'
color: 'green'
inputs:
style: # the specific style rules
description: "The style rules to use (defaults to 'llvm'). Set this to 'file' to have clang-format use the closest relative .clang-format file."
style:
description: >
The style rules to use (defaults to 'llvm').
Set this to 'file' to have clang-format use the closest relative .clang-format file.
required: false
default: 'llvm'
extensions:
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'."
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'.
required: false
default: "c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx"
tidy-checks:
description: >
A string of regex-like patterns specifying what checks clang-tidy will use.
This defaults to 'boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*'. See also clang-tidy docs for more info.
required: false
default: 'boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*'
repo-root:
description: >
The relative path to the repository root directory. The default value '.' is relative to the runner's GITHUB_WORKSPACE environment variable.
required: false
default: '.'
version:
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."
required: false
default: '10'
outputs:
checks-failed:
description: An integer that can be used as a boolean value to indicate if all checks failed.
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.style }}
- ${{ inputs.extensions }}
- ${{ inputs.tidy-checks }}
- ${{ inputs.repo-root }}
- ${{ inputs.version }}
186 changes: 186 additions & 0 deletions demo/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,performance-*,bugprone-*,clang-analyzer-*,mpi-*,misc-*,readability-*'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: 'file'
CheckOptions:
- key: bugprone-argument-comment.CommentBoolLiterals
value: '0'
- key: bugprone-argument-comment.CommentCharacterLiterals
value: '0'
- key: bugprone-argument-comment.CommentFloatLiterals
value: '0'
- key: bugprone-argument-comment.CommentIntegerLiterals
value: '0'
- key: bugprone-argument-comment.CommentNullPtrs
value: '0'
- key: bugprone-argument-comment.CommentStringLiterals
value: '0'
- key: bugprone-argument-comment.CommentUserDefinedLiterals
value: '0'
- key: bugprone-argument-comment.IgnoreSingleArgument
value: '0'
- key: bugprone-argument-comment.StrictMode
value: '0'
- key: bugprone-assert-side-effect.AssertMacros
value: assert
- key: bugprone-assert-side-effect.CheckFunctionCalls
value: '0'
- key: bugprone-dangling-handle.HandleClasses
value: 'std::basic_string_view;std::experimental::basic_string_view'
- key: bugprone-dynamic-static-initializers.HeaderFileExtensions
value: ',h,hh,hpp,hxx'
- key: bugprone-exception-escape.FunctionsThatShouldNotThrow
value: ''
- key: bugprone-exception-escape.IgnoredExceptions
value: ''
- key: bugprone-misplaced-widening-cast.CheckImplicitCasts
value: '0'
- key: bugprone-not-null-terminated-result.WantToUseSafeFunctions
value: '1'
- key: bugprone-signed-char-misuse.CharTypdefsToIgnore
value: ''
- key: bugprone-sizeof-expression.WarnOnSizeOfCompareToConstant
value: '1'
- key: bugprone-sizeof-expression.WarnOnSizeOfConstant
value: '1'
- key: bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression
value: '0'
- key: bugprone-sizeof-expression.WarnOnSizeOfThis
value: '1'
- key: bugprone-string-constructor.LargeLengthThreshold
value: '8388608'
- key: bugprone-string-constructor.WarnOnLargeLength
value: '1'
- key: bugprone-suspicious-enum-usage.StrictMode
value: '0'
- key: bugprone-suspicious-missing-comma.MaxConcatenatedTokens
value: '5'
- key: bugprone-suspicious-missing-comma.RatioThreshold
value: '0.200000'
- key: bugprone-suspicious-missing-comma.SizeThreshold
value: '5'
- key: bugprone-suspicious-string-compare.StringCompareLikeFunctions
value: ''
- key: bugprone-suspicious-string-compare.WarnOnImplicitComparison
value: '1'
- key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison
value: '0'
- key: bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit
value: '16'
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
value: '1'
- key: bugprone-unused-return-value.CheckedFunctions
value: '::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty'
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: misc-definitions-in-headers.HeaderFileExtensions
value: ',h,hh,hpp,hxx'
- key: misc-definitions-in-headers.UseHeaderFileExtension
value: '1'
- key: misc-throw-by-value-catch-by-reference.CheckThrowTemporaries
value: '1'
- key: misc-unused-parameters.StrictMode
value: '0'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: performance-faster-string-find.StringLikeClasses
value: 'std::basic_string'
- key: performance-for-range-copy.AllowedTypes
value: ''
- key: performance-for-range-copy.WarnOnAllAutoCopies
value: '0'
- key: performance-inefficient-string-concatenation.StrictMode
value: '0'
- key: performance-inefficient-vector-operation.EnableProto
value: '0'
- key: performance-inefficient-vector-operation.VectorLikeClasses
value: '::std::vector'
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: '1'
- key: performance-move-constructor-init.IncludeStyle
value: llvm
- key: performance-no-automatic-move.AllowedTypes
value: ''
- key: performance-type-promotion-in-math-fn.IncludeStyle
value: llvm
- key: performance-unnecessary-copy-initialization.AllowedTypes
value: ''
- key: performance-unnecessary-value-param.AllowedTypes
value: ''
- key: performance-unnecessary-value-param.IncludeStyle
value: llvm
- key: readability-braces-around-statements.ShortStatementLines
value: '0'
- key: readability-else-after-return.WarnOnUnfixable
value: '1'
- key: readability-function-size.BranchThreshold
value: '4294967295'
- key: readability-function-size.LineThreshold
value: '4294967295'
- key: readability-function-size.NestingThreshold
value: '4294967295'
- key: readability-function-size.ParameterThreshold
value: '4294967295'
- key: readability-function-size.StatementThreshold
value: '800'
- key: readability-function-size.VariableThreshold
value: '4294967295'
- key: readability-identifier-naming.IgnoreFailedSplit
value: '0'
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: '0'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: '0'
- key: readability-inconsistent-declaration-parameter-name.IgnoreMacros
value: '1'
- key: readability-inconsistent-declaration-parameter-name.Strict
value: '0'
- key: readability-magic-numbers.IgnoredFloatingPointValues
value: '1.0;100.0;'
- key: readability-magic-numbers.IgnoredIntegerValues
value: '1;2;3;4;'
- key: readability-redundant-member-init.IgnoreBaseInCopyConstructors
value: '0'
- key: readability-redundant-smartptr-get.IgnoreMacros
value: '1'
- key: readability-redundant-string-init.StringNames
value: '::std::basic_string'
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
value: '0'
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
value: '0'
- key: readability-simplify-subscript-expr.Types
value: '::std::basic_string;::std::basic_string_view;::std::vector;::std::array'
- key: readability-static-accessed-through-instance.NameSpecifierNestingThreshold
value: '3'
- key: readability-uppercase-literal-suffix.IgnoreMacros
value: '1'
- key: readability-uppercase-literal-suffix.NewSuffixes
value: ''
...
15 changes: 10 additions & 5 deletions demo/compile_commands.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[
{
"directory": ".",
"command": "/usr/bin/g++ -Wall -Werror demo.cpp",
"file": "/demo.cpp"
}
{
"directory": ".",
"command": "/usr/bin/g++ -Wall -Werror demo.cpp",
"file": "/demo.cpp"
},
{
"directory": ".",
"command": "/usr/bin/g++ -Wall -Werror demo.cpp",
"file": "/demo.hpp"
}
]
9 changes: 5 additions & 4 deletions demo/demo.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@

/** This is a very ugly test code (doomed to fail linting) */
#include "demo.hpp"
#include <stdio.h>




int main(){

printf("Hello world!\n");
for (;;) break;

return 0;}
printf("Hello world!\n");



/* This is an ugly test code */
return 0;}
Loading