Skip to content

Commit bb6e330

Browse files
author
Kirill Belousov
committed
Creates workflow and scripts to run code quality and format checks
1 parent f84609f commit bb6e330

6 files changed

Lines changed: 151 additions & 2 deletions

File tree

.github/workflows/code-quality.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Code Quality Check
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
code-quality:
13+
name: Code Formatting & Linting Check
14+
runs-on: windows-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Install Clang-Tools (LLVM)
21+
run: choco install llvm --version=20.1.7 -y
22+
23+
- name: Add LLVM to PATH for subsequent steps
24+
# This is a robust way to ensure the tools are found
25+
run: echo "C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
26+
27+
- name: Verify clang-tools installation
28+
run: |
29+
clang-format --version
30+
clang-tidy --version
31+
shell: pwsh
32+
33+
# --- 1. FORMATTING CHECK ---
34+
# We don't use the format.bat script here because we don't want to
35+
# modify files in CI, we want to VERIFY they are already formatted.
36+
# The '--dry-run --Werror' command is perfect for this.
37+
- name: Check code formatting for compliance
38+
run: |
39+
$files = Get-ChildItem -Path src -Recurse -Include *.cpp,*.h
40+
clang-format --dry-run --Werror --style=file $files
41+
shell: pwsh # Use PowerShell for Get-ChildItem
42+
43+
- name: Set up MSVC build environment for the script
44+
uses: ilammy/msvc-dev-cmd@v1
45+
with:
46+
arch: x64
47+
48+
- name: Run clang-tidy
49+
uses: HorstBaerbel/action-clang-tidy@1.2
50+
with:
51+
scandir: "."
52+
builddir: "build/windows-msvc-x64-lint"
53+
excludedirs: ""
54+
extensions: "c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx"
55+
cmakeoptions: "--preset windows-msvc-x64-lint"

CMakePresets.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@
6464
"strategy": "external"
6565
},
6666
"cacheVariables": { "CMAKE_BUILD_TYPE": "MinSizeRel" }
67+
},
68+
{
69+
"name": "windows-msvc-x64-lint",
70+
"displayName": "Windows MSVC x64 (for Linting)",
71+
"description": "Configures the project for running static analysis with clang-tidy.",
72+
"inherits": "windows-msvc-x64-debug",
73+
"cacheVariables": {
74+
"CMAKE_MSVC_DEBUG_INFORMATION_FORMAT": "ProgramDatabase"
75+
}
6776
}
6877
],
6978
"buildPresets": [

scripts/format.bat

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@echo off
2+
setlocal
3+
4+
echo Checking formatting for all .cpp and .h files in src/...
5+
echo ---
6+
7+
set "MODIFIED_COUNT=0"
8+
set "UNTOUCHED_COUNT=0"
9+
10+
rem Recursively find all target files in the src directory
11+
for /r "src" %%f in (*.cpp, *.h) do (
12+
rem Create a temporary copy to compare against
13+
copy "%%f" "%%f.bak" > nul
14+
15+
rem Apply formatting to the original file
16+
clang-format -i -style=file "%%f"
17+
18+
rem Compare the formatted file with the backup. fc returns errorlevel 1 if different.
19+
fc /b "%%f" "%%f.bak" > nul
20+
if errorlevel 1 (
21+
echo [Formatted] %%f
22+
set /a "MODIFIED_COUNT+=1"
23+
) else (
24+
echo [Unchanged] %%f
25+
set /a "UNTOUCHED_COUNT+=1"
26+
)
27+
28+
rem Clean up the temporary file
29+
del "%%f.bak"
30+
)
31+
32+
echo.
33+
echo ---
34+
echo Formatting complete.
35+
echo %MODIFIED_COUNT% file(s) were reformatted.
36+
echo %UNTOUCHED_COUNT% file(s) were already compliant.

scripts/lint.bat

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@echo off
2+
setlocal enabledelayedexpansion
3+
4+
:: ============================================================================
5+
:: This script runs clang-tidy to find lint issues and potential bugs.
6+
::
7+
:: It requires a compilation database generated with a specific 'lint' preset.
8+
:: ============================================================================
9+
10+
set "LINT_PRESET_NAME=windows-msvc-x64-lint"
11+
set "BUILD_DIR=build/!LINT_PRESET_NAME!"
12+
13+
if not exist "!BUILD_DIR!/compile_commands.json" (
14+
echo [INFO] Compilation database not found. Configuring project with preset '!LINT_PRESET_NAME!'...
15+
cmake --preset=!LINT_PRESET_NAME!
16+
if errorlevel 1 (
17+
echo [ERROR] CMake configuration failed.
18+
exit /b 1
19+
)
20+
)
21+
22+
echo [INFO] Using compilation database from: !BUILD_DIR!
23+
echo [INFO] Running clang-tidy on the project...
24+
echo ---
25+
26+
set "SOURCE_FILES="
27+
for /r "src" %%f in (*.cpp) do (
28+
set "SOURCE_FILES=!SOURCE_FILES! "%%f""
29+
)
30+
31+
clang-tidy -p "!BUILD_DIR!" !SOURCE_FILES! ^
32+
--header-filter="src/.*" ^
33+
--warnings-as-errors="*" ^
34+
--extra-arg="-Wno-unknown-warning-option" ^
35+
--extra-arg="-Wno-unused-command-line-argument"
36+
37+
38+
if %errorlevel% neq 0 (
39+
echo ---
40+
echo [FAILURE] clang-tidy found issues
41+
echo Please fix the reported errors and warnings.
42+
exit /b %errorlevel%
43+
) else (
44+
echo ---
45+
echo [SUCCESS] clang-tidy found no issues. Great work!
46+
exit /b 0
47+
)
48+
49+
endlocal

src/loggerSetup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#pragma once
22

3-
void InitializeLogging(int argc, char *argv[]);
3+
void InitializeLogging(int argc, char* argv[]);

src/ui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <wx/wx.h>
43
#include <wx/event.h>
4+
#include <wx/wx.h>
55

66
class MainFrame : public wxFrame {
77
public:

0 commit comments

Comments
 (0)