Skip to content

#8 update readme to suggest open push event by default #9

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 3 commits into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
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
id: linter
with:
style: file
extensions: 'cpp'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
style: file

- name: Fail fast?!
if: steps.linter.outputs.checks-failed > 0
Expand Down
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
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
FROM xianpengshen/clang-tools:11
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 @@ -13,4 +17,8 @@ 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" ]
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ 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

on: [pull_request]
# Triggers the workflow on push or pull request events
on: [push, pull_request]
jobs:
cpp-linter:
name: cpp-linter
Expand All @@ -30,6 +31,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.

### Outputs

Expand Down
28 changes: 25 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,33 @@ 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.
Expand All @@ -22,3 +41,6 @@ runs:
args:
- ${{ inputs.style }}
- ${{ inputs.extensions }}
- ${{ inputs.tidy-checks }}
- ${{ inputs.repo-root }}
- ${{ inputs.version }}
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"
}
]
4 changes: 3 additions & 1 deletion demo/demo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** This is a very ugly test code (doomed to fail linting) */

#include "demo.hpp"
#include <stdio.h>


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

for (;;) break;


printf("Hello world!\n");


return 0;}
39 changes: 39 additions & 0 deletions demo/demo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once



class Dummy {
char* useless;
int numb;
Dummy() :numb(0), useless("\0"){}

public:
void *not_usefull(char *str){useless = str;}
};






















struct LongDiff
{
long diff;

};
Loading