


此GitHub动作是为C ++/Python项目设计的,并使用以下方式执行静态分析。
它可以通过推和拉请求触发。
有关设置和各种输入的更多信息和指导,请参阅专用于每种语言的部分( C ++和Python )
创建的评论将包含具有问题描述的代码片段。首次运行此操作时,将为当前拉的请求创建带有初始结果的注释。连续运行将以更新状态编辑此注释。
请注意,检测到的问题的数量可能会使评论的身体大于PR评论的GitHub角色限制(65536)。在这种情况下,创建的评论将仅包含到达该点的问题,以及达到字符限制的信息。

对于非拉动请求,输出将打印到GitHub的输出控制台。此行为也可以通过force_console_print输入强制强制。

虽然建议您的项目基于CMAKE,但不需要(请参见下面的输入部分)。我们还建议在您的根目录中使用.clang-tidy文件。如果您的项目需要安装其他软件包,则可以使用apt_pckgs和/或init_script输入变量来安装它们(请参见下面的工作流示例或输入部分)。如果您的存储库允许叉子的贡献,则必须将此操作与pull_request_target触发事件一起使用,因为GitHub API否则不允许PR注释。
默认情况下, cppcheck以以下标志运行: --enable=all --suppress=missingIncludeSystem --inline-suppr --inconclusive您可以使用cppcheck_args输入来设置自己的标志。
Clang-Tidy在存储库中查找.clang-tidy文件,但是您还可以使用clang_tidy_args输入设置检查。
name : Static analysis
on :
# Will run on push when merging to 'branches'. The output will be shown in the console
push :
branches :
- develop
- master
- main
# 'pull_request_target' allows this Action to also run on forked repositories
# The output will be shown in PR comments (unless the 'force_console_print' flag is used)
pull_request_target :
branches :
- " * "
jobs :
static_analysis :
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@v2
- name : setup init_script
shell : bash
run : |
echo "#!/bin/bash
# Input args provided by StaticAnalysis action
root_dir=${1}
build_dir=${2}
echo "Hello from the init script! First arg=${root_dir} second arg=${build_dir}"
add-apt-repository ppa:oibaf/graphics-drivers
apt update && apt upgrade
apt install -y libvulkan1 mesa-vulkan-drivers vulkan-utils" > init_script.sh
- name : Run static analysis
uses : JacobDomagala/StaticAnalysis@master
with :
language : c++
# Exclude any issues found in ${Project_root_dir}/lib
exclude_dir : lib
use_cmake : true
# Additional apt packages that need to be installed before running Cmake
apt_pckgs : software-properties-common libglu1-mesa-dev freeglut3-dev mesa-common-dev
# Additional script that will be run (sourced) AFTER 'apt_pckgs' and before running Cmake
init_script : init_script.sh
# (Optional) clang-tidy args
clang_tidy_args : -checks='*,fuchsia-*,google-*,zircon-*,abseil-*,modernize-use-trailing-return-type'
# (Optional) cppcheck args
cppcheck_args : --enable=all --suppress=missingIncludeSystem | 姓名 | 描述 | 默认值 |
|---|---|---|
github_token | GitHub令牌用于GitHub API请求 | ${{github.token}} |
pr_num | 拉的请求号码将创建评论 | ${{github.event.pull_request.number}} |
comment_title | 标题与Raport发表评论。这应该是一个独特的名字 | Static analysis result |
exclude_dir | 应排除在狂欢之外的目录 | <empty> |
apt_pckgs | 需要安装的其他(空间分离的)软件包才能编译项目 | <empty> |
init_script | 在配置项目之前将运行的可选外壳脚本(IE运行CMAKE命令)。当项目需要事先设置一些环境设置时,应使用此方法。脚本将使用2个参数运行: root_dir (用户代码的根目录)和build_dir (为运行SA创建的构建目录)。笔记。 apt_pckgs将在此脚本之前运行,以防万一您需要安装一些软件包。此外,此脚本将在项目的根( root_dir )的根中运行 | <empty> |
cppcheck_args | 将使用的CPPCHECK(空间分离)参数 | --enable=all --suppress=missingIncludeSystem --inline-suppr --inconclusive |
clang_tidy_args | 将使用的clang-tidy参数(例如: -checks='*,fuchsia-*,google-*,zircon-*' | <empty> |
report_pr_changes_only | 仅在此拉请求中引入的更改中发现的问题。这意味着只有在更改线中发现的问题才会发布。由存储库中这些变化引起的任何其他问题都不会报告,因此通常您应该在整个代码库上进行静态分析 | false |
use_cmake | 确定应使用cmake生成compile_commands.json文件 | true |
cmake_args | 其他CMAKE参数 | <empty> |
force_console_print | 将操作结果输出到控制台,而不是创建注释 | false |
注意: apt_pckgs将在init_script之前运行,以防万一您需要在运行脚本之前安装一些软件包
name : Static analysis
on :
push :
branches :
- master
pull_request :
jobs :
check :
name : Run Linter
runs-on : ubuntu-20.04
steps :
- uses : actions/checkout@v3
- name : CodeQuality
uses : JacobDomagala/StaticAnalysis@master
with :
language : " Python "
pylint_args : " --rcfile=.pylintrc --recursive=true "
python_dirs : " src test " | 姓名 | 描述 | 默认值 |
|---|---|---|
github_token | GitHub令牌用于GitHub API请求 | ${{github.token}} |
pr_num | 拉的请求号码将创建评论 | ${{github.event.pull_request.number}} |
comment_title | 标题与Raport发表评论。这应该是一个独特的名字 | Static analysis result |
exclude_dir | 应排除在狂欢之外的目录 | <empty> |
apt_pckgs | 需要安装的其他(空间分离的)软件包才能编译项目 | <empty> |
init_script | 在配置项目之前将运行的可选外壳脚本(IE运行CMAKE命令)。当项目需要事先设置一些环境设置时,应使用此方法。脚本将使用2个参数运行: root_dir (用户代码的根目录)和build_dir (为运行SA创建的构建目录)。笔记。 apt_pckgs将在此脚本之前运行,以防万一您需要安装一些软件包。此外,此脚本将在项目的根( root_dir )的根中运行 | <empty> |
pylint_args | 将使用的Pylint(空间分离)参数 | <empty> |
python_dirs | 包含要检查Python文件的目录 | <empty> |
report_pr_changes_only | 仅在此拉请求中引入的更改中发现的问题。这意味着只有在更改线中发现的问题才会发布。由存储库中这些变化引起的任何其他问题都不会报告,因此通常您应该在整个代码库上进行静态分析 | false |
force_console_print | 将操作结果输出到控制台,而不是创建注释 | false |
注意: apt_pckgs将在init_script之前运行,以防万一您需要在运行脚本之前安装一些软件包