-
Notifications
You must be signed in to change notification settings - Fork 463
Add clang-tidy to gihub-workflows #2044
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| Checks: > | ||
| -*, | ||
| clang-analyzer-*, | ||
| bugprone-*, | ||
| performance-*, | ||
| portability-*, | ||
| readability-*, | ||
| misc-*, | ||
| cppcoreguidelines-*, | ||
| -cppcoreguidelines-pro-type-vararg, | ||
| -cppcoreguidelines-owning-memory, | ||
| -modernize-*, | ||
| -readability-implicit-bool-conversion | ||
|
|
||
| WarningsAsErrors: '' | ||
|
|
||
| FormatStyle: file | ||
|
|
||
| CheckOptions: | ||
| - key: readability-magic-numbers.IgnoredValues | ||
| value: '0, 1, -1, 255' | ||
| - key: readability-identifier-naming.VariableCase | ||
| value: lower_case | ||
| - key: readability-identifier-naming.FunctionCase | ||
| value: lower_case | ||
| - key: readability-identifier-naming.MacroDefinitionCase | ||
| value: UPPER_CASE | ||
| - key: cppcoreguidelines-pro-type-member-init.HaltOnMissingInitializers | ||
| value: 'false' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| name: Clang-Tidy Lint | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| clang-tidy: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: actions/setup-go@v3 | ||
| with: | ||
| go-version: 'stable' | ||
| - uses: carlosperate/[email protected] | ||
| with: | ||
| release: ${{ matrix.gcc }} | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y jq | ||
| sudo apt-get install -y clang-tidy cmake build-essential ninja-build | ||
|
|
||
| - name: Install newt | ||
| shell: bash | ||
| run: | | ||
| go version | ||
| go install mynewt.apache.org/newt/newt@latest | ||
|
|
||
| - name: Setup project | ||
| shell: bash | ||
| run: | | ||
| newt new build | ||
| cp -f .github/project.yml build/project.yml | ||
| cd build | ||
| newt upgrade --shallow=1 | ||
| rm -rf repos/apache-mynewt-nimble | ||
| git clone .. repos/apache-mynewt-nimble | ||
| cd .. | ||
|
|
||
| - name: Configure CMake project | ||
| shell: bash | ||
| run: | | ||
| cd build | ||
| newt target create cc_test | ||
| newt target set cc_test bsp="@apache-mynewt-core/hw/bsp/nordic_pca10056" | ||
| newt target set cc_test app="@apache-mynewt-nimble/apps/btshell" | ||
| cp -f ../.github/test_build_apps_syscfg.yml targets/cc_test/syscfg.yml | ||
| newt target cmake cc_test | ||
| cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | ||
| cp build/compile_commands.json . | ||
|
|
||
| - name: Clean Compile Commands | ||
| shell: bash | ||
| run: | | ||
| COMPILE_COMMANDS="compile_commands.json" | ||
| if command -v jq >/dev/null 2>&1; then | ||
| echo "Cleaning compile_commands.json: removing -mthumb-interwork flag..." | ||
| jq 'map(.command |= gsub("-mthumb-interwork"; ""))' "$COMPILE_COMMANDS" > "${COMPILE_COMMANDS}.clean" | ||
| mv "${COMPILE_COMMANDS}.clean" "$COMPILE_COMMANDS" | ||
| else | ||
| echo "Error: jq is not installed. Please install jq to clean compile_commands.json" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Download clang-tidy-diff.py | ||
| run: | | ||
| curl -sSL -o clang-tidy-diff.py https://raw.githubusercontent.com/llvm/llvm-project/main/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | ||
| chmod +x clang-tidy-diff.py | ||
|
|
||
| - name: Generate patch from base branch | ||
| shell: bash | ||
| run: | | ||
| git diff -U0 origin/master...HEAD > diff.patch || true | ||
|
|
||
| - name: Run clang-tidy-diff | ||
| run: | | ||
| python3 clang-tidy-diff.py \ | ||
| -p1 \ | ||
| -path build \ | ||
| -config-file=.clang-tidy \ | ||
| < diff.patch | tee tidy-output.txt | ||
|
|
||
| # Check for warnings or errors | ||
| if grep -q -E 'warning:|error:' tidy-output.txt; then | ||
| echo "::error ::clang-tidy found issues in changed lines" | ||
| exit 1 | ||
| else | ||
| echo "✅ clang-tidy passed on changed lines" | ||
| fi | ||
| else | ||
| echo "✅ No diff to analyze. Skipping clang-tidy." | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check shouldn't be needed, all required tools shall be installed in previous steps