-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHEL-65784: CI: Enable code style chacking with clang-format
Add empty config for clang-format. Jira: https://issues.redhat.com/browse/RHEL-65784 Signed-off-by: Konstantin Kostiuk <[email protected]>
- Loading branch information
1 parent
ff57c6c
commit 320c189
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
DisableFormat: true |
This file contains 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,25 @@ | ||
name: clang-format check | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
clang-format: | ||
name: Code style check | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
path: | ||
- check: '.' | ||
exclude: './VirtIO' | ||
- check: 'VirtIO' | ||
exclude: '' | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Run clang-format style check for C/C++/Protobuf programs. | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install --no-install-recommends -y clang-format-18 | ||
bash Tools/clang-format.sh ${CHECK_PATH} "" ${EXCLUDE_REGEX} | ||
env: | ||
CHECK_PATH: ${{ matrix.path['check'] }} | ||
EXCLUDE_REGEX: ${{ matrix.path['exclude'] }} |
This file contains 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,58 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
# Default to the root of the repository | ||
CHECK_PATH="${1:-"${SCRIPT_DIR}/.."}" | ||
CLANG_FORMAT_STYLE="${2:-"${CHECK_PATH}/.clang-format"}" | ||
EXCLUDE_REGEX="$3" | ||
INCLUDE_REGEX="$4" | ||
|
||
CLANG_FORMAT_STYLE="$(realpath "${CLANG_FORMAT_STYLE}")" | ||
|
||
echo "Using clang-format version: $(clang-format --version)" | ||
echo "Running clang-format on $(realpath ${CHECK_PATH})" | ||
echo "Using clang-format style file: ${CLANG_FORMAT_STYLE}" | ||
|
||
if [[ -z $EXCLUDE_REGEX ]]; then | ||
EXCLUDE_REGEX="^$" | ||
fi | ||
|
||
# Set the filetype regex if nothing was provided. | ||
# Find all C/C++ files: | ||
# h, H, hpp, hh, h++, hxx | ||
# c, C, cpp, cc, c++, cxx | ||
if [[ -z $INCLUDE_REGEX ]]; then | ||
INCLUDE_REGEX='^.*\.((((c|C)(c|pp|xx|\+\+)?$)|((h|H)h?(pp|xx|\+\+)?$)))$' | ||
fi | ||
|
||
# initialize exit code | ||
exit_code=0 | ||
|
||
cd "${CHECK_PATH}" | ||
src_files=$(find "." -name .git -prune -o -regextype posix-egrep -regex "$INCLUDE_REGEX" -print) | ||
|
||
# check formatting in each source file | ||
IFS=$'\n' # Loop below should separate on new lines, not spaces. | ||
for file in $src_files; do | ||
# Only check formatting if the path doesn't match the regex | ||
if ! [[ ${file} =~ $EXCLUDE_REGEX ]]; then | ||
|
||
formated_code="$(clang-format --style=file:"${CLANG_FORMAT_STYLE}" --verbose --Werror "${file}")" | ||
if [[ -z "$formated_code" ]]; then | ||
continue | ||
fi | ||
|
||
local_format="$(diff <(cat "${file}") <(echo "${formated_code}") || true)" | ||
if [[ -n "${local_format}" ]]; then | ||
echo "The file ${file} is not formatted correctly" | ||
echo "${local_format}" | ||
exit_code=1 | ||
fi | ||
fi | ||
done | ||
|
||
echo "clang-format check finished with exit code: ${exit_code}" | ||
exit $exit_code |
This file contains 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,4 @@ | ||
IndentWidth: 4 | ||
TabWidth: 4 | ||
UseTab: Never | ||
DisableFormat: true |