Skip to content

Commit

Permalink
test clang-tidy
Browse files Browse the repository at this point in the history
Create clang-format.yml
Update and rename lint.yml to clang-tidy.yml
  • Loading branch information
zjeffer committed Dec 7, 2023
1 parent dc208b6 commit 5f69d6e
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 3 deletions.
156 changes: 156 additions & 0 deletions .github/actions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: C/C++ Linter
description: Lint C/C++ code with clang-format and clang-tidy then post annotations, comments, and step summary with results.
author: shenxianpeng
branding:
icon: "check-circle"
color: "green"
inputs:
thread-comments:
description: >-
Set this option to 'true' or 'false' to enable or disable the use of
thread comments as feedback. Set this to 'update' to update an existing comment
if one exists; the value 'true' will always delete an old comment and post a new one
if necessary. Defaults to false.
required: false
default: 'false'
no-lgtm:
description: >-
Set this option to true or false to enable or disable the use of a thread comment that
basically says 'Looks Good To Me' (when all checks pass). Defaults to true.
See `thread-comments` option for further details.
required: false
default: true
step-summary:
description: >
Set this option to true to append content as part of workflow's job summary. Defaults to false.
See implementation details in GitHub's documentation about
[Adding a job summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary).
This option is independent of the `thread-comments` option, rather this option uses the same content that
the `thread-comments` option would use.
required: false
default: false
file-annotations:
description: Set this option to false to disable the use of file annotations as feedback. Defaults to true.
required: false
default: true
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'.
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 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4 or 3.9. Defaults to 12."
required: false
default: "12"
verbosity:
description: A hidden option to control the action's log verbosity. This is the `logging` level (defaults to DEBUG).
required: false
default: "10"
lines-changed-only:
description: Set this option to 'true' to only analyze changes in the event's diff. Defaults to 'false'.
required: false
default: false
files-changed-only:
description: Set this option to 'false' to analyze any source files in the repo. Defaults to 'true'.
required: false
default: true
ignore:
description: >
Set this option with string of path(s) to ignore.
- In the case of multiple paths, you can use a pipe character ('|')
to separate the multiple paths. Multiple lines are forbidden as input to this option.
- This can also have files, but the file's relative path has to be specified
as well.
- There is no need to use './' for each entry; a blank string ('') represents
the repo-root path (specified by the `repo-root` input option).
- Path(s) containing a space should be inside single quotes.
- Submodules are automatically ignored.
- Prefix a path with a bang (`!`) to make it explicitly not ignored - order of
multiple paths does take precedence. The `!` prefix can be applied to
submodules if desired.
- Glob patterns are not supported here. All asterisk characters ('*') are literal.
required: false
default: ".github"
database:
description: The directory containing compile_commands.json file.
required: false
default: ""
extra-args:
description: A string of extra arguments passed to clang-tidy for use as compiler arguments. Multiple arguments are separated by spaces so the argument name and value should use an '=' sign instead of a space.
required: false
default: ""
outputs:
checks-failed:
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy and clang-format.
value: ${{ steps.cpp-linter.outputs.checks-failed }}
clang-tidy-checks-failed:
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-tidy only.
value: ${{ steps.cpp-linter.outputs.clang-tidy-checks-failed }}
clang-format-checks-failed:
description: An integer that can be used as a boolean value to indicate if any checks failed by clang-format only.
value: ${{ steps.cpp-linter.outputs.clang-format-checks-failed }}
runs:
using: "composite"
steps:
- name: Install action dependencies
shell: bash
run: |
if [[ "${{runner.os}}" == "Linux" ]]; then
sudo apt-get update
# First try installing from default Ubuntu repositories before trying LLVM script
if ! sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}; then
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
wget https://apt.llvm.org/llvm.sh -O $GITHUB_ACTION_PATH/llvm_install.sh
chmod +x $GITHUB_ACTION_PATH/llvm_install.sh
if sudo $GITHUB_ACTION_PATH/llvm_install.sh ${{ inputs.version }}; then
sudo apt-get install -y clang-format-${{ inputs.version }} clang-tidy-${{ inputs.version }}
fi
fi
fi
python3 -m venv "$GITHUB_ACTION_PATH/venv"
. "$GITHUB_ACTION_PATH/venv/bin/activate"
python3 -m pip install -r "$GITHUB_ACTION_PATH/requirements.txt"
clang-tools -i ${{ inputs.version }} -b
- name: Run cpp-linter
id: cpp-linter
shell: bash
run: |
. "$GITHUB_ACTION_PATH/venv/bin/activate"
cpp-linter \
--style="${{ inputs.style }}" \
--extensions=${{ inputs.extensions }} \
--tidy-checks="${{ inputs.tidy-checks }}" \
--repo-root=${{ inputs.repo-root }} \
--version=${{ inputs.version }} \
--verbosity=${{ inputs.verbosity }} \
--lines-changed-only=${{ inputs.lines-changed-only }} \
--files-changed-only=${{ inputs.files-changed-only }} \
--thread-comments=${{ inputs.thread-comments }} \
--no-lgtm=${{ inputs.no-lgtm }} \
--step-summary=${{ inputs.step-summary }} \
--ignore="${{ inputs.ignore }}" \
--database=${{ inputs.database }} \
--file-annotations=${{ inputs.file-annotations }} \
--extra-arg="${{ inputs.extra-args }}"
7 changes: 7 additions & 0 deletions .github/actions/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Install clang-tools binaries (clang-format, clang-tidy)
# For details please see: https://github.com/cpp-linter/clang-tools-pip
clang-tools==0.9.0

# cpp-linter core Python executable package
# For details please see: https://github.com/cpp-linter/cpp-linter
cpp-linter==1.6.2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Linter
name: clang-format

on: [push, pull_request]

Expand All @@ -8,7 +8,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: DoozyX/clang-format-lint-action@v0.16.2
name: clang-format
with:
source: '.'
extensions: 'hpp,h,cpp,c'
clangFormatVersion: 16
clangFormatVersion: 16
33 changes: 33 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: clang-tidy

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
container:
image: alexays/waybar:debian
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
apt update
apt install sudo python3-pip python3-venv -y
- name: configure
run: meson -Dcpp_std=c++20 build # necessary to generate compile_commands.json
- uses: ./.github/actions/
name: clang-tidy
id: clang-tidy-check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PIP_NO_CACHE_DIR: false
with:
style: '' # empty string => don't do clang-format checks here, we do them in clang-format.yml
files-changed-only: true # only check files that have changed
lines-changed-only: true # only check lines that have changed
tidy-checks: '' # empty string => use the .clang-tidy file
version: '17' # clang-tools version
database: 'build' # path to the compile_commands.json file
- name: Check if clang-tidy failed on any files
if: steps.clang-tidy-check.outputs.checks-failed > 0
run: echo "Some files failed the linting checks!" && exit 1
2 changes: 1 addition & 1 deletion src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
}
event_box_.add(m_box);

if (!gIPC) {
if (!gIPC.get()) {
gIPC = std::make_unique<IPC>();
}

Expand Down

0 comments on commit 5f69d6e

Please sign in to comment.