cpp-linter/cpp-linter-action

GitHub: cpp-linter/cpp-linter-action

集成了 clang-tidy 和 clang-format 的 GitHub Action,为 C/C++ 项目在 CI 流程中提供自动化的代码质量检查与多维反馈。

Stars: 141 | Forks: 23

# C/C++ Linter Action | clang-format & clang-tidy ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/cpp-linter/cpp-linter-action) [![GitHub marketplace](https://img.shields.io/badge/marketplace-C%2FC%2B%2B%20Linter-blue?logo=github)](https://github.com/marketplace/actions/c-c-linter) [![cpp-linter](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml) [![MkDocs Deploy](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/mkdocs-deploy.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/mkdocs-deploy.yml) [![cpp-linter hub](https://img.shields.io/badge/%F0%9F%8F%A0_cpp--linter_hub-%E2%86%90_home-22863a)](https://cpp-linter.github.io/) 一个用于对 C/C++ 代码进行 linting 的 GitHub Action,集成了 clang-tidy 和 clang-format 用于收集以以下形式提供的反馈: [`file-annotations`][file-annotations]、[`thread-comments`][thread-comments]、 工作流 [`step-summary`][step-summary],以及 Pull Request 审查(通过 [`tidy-review`][tidy-review] 或 [`format-review`][format-review])。 ## 用法 在你的项目中创建一个新的 GitHub Actions 工作流,例如在 [.github/workflows/cpp-linter.yml](https://github.com/cpp-linter/cpp-linter-action/blob/main/.github/workflows/cpp-linter.yml) 该文件的内容应采用以下格式。 ``` steps: - uses: actions/checkout@v5 - uses: cpp-linter/cpp-linter-action@v2 id: linter env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: style: 'file' # Use .clang-format config file tidy-checks: '' # Use .clang-tidy config file # only 'update' a single comment in a pull request thread. thread-comments: ${{ github.event_name == 'pull_request' && 'update' }} - name: Fail fast?! if: steps.linter.outputs.checks-failed > 0 run: exit 1 ``` 有关我们所有可用输入参数和输出变量的详细说明,请参阅我们的 [输入和输出文档][io-doc]。 另请参阅我们的[示例配方][recipes-doc]。 ## 使用情况

Microsoft Microsoft   Apache Apache   NASA NASA   Samsung Samsung   TheAlgorithms TheAlgorithms   CachyOS CachyOS  
Nextcloud Nextcloud   Jupyter Jupyter   NNStreamer NNStreamer   imgproxy imgproxy   Zondax Zondax   AppNeta AppNeta  
Chocolate Doom Chocolate Doom and many more.

## 示例 ### 注释 使用 [`file-annotations`][file-annotations]: #### clang-format 注释 ![clang-format annotations](https://static.pigsec.cn/wp-content/uploads/repos/cas/16/16c9514f31d64bd5f13cf8a9fac18cf6d4ac30877f0794d7c263a11f2a1ec6df.png) #### clang-tidy 注释 ![clang-tidy annotations](https://static.pigsec.cn/wp-content/uploads/repos/cas/3d/3db3f1d465b6f1a484844d75eac190d5937d7befe8d60b57777ca72406d4eac5.png) ### 讨论串评论 使用 [`thread-comments`][thread-comments]: ![sample thread-comment](https://static.pigsec.cn/wp-content/uploads/repos/cas/88/8892afe03ca3c6ff073458dd05bc57eeb02f5c614888b24631da124b7ab1a7bd.png) ### 步骤总结 使用 [`step-summary`][step-summary]: ![step summary](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/step-summary.png) ### Pull Request 审查 #### 仅使用 clang-tidy 使用 [`tidy-review`][tidy-review]: ![sample tidy-review](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/tidy-review.png) #### 仅使用 clang-format 使用 [`format-review`][format-review]: ![sample format-review](https://raw.githubusercontent.com/cpp-linter/cpp-linter-action/main/docs/images/format-review.png) ![sample format-suggestion](https://static.pigsec.cn/wp-content/uploads/repos/cas/8b/8b155ad4be129591f739cd12a76e2bd789b7a1d5bf095126334875075e1a8a00.png) ## 在 README 中添加 C/C++ Linter Action 徽章 你可以通过在你的仓库 README 中添加徽章来展示 C/C++ Linter Action 的状态 示例 ``` [![cpp-linter](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml) ``` [![cpp-linter](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-action/actions/workflows/cpp-linter.yml) ## 有疑问或反馈? 如需提供反馈(请求功能或报告错误),请发布到 [issues](https://github.com/cpp-linter/cpp-linter-action/issues)。 ## 已安装的必需工具 从 v2.16.0 版本起,此 Action 使用 - [nushell] 用于实现跨平台兼容的脚本 - [uv] 用于驱动 Python 虚拟环境 此 Action 会自动安装 [nushell] 和 [uv]。 只有 [nushell] 会被添加到 PATH 环境变量中。 [uv] 及其下载的任何独立 Python 发行版都不会被添加到 PATH 环境变量中。 ### 在 Linux runner 上 我们仅支持使用基于 Debian 的 Linux 操作系统(如 Ubuntu 等)的 Linux runner。 这是因为我们会首先尝试使用 `apt` 包管理器来安装 clang 工具。 使用特定 [`container`][gh-container-syntax] 的 Linux 工作流应确保安装了以下内容: - GLIBC(v2.32 或更高版本) - `wget` 或 `curl` - `lsb-release`(LLVM 提供的安装脚本所需) - `software-properties-common`(LLVM 提供的安装脚本所需) - `gnupg`(LLVM 提供的安装脚本所需) ``` apt-get update apt-get install -y libc6 wget lsb-release software-properties-common gnupg ``` 否则,[nushell] 和/或 LLVM 提供的 bash 脚本将无法运行。 如果使用 `apt` 包管理器安装 clang 工具失败,那么 我们将依次尝试以下来源: 1. PyPI 包 [clang-tidy][clang-tidy-wheel] 和/或 [clang-format][clang-format-wheel] 2. 我们自行构建的静态二进制文件;详情请参阅 [cpp-linter/clang-tools-pip] 项目。 ### 在 macOS runner 上 指定的 `clang-format` 和 `clang-tidy` 版本将依次通过以下来源进行安装(以最先成功的来源为准): 1. Homebrew 2. PyPI 包 [clang-tidy][clang-tidy-wheel] 和/或 [clang-format][clang-format-wheel] 3. 我们自行构建的静态二进制文件;详情请参阅 [cpp-linter/clang-tools-pip] 项目。 ### 在 Windows runner 上 对于 Windows runner,我们使用通过以下来源安装的 clang 工具(以最先成功的来源为准): 1. PyPI 包 [clang-tidy][clang-tidy-wheel] 和/或 [clang-format][clang-format-wheel] 2. 我们自行构建的静态二进制文件;详情请参阅 [cpp-linter/clang-tools-pip] 项目。 ## 许可证 本项目中的脚本和文档采用 [MIT License](https://github.com/cpp-linter/cpp-linter-action/blob/main/LICENSE) 发布。
标签:C/C++, SOC Prime, 事务性I/O, 开发工具, 逆向工具, 静态检查