Skip to content
Open
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
5 changes: 4 additions & 1 deletion .github/workflows/compiling_and_unittests_on_ubuntu_2404.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ jobs:
echo "timestamp=${timestamp}" >> ${GITHUB_OUTPUT}

- name: Install Dependencies
run: sudo apt-get install -y libboost-all-dev libgit2-dev ninja-build ccache
run: |
set -euo pipefail
sudo apt-get install -y libboost-all-dev libgit2-dev ninja-build ccache
bash scripts/linux/ubuntu/install_llvm_tools.sh 22 clang-format-22 clang-tidy-22

- name: Setup C/C++ Compiler and ccache
run: |
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
run: |
set -euo pipefail
mv "${{ inputs.artifact-name }}" "${{ inputs.distribution-name }}"
mv "${{ inputs.artifact-name }}.sha256" "${{ inputs.distribution-name }}.sha256"
sed -i "s/${{ inputs.artifact-name }}/${{ inputs.distribution-name }}/" \
"${{ inputs.distribution-name }}.sha256"

- name: Release Artifacts to Github Release Page
uses: softprops/action-gh-release@v2
Expand All @@ -38,3 +41,4 @@ jobs:
tag_name: v${{ inputs.release-version }}
files: |
${{ inputs.distribution-name }}
${{ inputs.distribution-name }}.sha256
9 changes: 7 additions & 2 deletions .github/workflows/release_new_version_on_ubuntu_2404.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ jobs:

# rename
mv build/${package_name}.tar.gz build/${artifact_name}.tar.gz
(
cd build
sha256sum "${artifact_name}.tar.gz" > "${artifact_name}.tar.gz.sha256"
)

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: "${{ steps.artifact.outputs.artifact_name }}.tar.gz"
path: build/${{ steps.artifact.outputs.artifact_name }}.tar.gz
path: |
build/${{ steps.artifact.outputs.artifact_name }}.tar.gz
build/${{ steps.artifact.outputs.artifact_name }}.tar.gz.sha256
if-no-files-found: error

run-regression-tests:
Expand All @@ -108,4 +114,3 @@ jobs:
artifact-name: "${{ needs.build-unit-tests-package.outputs.artifact_name }}.tar.gz"
distribution-name: "${{ needs.build-unit-tests-package.outputs.distribution_name }}.tar.gz"
release-version: "${{ needs.build-unit-tests-package.outputs.release_version }}"

8 changes: 7 additions & 1 deletion .github/workflows/run_regression_tests_on_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
fail-fast: true
matrix:
include:
- { platform: "Ubuntu-24.04", clang_tool_version: "22" }
- { platform: "Ubuntu-24.04", clang_tool_version: "18" }
- { platform: "Ubuntu-24.04", clang_tool_version: "17" }
- { platform: "Ubuntu-24.04", clang_tool_version: "16" }
Expand All @@ -33,6 +34,12 @@ jobs:
- name: Make Test Repository
run: bash ./.github/workflows/scripts/basic_regression_test.sh

- name: Install LLVM 22 Tools
if: matrix.clang_tool_version == '22'
run: |
set -euo pipefail
bash scripts/linux/ubuntu/install_llvm_tools.sh 22 clang-format-22 clang-tidy-22

- name: Download Artifacts
uses: actions/download-artifact@v4
with:
Expand Down Expand Up @@ -84,4 +91,3 @@ jobs:
[[ "${format_failed}" -ne 1 ]] && exit 1
[[ "${tidy_failed}" -ne 1 ]] && exit 1
exit 0

81 changes: 60 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ string(STRIP "${CPP_LINT_ACTION_VERSION}" CPP_LINT_ACTION_VERSION)

project(cpp_lint_action VERSION ${CPP_LINT_ACTION_VERSION})

set(CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED true)
set(CMAKE_EXPORT_COMPILE_COMMANDS on)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(cpp_lint_action_root ${CMAKE_CURRENT_SOURCE_DIR})
set(config_dir ${cpp_lint_action_root}/src/configs)
set(src_dir ${cpp_lint_action_root}/src)
set(config_dir ${cpp_lint_action_root}/src/configs)
set(src_dir ${cpp_lint_action_root}/src)
set(generated_config_dir ${CMAKE_CURRENT_BINARY_DIR}/generated/configs)

include(${cpp_lint_action_root}/cmake/FetchSpdlog.cmake)
include(${cpp_lint_action_root}/cmake/FetchRangeV3.cmake)
Expand All @@ -36,22 +36,30 @@ IF(ENABLE_CODE_COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-abs-path -g -O0")
ENDIF()

find_package(Boost REQUIRED CONFIG COMPONENTS filesystem system regex program_options)
find_package(Boost REQUIRED CONFIG COMPONENTS filesystem process regex program_options)
find_package(Threads REQUIRED)
find_package(PkgConfig QUIET)

configure_file(${config_dir}/version.h.in ${config_dir}/version.h)
set(cpp_lint_action_libgit2_target "")
if(PkgConfig_FOUND)
pkg_check_modules(LIBGIT2 QUIET IMPORTED_TARGET libgit2)
endif()
if(TARGET PkgConfig::LIBGIT2)
set(cpp_lint_action_libgit2_target PkgConfig::LIBGIT2)
else()
find_package(libgit2 CONFIG QUIET)
if(TARGET libgit2::libgit2package)
set(cpp_lint_action_libgit2_target libgit2::libgit2package)
else()
find_path(LIBGIT2_INCLUDE_DIR git2.h)
find_library(LIBGIT2_LIBRARY NAMES git2)
if(NOT LIBGIT2_INCLUDE_DIR OR NOT LIBGIT2_LIBRARY)
message(FATAL_ERROR "Could not find libgit2. Install libgit2-dev or provide libgit2.pc.")
endif()
endif()
endif()

include_directories(${Boost_INCLUDE_DIRS}
${magic_enum_SOURCE_DIR}/include
${src_dir})

link_libraries(${Boost_LIBRARIES}
spdlog
range-v3
httplib
nlohmann_json
tinyxml2
magic_enum
git2)
configure_file(${config_dir}/version.h.in ${generated_config_dir}/version.h)

FILE(GLOB_RECURSE dep_files "${src_dir}/github/*.cpp"
"${src_dir}/tools/*.cpp"
Expand All @@ -61,7 +69,38 @@ FILE(GLOB_RECURSE dep_files "${src_dir}/github/*.cpp"
)

add_library(dep_obj OBJECT ${dep_files})
add_executable(cpp-lint-action $<TARGET_OBJECTS:dep_obj> "${src_dir}/main.cpp")
target_include_directories(dep_obj
PUBLIC
${Boost_INCLUDE_DIRS}
${magic_enum_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/generated
${src_dir}
)
if(LIBGIT2_INCLUDE_DIR)
target_include_directories(dep_obj PUBLIC ${LIBGIT2_INCLUDE_DIR})
endif()
target_link_libraries(dep_obj
PUBLIC
Boost::filesystem
Boost::process
Boost::regex
Boost::program_options
spdlog
range-v3
httplib
nlohmann_json
tinyxml2
magic_enum
Threads::Threads
)
if(cpp_lint_action_libgit2_target)
target_link_libraries(dep_obj PUBLIC ${cpp_lint_action_libgit2_target})
else()
target_link_libraries(dep_obj PUBLIC ${LIBGIT2_LIBRARY})
endif()

add_executable(cpp-lint-action "${src_dir}/main.cpp")
target_link_libraries(cpp-lint-action PRIVATE dep_obj)

IF (BUILD_TESTING)
add_subdirectory(tests)
Expand Down
59 changes: 43 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,78 @@ Use cpp-lint-action on Github workflow is a easy thing.

Just add follow lines to your `.github/workflows/your_workflow_name.yml`
```yaml
- uses: emmett2020/cpp-lint-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
pull_request:

permissions:
contents: read
issues: write
pull-requests: write

jobs:
cpp-lint:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: emmett2020/cpp-lint-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
jobs: "2"
max-review-comments: "50"
```

After the workflow is complete, you can see the following results displayed in the GitHub pull request review page.
![output](./docs/cpp-lint-action.png)

You can find more comprehensive configurations in [there](action.yml) and usage examples in the `examples/` directory.
By default, cpp-lint-action uses `clang-format-22` and `clang-tidy-22`. Pull request API reporting is only attempted for `pull_request` and `pull_request_target` events. On push, schedule, and other non-PR events, issue comments and pull request reviews are skipped automatically and `GITHUB_TOKEN` is not required for that reporting path.

You can find all inputs in [action.yml](action.yml). The most commonly adjusted options are:

| input | default | description |
| ----- | ------- | ----------- |
| `jobs` | `1` | Maximum file checks each enabled tool can run in parallel. |
| `max-review-comments` | `50` | Maximum inline pull request review comments to send. |
| `enable-comment-on-issue` | `true` | Create or update the summary issue comment on PRs. |
| `enable-pull-request-review` | `false` | Create inline pull request review comments on PRs. |
| `clang-format-version` | `22` | clang-format major version to find from `PATH`. |
| `clang-tidy-version` | `22` | clang-tidy major version to find from `PATH`. |

# Develop cpp-lint-action
1. cpp-lint-action needs c++20 standard. Ensure your local compiler version supports it.
2. cpp-lint-action now supports Ubuntu only.
3. cpp-lint-action has two dependencies. You should install it before compilation.
3. cpp-lint-action uses Catch2 for unit tests. Run the Catch2 test binary directly.
4. cpp-lint-action has two system dependencies. You should install them before compilation.
```bash
sudo apt install -y libboost-all-dev libgit2-dev
sudo apt install -y libboost-all-dev libgit2-dev ninja-build
```

4. Download this repository and build.
5. Download this repository and build.
```bash
git clone https://github.com/emmett2020/cpp-lint-action.git
mkdir build && cd build
cmake ..
make -j`nproc`

cmake -S cpp-lint-action -B cpp-lint-action/build -GNinja
cmake --build cpp-lint-action/build -j`nproc`
```

5. Run unit tests
6. Run unit tests.
```bash
./build/tests/test
./cpp-lint-action/build/tests/test
```

# How to use cpp-lint-action locally
Since cpp-lint-action is used for Github, you must set some environment variables to simulate Github CI environment.
```bash
export GITHUB_REPOSITORY="owner/repository"
export GITHUB_TOKEN="your_private_github_token"
export GITHUB_EVENT_NAME=pull_request
export GITHUB_WORKSPACE="/path/to/your/local/repo"
export GITHUB_REF="ref/pull/NUMBER/merge"
export GITHUB_REF="refs/pull/NUMBER/merge"
export GITHUB_SHA="test_branch_name_in_your_local_repository"
export GITHUB_EVENT_PATH="/path/to/event.json"
export GITHUB_TOKEN="your_private_github_token" # only required for PR API reporting

```

Then, just run cpp-lint-action
```bash
./build/cpp-lint-action
./build/cpp-lint-action --target-revision=main
```
Loading
Loading